我使用的是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管道”字符串时遇到了问题。需要帮助。
在'QMediaPlayer‘的文档中,它声明:从Qt 5.12.2开始,url方案gst-pipeline为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();
发布于 2019-10-12 01:13:58
如果您的Qt版本是5.12.2之前的版本,那么自定义管道将不能与QMediaPlayer
一起工作,因为将使用playbin
。
https://stackoverflow.com/questions/58324750
复制相似问题