How to use a GStreamer pipeline to play a test video in a Qt QVideoWidget on Windows

3k Views Asked by At

I am trying to get a GStreamer test video to play in a Qt QVideoWidget using the Qt example code from here but the video never plays. The Qt widget is just a blank window like in this screenshot.

enter image description here

The code I am using is listed below. I am using Qt 5.13.0.

#include <QtWidgets/QApplication>
#include <QVideoWidget>
#include <QtMultimedia/QMediaPlaylist>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    auto player = new QMediaPlayer;
    auto videoWidget = new QVideoWidget;
    player->setMedia(QUrl("gst-pipeline: videotestsrc ! xvimagesink name=\"qtvideosink\""));
    videoWidget->show();
    player->setVideoOutput(videoWidget);
    player->play();

    return a.exec();
}

I have been able to successfully play a video in the Qt QVideoWidget from a video file using the same setup but with the following setMedia() call so I know the QVideoWidget will play video:

    player->setMedia(QUrl::fromLocalFile("C:/Users/<MyUser>/Videos/testVideo.wmv"));

I am also able to play the test video using GStreamer from the command line using the following:

gst-launch-1.0.exe videotestsrc ! autovideosink

It plays the test video shown below. This is what I would like to play in the Qt QVideoWidget.

enter image description here

0

There are 0 best solutions below