Fastest way to render a VideoFrame?

  • I have a grabber card, where I receive my video frames.
    I have all the code to grab the frames.
    Now I want to render the frame. How can I do this efficient for Qt-Desktop?
    With QML it was easy, using the "VideoOutput" node.

    But where is the C++ equivalent for this, because I don't want to use QML atm.
    I saw QVideoWidget, but this seems to be only plug able to a MediaPlayer...
    So what to do here? Has anybody a small code snippet for me?

  • Lifetime Qt Champion


    How did you do it for QML ?

  • Here is my simplified code for the Grabber:
    The grabber object will be exposed to the QML engine.
    It has a property called: videoSurface, this is required from the VideoOutput element in QML.

    class grabber : public QObject
        Q_PROPERTY(bool capture READ is_capturing WRITE set_enable_capturing)
        //! This property is needed to connect a VideoOutput with this grabber.
        Q_PROPERTY(QAbstractVideoSurface* videoSurface READ get_video_surface WRITE set_video_surface)
        QAbstractVideoSurface* get_video_surface() const;
        void set_video_surface(QAbstractVideoSurface* s);
        QAbstractVideoSurface* m_video_surface;

    Somewhere in grabber.cpp I just update the video surface when I get a new video frame from the grabber.

    connect(m_grabber.get(), &matrox_grabber::new_video_frame, this, [this](const QVideoFrame& frame)
            if (m_video_surface)

    My matrox_grabber has all the logic to retrieve frame and put it into a QVideoFrame.

    And here is the QML file:

    # Main.qml
    import QtQuick 2.3
    import QtQuick.Controls 1.2
    import QtQuick.Window 2.2
    import QtMultimedia 5.9
    import divas.components 1.0
    ApplicationWindow {
     id: window
      visible: true
      Grabber {
        id: matrox
       VideoOutput {
            source: matrox;
            anchors.centerIn: parent;
            width: parent.width;
            height: parent.height;

  • Lifetime Qt Champion

    I usually wrote that kind of backend as QCamera plugins which makes it simpler to integrate with both C++ and QML

    IIRC, you might be able to avoid that by implementing a QMediaObject subclass that provides the adequate interface basically grabber should become a QMediaObject. However I'm not sure whether you can then just call bind on your QVideoWidget from your grabber instance.

  • @SGaist Hello Samuel, do you have any pointer to a doc on how to create QCamera plugins ?

  • Lifetime Qt Champion

    Hi, sorry, no I don't. I went it hardcore style and looked at the various camera backend implemented by Qt. You'll see that it's not that complicated to put together.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.