1

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();

Steven Cao
  • 83
  • 2
  • 7

1 Answers1

1

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

Fryz
  • 2,119
  • 2
  • 25
  • 45
  • Thanks for the reply. I am trying to use 'playbin' and did get it work by using 'QProcess' and 'QMediaPlayer' to do that. But, I want to do like the way (QGraphicsVideoItem) in my code and could NOT find the correct gst-pipeline. Here is my code: mpPlayer1->setMedia(QUrl("gst-launch-1.0 playbin uri=rtsp://20.0.2.118:8554/0")); I got this message: GStreamer; Unable to pause - "" – Steven Cao Oct 11 '19 at 20:52
  • If I upgrade to 5.12.2 or later version and put 'gst-launch-1.0 ...' string in the 'mpPlayer1->setMedia("..")' is it going to work? – Steven Cao Oct 11 '19 at 20:57
  • I just tried the gst string, gst-launch-1.0 playbin uri=rtsp://20.0.2.118:8554/0, in the Linux terminal and it worked. But, I don't know why I could not put inside a 'QMediaPlayer'. – Steven Cao Oct 11 '19 at 21:05
  • You don't need a `QProcess` at all. Just use `QMediaPlayer` in your app as described here https://doc.qt.io/qt-5/qmediaplayer.html#setMedia. Install all GStreamer plugins (base, good, bad, ugly, ..). Also if you are using RTSP streaming, then you might not be able to have a TEARDOWN with rtspsrc using GStreamer up to v1.14 but in v1.16 it's fine. – Fryz Oct 12 '19 at 08:17
  • Note that to set a custom pipeline with Qt 5.12.2 the syntax is `player->setMedia(QUrl("gst-pipeline: videotestsrc ! autovideosink"));` – Fryz Oct 12 '19 at 08:23
  • I am still using Qt 5.9.5 and already have all plug-in: Base, Good, Band and Ugly. I have GStreamer v1.14 so I tried to play a local file by using this line 'player->setMedia(QUrl("gst-pipeline: playbin uri=file:///home/test1/Videos/tmp1.avi"));'. But, I still got this error message: GStreamer; Unable to pause - "gst-pipeline: playbin uri=file:///home/test1/Videos/tmp1.avi". Don't know why. Any idea? – Steven Cao Oct 14 '19 at 15:23
  • playbin is not a custom pipeline but a helper tool that build an appropriate pipeline according to your url. If you give an url, `QMediaPlayer` will call playbin internally and let it do all the work. Now if you wanna build your own pipeline, then just don't use playbin. GStreamer also gives you the ability to specifiy some parts of the pipeline used by playbin, for example you can ask playbin to use a specific video-sink. Look at this for more details about GStreamer https://gstreamer.freedesktop.org/documentation/tutorials/index.html?gi-language=c – Fryz Oct 21 '19 at 07:50