Congratulations to our 2022 Qt Champions!

QVideoFrames pixel format to Camera_Raw : for processing frames realtime.

  • Hi Friends

    I am working on a project that requires me to use the Macbook Camera. The idea is to process the video frames as they come.

    I read through the following document :

    which tells me that :

    "***For advanced usage (like processing viewfinder frames as they come, to detect objects or patterns), you can also derive from QAbstractVideoSurface and set that as the viewfinder for the QCamera object. In this case you will need to render the viewfinder image yourself.***"

    Hence, I create a class CameraFrameGrabber which looks like this :

    #include "cameraframegrabber.h"
    CameraFrameGrabber::CameraFrameGrabber(QObject *parent) :
    QList<QVideoFrame::PixelFormat> CameraFrameGrabber::supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType) const
    //    Q_UNUSED(handleType);
        if (handleType == QAbstractVideoBuffer::NoHandle) {
                return QList<QVideoFrame::PixelFormat>()
                        << QVideoFrame::Format_CameraRaw;
        return QList<QVideoFrame::PixelFormat>()
              << QVideoFrame::Format_RGB24;
    bool CameraFrameGrabber::present(const QVideoFrame &frame)
        if (frame.isValid()) {
            QVideoFrame cloneFrame(frame);
            QAbstractVideoBuffer::HandleType handleType;
              const QImage image(cloneFrame.bits(),
                              QVideoFrame::imageFormatFromPixelFormat(cloneFrame .pixelFormat()));
            emit frameAvailable(image);
            return true;
        return false;

    My issue is I need the images in Camera_Raw format. But I only end up getting the pixel format of the QVideoFrame as RGB_32. I am not able to change the QVideoFrame format. Can you please help me solve this?

    Thank you


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    AFAIK, you need to go lower level in order to modify the type of the generated image