【问题标题】:GST (gstreamer) command in QMediaPlayer commandQMediaPlayer 命令中的 GST (gstreamer) 命令
【发布时间】:2020-02-08 00:10:33
【问题描述】:

我正在使用 Qt Creator 4.5.2(Qt 5.9.5,GCC 7.3.0 64 位)并在 Ubuntu 18.04 上运行,我只是想从 IP 摄像机获取实时视频流。我使用了 'QGraphicsView'、'QGraphicsScene'、'QGraphicsVideoItem' 和 QMediaPlayer 方法。

现在,视频流源是 IP 摄像机,我正在使用“QMediaPlayer”和“RTSP”来获取实时视频,并且它可以正常工作。但是,出于性能和其他原因,我需要更改为 gstreamer 类型命令,例如“gst-launch-1.0”,以获取实时视频。我无法获得正确的“gst pipe”字符串。需要帮助。

在“QMediaPlayer”的文档中,它指出:从 Qt 5.12.2 开始,url 方案 gst-pipeline 为 GStreamer 后端提供自定义管道。 我的版本是 5.9.5,所以我认为 GStreamer type 命令应该可以工作。

相关代码和cmets:

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

【问题讨论】:

    标签: c++ qt qgraphicsview qgraphicsscene qmediaplayer


    【解决方案1】:

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

    【讨论】:

    • 感谢您的回复。我正在尝试使用“playbin”,并通过使用“QProcess”和“QMediaPlayer”来做到这一点。但是,我想在我的代码中这样做(QGraphicsVideoItem)并且找不到正确的gst-pipeline。这是我的代码: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("..")' 中是否可以工作?
    • 我刚刚在 Linux 终端中尝试了 gst 字符串 gst-launch-1.0 playbin uri=rtsp://20.0.2.118:8554/0,它工作正常。但是,我不知道为什么我不能放入“QMediaPlayer”。
    • 您根本不需要QProcess。只需在您的应用程序中使用QMediaPlayer,如doc.qt.io/qt-5/qmediaplayer.html#setMedia 所述。安装所有 GStreamer 插件(基础、好、坏、丑……)。此外,如果您使用的是 RTSP 流,那么您可能无法使用 rtspsrc 进行 TEARDOWN 使用 GStreamer 直到 v1.14,但在 v1.16 中它很好。
    • 请注意,要使用 Qt 5.12.2 设置自定义管道,语法为 player->setMedia(QUrl("gst-pipeline: videotestsrc ! autovideosink"));
    猜你喜欢
    • 2011-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    • 2011-04-25
    相关资源
    最近更新 更多