C++ QMediaPlayer命令中的GST(gstreamer)命令

C++ QMediaPlayer命令中的GST(gstreamer)命令,c++,qt,qgraphicsview,qgraphicsscene,qmediaplayer,C++,Qt,Qgraphicsview,Qgraphicsscene,Qmediaplayer,我正在使用QtCreator 4.5.2(Qt5.9.5,GCC 7.3.0 64位)并在Ubuntu18.04上运行,我只是试图从IP摄像头获取实时视频流。我使用了“QGraphicsView”、“QGraphicscene”、“QGraphicsVideoItem”和QMediaPlayer方法 现在,视频流源是一个IP摄像头,我正在使用“QMediaPlayer”和“RTSP”来获取实时视频,它可以正常工作。但是,出于性能和其他原因,我需要更改为gstreamer类型的命令,如“gst-l

我正在使用QtCreator 4.5.2(Qt5.9.5,GCC 7.3.0 64位)并在Ubuntu18.04上运行,我只是试图从IP摄像头获取实时视频流。我使用了“QGraphicsView”、“QGraphicscene”、“QGraphicsVideoItem”和QMediaPlayer方法

现在,视频流源是一个IP摄像头,我正在使用“QMediaPlayer”和“RTSP”来获取实时视频,它可以正常工作。但是,出于性能和其他原因,我需要更改为gstreamer类型的命令,如“gst-launch-1.0”,以获取实时视频。我很难获得正确的“gst管道”管柱。我需要帮助

在“QMediaPlayer”的文档中,它声明:自Qt5.12.2以来,url方案gst管道为GStreamer后端提供自定义管道。 我的版本是5.9.5,所以我认为GStreamer类型的命令应该可以工作

相关代码和注释:

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


如果您的Qt版本早于5.12.2,则自定义管道将无法与
QMediaPlayer
一起使用,因为将使用
playbin

谢谢你的回复。我正在尝试使用“playbin”,并通过使用“QProcess”和“QMediaPlayer”来实现。但是,我想按照代码中的方式(QGraphicsVideoItem)执行操作,但找不到正确的gst管道。这是我的代码:mpPlayer1->setMedia(QUrl(“gst-launch-1.0 playbin uri=rtsp://20.0.2.118:8554/0")); 我得到了这个信息:GStreamer;无法暂停-“”如果我升级到5.12.2或更高版本,并将'gst-launch-1.0…'字符串放在'mpPlayer1->setMedia(“…”)中,它会工作吗?我刚刚尝试了gst字符串,gst-launch-1.0 playbin uri=rtsp://20.0.2.118:8554/0,并在Linux终端上运行。但是,我不知道为什么我不能放入“QMediaPlayer”中。你根本不需要
QProcess
。只需在应用程序中使用
QMediaPlayer
,如下所述。安装所有GStreamer插件(基本插件、好插件、坏插件、丑插件等等)。另外,如果您使用的是RTSP流媒体,那么您可能无法在1.14版之前使用GStreamer对rtspsrc进行拆卸,但在1.16版中可以。请注意,要使用Qt 5.12.2设置自定义管道,语法是
player->setMedia(QUrl(“gst管道:videotestsrc!autovideosink”)