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. How to show video frame by frame in Qt?
Forum Updated to NodeBB v4.3 + New Features

How to show video frame by frame in Qt?

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 5.4k 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.
  • T Offline
    T Offline
    Tejas Virpariya
    wrote on last edited by
    #1

    Hi,

    I used linux OS, I have system decoder, so I can play any type of video using Qt Player.

    Now I am trying to play video frame by frame, In my code I get frame from RTSP, and I stored it in one buffer, and this buffer I pass to player.

    sample code:

    QMediaPlayer* player[screen];
    QVideoWidget* vw[screen];
    ....
    while(1){
        if (NULL != fpFrames)
                    {
                        fwrite(u8NAL, 4, 1, fpFrames);
                        fwrite(streamData->dataBuffer, streamData->dataSize, 1, fpFrames);
    
    
                        mBuffer->open(QIODevice::ReadWrite);
                        mBuffer->seek(0);
                        mBuffer->setData((char *)streamData->dataBuffer,streamData->dataSize);
                        mBuffer->write((char *)streamData->dataBuffer);
                        mBuffer->seek(0);
    
                        if(playerFlag == 0){
    
                            player[0]->setMedia(QMediaContent(), mBuffer);
    
                            playerFlag = 1;
                            player[0]->play();
                        }
    }
    

    In above code I get frame in a streamData->dataBuffer, which is a void* type, I store this frame to QBuffer *mBuffer, and I pass this mBuffer to player, but when I run this code, player show only black screen. I store this buffer to one file also, I can play this file in VLC successfully. When I run this code, Application Output show some messages :

    QBuffer::setData: Buffer is open

    GStreamer; Unable to pause - ""

    QBuffer::setData: Buffer is open

    QBuffer::setData: Buffer is open

    QBuffer::setData: Buffer is open

    QBuffer::setData: Buffer is open

    QBuffer::setData: Buffer is open.............

    Now Please help me to come out this problem.

    Thanks
    Tejas Patel

    -Thanks
    Tejas Patel

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

      Hi,

      You neve close mBuffer hence the error message.

      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
      1
      • T Offline
        T Offline
        Tejas Virpariya
        wrote on last edited by
        #3

        Thanks @SGaist, but this is not a big issue, problem is I cannot show frame on my player using mBuffer, and ya when I store this buffer to any file and when I play this file it run successfully. How can i set media in a player? so I can show live stream.

        -Thanks
        Tejas Patel

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

          You're using an infinite loop that never gives control back to the main event loop so the video widget can't be refreshed.

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

          T 1 Reply Last reply
          1
          • T Offline
            T Offline
            Tejas Virpariya
            wrote on last edited by
            #5

            Thanks @SGaist : thats the point, now my question is where I have to put player->setmedia and player->play option?

            While loop give new data to buffer every time and I want to set this buffer into player, so please give right sequence.

            Thanks again..... :)

            -Thanks
            Tejas Patel

            1 Reply Last reply
            0
            • SGaistS SGaist

              You're using an infinite loop that never gives control back to the main event loop so the video widget can't be refreshed.

              T Offline
              T Offline
              Tejas Virpariya
              wrote on last edited by
              #6

              @SGaist Please tell me how can I handle buffer and player using thread in qt? means in a main thread buffer get data in while loop and in a thread player try to play that data.
              1.

              while(1){
                  buffer->write();
              }
              

              2.

              player->setdata(....);
              player->play();
              

              I want to handle both task simultaneously.. Please guide me for this task.
              Thanks for your great interest in every question...

              -Thanks
              Tejas Patel

              1 Reply Last reply
              0
              • jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                It should be other way around: player is in the main thread (because all UI related stuff must be in the main thread) and filling buffer is done in another thread. The second thread emits signal each time there is a new frame available and in main thread you connect to this signal and pass the frame to the player.
                Regarding multi-threading in Qt read this: http://doc.qt.io/qt-5/thread-basics.html

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • L Offline
                  L Offline
                  Lineaxe
                  wrote on last edited by
                  #8

                  Yes that sounds like the right way to handle it when using mulithreading . You can use this overall concept for handling many other types of multithreaded projects as well as In other languages such as XNA , C# and so on ...

                  1 Reply Last reply
                  1
                  • T Offline
                    T Offline
                    Tejas Virpariya
                    wrote on last edited by
                    #9

                    Thanks @jsulm and @Lineaxe : may you give sample code for thread? just give some lines of code how to use thread in my code for player and buffer... Thanks again...

                    -Thanks
                    Tejas Patel

                    jsulmJ 1 Reply Last reply
                    0
                    • T Tejas Virpariya

                      Thanks @jsulm and @Lineaxe : may you give sample code for thread? just give some lines of code how to use thread in my code for player and buffer... Thanks again...

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Tejas-Virpariya Please read the documentation (I posted the link before). It is a complex topic and you should understand what you are doing, giving you some lines of code will not really help.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        Tejas Virpariya
                        wrote on last edited by
                        #11

                        OK, I will try, actually I tried before to understand thread in Qt, it was difficult for me to understand. Thanks again @jsulm.

                        -Thanks
                        Tejas Patel

                        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