QGraphicsView not displaying QMediaPlayer's output that's using Gstreamer pipeline, instead just opens a new video window
-
Hi,
I've been having this problem for a long time now. I've tried searching for a similar problem before, and haven't found any answers.
I'm trying to play a video inside QGraphicsView, but it won't display in the widget despite many attempts. Instead it just shows the video in the new window. When playing the video from a local file, without using the gstreamer pipeline, the video is shown in the widget just fine but when using gstreamer pipeline it opens a new window.I'm cross-compiling to a Raspberry Pi 3B that's on Buster. I'm on Qt 5.12.5. Qt is compiled with Gstreamer version is 1.14.4.
I have the following code,
QGraphicsScene *scene = new QGraphicsScene(this); ui->videoStreamView->setScene(scene); QGraphicsVideoItem *videoItem = new QGraphicsVideoItem; QMediaPlayer *player = new QMediaPlayer(this, QMediaPlayer::VideoSurface); ui->videoStreamView->scene()->addItem(videoItem); player->setMedia(QUrl("gst-pipeline: udpsrc port=5801 ! application/x-rtp,payload=(int)96,encoding-name=(string)H264,clock-rate=(int)90000 ! rtpjitterbuffer latency=50 ! rtph264depay ! h264parse ! omxh264dec ! videoconvert ! ximagesink")); player->setVideoOutput(videoItem); player->play();
-
In the pipeline you have mentioned that ximagesink as the final sink plugin. The function of the ximagesink is to launch a new window. If you require the video frame to be displayed on the graphics view, you will have to use appsink as the final sink plugin.
Another approach will be to use the QtGst library to render the video. Please look at the demo examples on this Github repository.
https://github.com/GStreamer/qt-gstreamer/tree/master/examples
-
Hi,
As explained in the method documentation, you need to have a sink that is named qtvideosink.
-
@SGaist Hey thanks for the reply. Yes it does work for QVideoWidget and I have tried that and it worked for QVideoWidget specifically. However, I'm trying to play the video in QGraphicsView here, and I have tried using qtvideosink as the name of the sink and that didn't do anything for my situation. The reason why I'm trying to use the QGraphicsView is because I need to put widgets on top, which QVideoWidget doesn't allow transparent backgrounds for. I've seen it work for QGraphicsView which is why I'm pursuing this method of displaying the video.
-
What about QGraphicsVideoItem ?
-
@SGaist Thanks for replying again!
Yes I'm trying that, as it is shown above,
I set video output of QMediaPlayer to QGraphicsVideoItem which is an item of QGraphicsScene that belongs to QGraphicsView. I'm suspecting that it might be a bug or other issue that I'm not aware of.From using the QVideoWidget before, I found that if the sink is not compatible with the widget, then it will create an external window. I was using glimagesink before, and with QVideoWidget the video would display in a new window. However, with ximagesink the QVideoWidget displayed it internally. Hence, it could be that QGraphicsView setup might not be compatible with either sinks (glimagesink and ximagesink, I tried both). I tried the appsink suggestion above but it didn't work either.
-
Based on the setMedia documentation., you seem to be missing the
name=qtvideosink
part for your sink. -
@SGaist Yes, as I said before, I tried that. And I tried it again now. Same situation as before, video stream is working fine, but it opens a new window instead of displaying it inside QGraphicsView.
player->setMedia(QUrl("gst-pipeline: udpsrc port=5801 ! application/x-rtp,payload=(int)96,encoding-name=(string)H264,clock-rate=(int)90000 ! rtpjitterbuffer latency=50 ! rtph264depay ! h264parse ! omxh264dec ! videoconvert ! ximagesink name=qtvideosink"));
-
Hi everyone!
Set video output before setting the pipeline.
player->setVideoOutput(videoItem);
and then
player->setMedia(QUrl("gst-pipeline: udpsrc port=5801 ! application/x-rtp,payload=(int)96,encoding-name=(string)H264,clock-rate=(int)90000 ! rtpjitterbuffer latency=50 ! rtph264depay ! h264parse ! omxh264dec ! videoconvert ! ximagesink name=qtvideosink")); -
@RGutstein said in QGraphicsView not displaying QMediaPlayer's output that's using Gstreamer pipeline, instead just opens a new video window:
Hi everyone!
Set video output before setting the pipeline.
player->setVideoOutput(videoItem);
and then
player->setMedia(QUrl("gst-pipeline: udpsrc port=5801 ! application/x-rtp,payload=(int)96,encoding-name=(string)H264,clock-rate=(int)90000 ! rtpjitterbuffer latency=50 ! rtph264depay ! h264parse ! omxh264dec ! videoconvert ! ximagesink name=qtvideosink"));Thanks !