[Interest] Converting CVImageBufferRef into QImage

Nuno Santos nunosantos at imaginando.pt
Fri Feb 28 16:42:20 CET 2020


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200228/2c57051b/attachment.html>


More information about the Interest mailing list