Just how invalid are we talking? It's well-known that the blue/red channels may be swapped, and I've seen padding on the row. Doing your math though you're only reporting 2 bytes per pixel, which is very wrong. What is the image format you expect?
> Sent: Friday, February 28, 2020 at 4:42 PM > From: "Nuno Santos" <nunosan...@imaginando.pt> > To: "interestqt-project.org" <interest@qt-project.org> > Subject: [Interest] Converting CVImageBufferRef into QImage > > Hi, > > I’m trying to capture my Mac screen. I’ve found an example of > AVCaptureScreenInput. It seems to be working but now I need to convert from > CMSampleBufferRef/CVImageBufferRef to QImage. I’m trying the following code > without success: > > - (void)captureOutput:(AVCaptureOutput *)captureOutput > didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer > fromConnection:(AVCaptureConnection *)connection > { > CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); > > unsigned char *pixels = ( unsigned char > *)CVPixelBufferGetBaseAddress(imageBuffer); > int width = CVPixelBufferGetWidth(imageBuffer); > int height = CVPixelBufferGetHeight(imageBuffer); > int bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); > > qDebug() << width << height << bytesPerRow << > CVPixelBufferGetPixelFormatType(imageBuffer); > // outputs -> 1920 1080 3840 846624121 > > QImage image(pixels, width, height, bytesPerRow, QImage::Format_ARGB32); > > qDebug() << image; > } > > But the image is invalid. I guess the pixel format is not compatible. > > I don’t know how to interpret the > CVPixelBufferGetPixelFormatType(imageBuffer) to know the exact pixel format. > > As anyone crossed with a similar problem before? > > Thanks! > > Regards, > > Nuno_______________________________________________ > Interest mailing list > Interest@qt-project.org > https://lists.qt-project.org/listinfo/interest > _______________________________________________ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest