Steven Cao
Steven Cao

Reputation: 93

GST (gstreamer) command in QMediaPlayer command

I am using Qt Creator 4.5.2 (Qt 5.9.5, GCC 7.3.0 64-bit) and running on Ubuntu 18.04 I am just trying to get live video stream from a IP camera. I used 'QGraphicsView', 'QGraphicsScene', 'QGraphicsVideoItem' and QMediaPlayer methods.

Right now, the video streaming source is a IP camera and I am using 'QMediaPlayer' with 'RTSP' to get the live video and it works. However, for performance and other reasons, I need to change to gstreamer type command, like 'gst-launch-1.0', to get the live video. I am having trouble to get the correct 'gst pipe' string. Need helps.

In the document for 'QMediaPlayer', it states: Since Qt 5.12.2, the url scheme gst-pipeline provides custom pipelines for the GStreamer backend. My version is 5.9.5 so I think the GStreamer type command should work.

Related Code and comments:

   // Setup GraphicsScene
   mpView = ui->gvCam;
   mpView->setVisible(true);
   mpScene = new QGraphicsScene;
   mpView->setScene(mpScene);
   mpScene->setSceneRect(0, 0, mpView->width(), mpView->height());
   mpView->setSceneRect(QRectF());
   // Setup IP camera
   mpPlayer1 = new QMediaPlayer;
   mpVideoItem1 = new QGraphicsVideoItem;
   mpPlayer1->setVideoOutput(mpVideoItem1);

   //The following line works and I got the live stream.
   mpPlayer1->setMedia(QUrl("rtsp://20.0.2.118:8554/0"));

   //However, I need to use GST type command, like:
   //gst-launch-1.0 rtspsrc location=rtsp://20.0.2.118:8554/0 ! decodebin ! videoscale \
               ! 'video/x-raw, width=480, height=270, format=I420' \
               ! xvimagesink sync=false force-aspect-ratio=false;

   //The above GST command worked if I issued from the terminal and I got the live stream. 
//But, I don't know how to put it as a 'gst pipeline' string as a parameter for  'setMedia' call.

   mpScene->addItem(mpVideoItem1);
   QSizeF qf1(mpView->width(), mpView->height());
   mpVideoItem1->setSize(qf1);
   mpVideoItem1->setAspectRatioMode(Qt::IgnoreAspectRatio);
   mpPlayer1->play();

Upvotes: 1

Views: 3445

Answers (1)

kzsnyk
kzsnyk

Reputation: 2211

If your Qt version is prior to 5.12.2 then a custom pipeline won't work with QMediaPlayer, because playbin is used instead.

Upvotes: 1

Related Questions