【发布时间】: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