Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Fastest way to render a VideoFrame?
Qt 6.11 is out! See what's new in the release blog

Fastest way to render a VideoFrame?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 2.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zack
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      HI,

      How did you do it for QML ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zack
        wrote on last edited by
        #3

        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_OBJECT
        
            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)
                    m_video_surface->present(frame);
            });
        

        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;
                }
        
        }
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          R 1 Reply Last reply
          2
          • SGaistS SGaist

            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.

            R Offline
            R Offline
            r2d3
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved