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

Reply via email to