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. Where and in which widget should I put decoded video frames?

Where and in which widget should I put decoded video frames?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.0k Views 1 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.
  • L Offline
    L Offline
    lucaszanella
    wrote on last edited by lucaszanella
    #1

    In which widget should I display my ffmpeg decoded frames?

    I've found here: https://doc.qt.io/qt-5/videooverview.html that I can use a subclass of QAbstractVideoSurface to process my frames. And I used a QMediaPlayer and passed my QAbstractVideoSurface to it. However, QMediaPlayer is not a displayable element, so which element should output the frames? (In the right way, not using QImages or something like that). Also, my QMediaPlayer never calls the method bool present of QAbstractVideoSurface, so I don't know how it works.

    This is my code:

    QList<QVideoFrame::PixelFormat> VideoSurface::supportedPixelFormats(QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const
    {
        Q_UNUSED(handleType);
    
        // Return the formats you will support
        return QList<QVideoFrame::PixelFormat>() << QVideoFrame::Format_YUV420P;
    }
    
    bool VideoSurface::present(const QVideoFrame &frame)
    {
        //Q_UNUSED(frame);
        std:: cout << "VideoSurface processing 1 frame " << std::endl; 
    
        QVideoFrame frametodraw(frame);
    
        if(!frametodraw.map(QAbstractVideoBuffer::ReadOnly))
        {
            setError(ResourceError);
            return false;
        } 
        // Handle the frame and do your processing
        const size_t bufferSize = 398304;
        uint8_t frameBuffer[bufferSize];
        this->mediaStream->receiveFrame(frameBuffer, bufferSize);
        //Frame is now in frameBuffer, we must put into frametodraw, I guess
        // ------------What should I do here?-------------
        frametodraw.unmap();
        return true;
    }
    

    Look at this->mediaStream.decodeFrame(frameBuffer, bufferSize). This line decodes a new h264 frame into frameBuffer in the YUV420P format. Now I need to pass it to the QFrame and I must find a way to display this QFrame on screen

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

      Hi and welcome to devnet,

      Before digging into this, rather than doing things manually, did you consider using something like VLC-Qt that offers Qt support on top of VLC ?

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

      L 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Before digging into this, rather than doing things manually, did you consider using something like VLC-Qt that offers Qt support on top of VLC ?

        L Offline
        L Offline
        lucaszanella
        wrote on last edited by
        #3

        @SGaist thank you, but I really need to make it low level, and it's almost ready, as ffmpeg already works, it's just a matter of drawing the pixels in the screen in an efficient way

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

          IIRC, you should provide a custom class that provides a QVideoRendererControl interface like explained here.

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

          L 1 Reply Last reply
          0
          • SGaistS SGaist

            IIRC, you should provide a custom class that provides a QVideoRendererControl interface like explained here.

            L Offline
            L Offline
            lucaszanella
            wrote on last edited by
            #5

            @SGaist the problem is that QVideoRendererControl is also a not displayable element. I don't know which element of QT (like, which Widget) is going to display the video. Also, this class should implement QVideoRendererControl but what more? For example, I know I can set my AbstractVideoSurface to it, but when will it call my video surface?

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

              QVideoWidget will show your video. Implement a QMediaObject subclass that will provide the control interface. It will also be responsible for the decoding and the rest. Like the any of the QtMultimedia backend is.

              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