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. Displaying video stream using Qt Multimedia and GStreamer process

Displaying video stream using Qt Multimedia and GStreamer process

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 8.3k Views
  • 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.
  • A Offline
    A Offline
    ADGB
    wrote on last edited by
    #1

    Hello here.

    I would like to display a video resulting from a "complex" GStreamer pipeline within a Qt GUI.

    Although Qt seems to have GStreamer backends and libraries, it appears easier to use the Qt Multimedia module and rely on the QMediaPlayer.setMedia() method. Particularly, as this function accepts any QIODevice stream, I thought I could use a QProcess to call the gstreamer command, redirect the output to stdout and let Qt take care of the rest.

    This is working pretty well using this video sample.

    #include <QApplication>
    #include <QMediaPlayer>
    #include <QWidget>
    #include <QVideoWidget>
    #include <QBoxLayout>
    #include <QProcess>
    #include <QDebug>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        QWidget *window = new QWidget;
        QVideoWidget *videoWidget = new QVideoWidget;
        QBoxLayout *layout = new QVBoxLayout;
        QMediaPlayer *player = new QMediaPlayer;
        QProcess *process = new QProcess;
    
        layout->addWidget(videoWidget);
        window->setLayout(layout);
        window->show();
        player->setVideoOutput(videoWidget);
    
        QString program = "gst-launch-1.0";
        QStringList arguments;
        arguments << "-v" << "filesrc" << "location=/home/adgb/Desktop/video.mp4" << "!" << "filesink" << "location=/dev/stdout";
    
    
        process->start(program, arguments);
        process->waitForReadyRead();
    
        player->setMedia(QMediaContent(), process);
        player->play();
    
        return a.exec();
    }
    

    However, I have trouble as soon as I try to replace the file source with videotestsrc.

    arguments << "-v" << "videotestsrc" << "!" << "video/x-raw,width=1280,height=720" << "!" << "filesink" << "location=/dev/stdout";
    

    I tried with several different pipelines, but it always results in an error like "Stream doesn't contain enough data" or "Could not determine type of stream".

    I wanted to use the videotestsrc as a first step, before implementing my whole pipeline implying live-streaming of remote camera, but I struggle to make even a simple command like this to work.

    Could anyone help me please? I am stuck on this issue since too many hours. :/

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

      Hi and welcome to devnet,

      Since you have a custom GStreamer pipeline, you could consider using the QtGStreamer module.

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

      A 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Since you have a custom GStreamer pipeline, you could consider using the QtGStreamer module.

        A Offline
        A Offline
        ADGB
        wrote on last edited by
        #3

        @SGaist Thanks for your answer.

        I am aware of QtGstreamer, unfortunately the installation procedure is difficult, requiring cmake and boost while we try hard to avoid such dependencies.

        As I managed to make gstreamer work a little using QProcess and QMediaPlayer, I was hoping there was a way to fix the problem for different video sources like videotestsrc and others .mp4 files (I realized the one I linked in my post worked fine, but error appears for others videos samples, worths investigating).

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ADGB
          wrote on last edited by ADGB
          #4

          Quick update about the issue I had to display .mp4 video samples.

          This was because of mixed content on the /dev/stdout, I guess GStreamer outputs sometime decoding information (figured out using the gst-launch-1.0 command line in a terminal) so Qt could not understand what type of data it received, and sometimes failed with an error "This appears to be a text file".

          As a workaround, just use stderr instead:

          arguments << "-v" << "filesrc" << "location=/home/adgb/Desktop/sample.mp4" << "!" << "filesink" << "location=/dev/stderr";
          
          process->setReadChannel(QProcess::StandardError);
          

          But this does not seem to fix the videotestsrc though.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ADGB
            wrote on last edited by
            #5

            Finally figured out how to display the videotestsrc stream!

            arguments << "-v" << "videotestsrc" << "!" << "video/x-raw,width=1280,height=720" << "!" << "x264enc" << "!" << "filesink" << "location=/dev/stderr";
            

            The QMediaPlayer seems to expect binary and encoded input. It makes plain sense actually as the first purpose of this class is to display video files. I guess it failed because I tried to feed decoded data.

            Pablo J. RoginaP H 2 Replies Last reply
            0
            • A ADGB

              Finally figured out how to display the videotestsrc stream!

              arguments << "-v" << "videotestsrc" << "!" << "video/x-raw,width=1280,height=720" << "!" << "x264enc" << "!" << "filesink" << "location=/dev/stderr";
              

              The QMediaPlayer seems to expect binary and encoded input. It makes plain sense actually as the first purpose of this class is to display video files. I guess it failed because I tried to feed decoded data.

              Pablo J. RoginaP Offline
              Pablo J. RoginaP Offline
              Pablo J. Rogina
              wrote on last edited by
              #6

              @ADGB great your issue seems solved. If so, please don't forget to mark your post as such. Thanks.

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • A ADGB

                Finally figured out how to display the videotestsrc stream!

                arguments << "-v" << "videotestsrc" << "!" << "video/x-raw,width=1280,height=720" << "!" << "x264enc" << "!" << "filesink" << "location=/dev/stderr";
                

                The QMediaPlayer seems to expect binary and encoded input. It makes plain sense actually as the first purpose of this class is to display video files. I guess it failed because I tried to feed decoded data.

                H Offline
                H Offline
                himanshu.d
                wrote on last edited by
                #7

                @ADGB ,

                I have tried your example.
                What I have observed is while running you example application it is opening two output widgets. One test and other for for the pipeline.
                Did you observed the same issue?
                If yes, how you resolved the issue?

                A 1 Reply Last reply
                0
                • H himanshu.d

                  @ADGB ,

                  I have tried your example.
                  What I have observed is while running you example application it is opening two output widgets. One test and other for for the pipeline.
                  Did you observed the same issue?
                  If yes, how you resolved the issue?

                  A Offline
                  A Offline
                  ADGB
                  wrote on last edited by
                  #8

                  @himanshu-d Sorry I never finalized this development.

                  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