Qt and gstreamer
-
Hi I have made a program based on the example of gstreamer-1.0 "GstOverlay and Qt" but the video is not displayed in my widget
I play the same video with the same pipeline with gst-launch but in my program with Qt the video is not displayed (Qt5.12.3 and gstreamer 1.10 )
I think my .pro is not correct :#------------------------------------------------- # # Project created by QtCreator 2017-11-06T21:33:02 # #------------------------------------------------- QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = gst01 TEMPLATE = app INCLUDEPATH +="/usr/include" INCLUDEPATH +="/usr/include/glib-2.0" INCLUDEPATH +="/usr/include/gstreamer-1.0" CONFIG += link_pkgconfig PKGCONFIG += gstreamer-1.0 PKGCONFIG += gstreamer-video-1.0 # The following define makes your compiler emit warnings if you use # any feature of Qt which as been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 LIBS+=-L"/usr/lib/x86_64-linux-gnu/gstreamer-1.0" -lgstxvimagesink -L"/usr/lib/x86_64-linux-gnu" -lgstbase-1.0 -lgstreamer-1.0 -lglib-2.0 -lgobject-2.0 SOURCES += main.cpp\ mainwindow.cpp HEADERS += mainwindow.h FORMS += mainwindow.ui
my pipeline is filesrc and decodebin and xvimagesink and my code is like the exemple here : GstVideoOverlay
can someone help me ?
-
Hi,
What Linux distribution are you running ?
What Desktop Environment are you using ?
What window manager are you using ? -
@stephane78-0
since you are using gstreamer-1.0, did you also compile Qt with gstreamer-1.0 support? AFAIK it uses gstreamer-0.1 by default -
@raven-worx Hi thank you,no I didn't compile Qt with gstreamer 1.0 support but do you think I need this ? because I use only a QWidget and the winId handle of the QWidget , here is my code :```
#include <glib.h>
#include <gst/gst.h>
#include <gst/video/videooverlay.h>#include <QApplication>
#include <QTimer>
#include <QWidget>int main(int argc, char *argv[])
{
if (!g_thread_supported ())
g_thread_init (NULL);gst_init (&argc, &argv);
QApplication app(argc, argv);
//MainWindow w;
QWidget w;
w.resize(640,480);app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit ()));
// prepare the pipeline
GstElement *pipeline = gst_pipeline_new ("xvoverlay");
GstElement *videosrc = gst_element_factory_make ("filesrc","videosrc");
GstElement *videoscale=gst_element_factory_make("videoscale",NULL);
GstElement *capsfilter=gst_element_factory_make("capsfilter",NULL);
GstElement *sink = gst_element_factory_make ("xvimagesink", NULL);
GstElement *decodebin = gst_element_factory_make("decodebin", NULL);//g_object_set (G_OBJECT(playbin),"uri","file:///home/user/Downloads/thesimpsonstrailer.mp4");
g_object_set (G_OBJECT (videosrc), "location", "/home/user/Downloads/small.mp4", NULL);
GstCaps *caps = gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING, "RGB",
"framerate", GST_TYPE_FRACTION, 25, 1,
"width", G_TYPE_INT, 640,
"height", G_TYPE_INT, 480,NULL);g_object_set(G_OBJECT(capsfilter), "caps", caps, NULL);
gst_caps_unref (caps);
gst_bin_add_many (GST_BIN (pipeline), videosrc, decodebin, sink, NULL);
gst_element_link_many(videosrc, decodebin, NULL);
gst_element_link_many(decodebin, sink, NULL);// prepare the ui
w.show();
gst_element_set_state(sink, GST_STATE_READY);
WId xwinid =w.winId();
gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (sink), xwinid);// run the pipeline
GstStateChangeReturn sret = gst_element_set_state (pipeline,
GST_STATE_PLAYING);
if (sret == GST_STATE_CHANGE_FAILURE)
{
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
// Exit application
QTimer::singleShot(0, QApplication::activeWindow(), SLOT(quit()));
}int ret = app.exec();
w.hide();
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);return ret;
} -
@stephane78-0
oh sry...i thought you are talking about the QtMultimedia module -
@raven-worx Hi ,you have perhaps a good idea I will try to compile Qt with gstreamer 1.0 support and I come again back
-
Did you check the winID value ?
-
Hi, I have tryed another method with the plugin qmlsink s owith qml but I have a black screen, my code comes from an exemple of the plugin good on github:
int main(int argc, char *argv[]) { int ret; gst_init (&argc, &argv); { QGuiApplication app(argc, argv); GstElement *pipeline = gst_pipeline_new (NULL); //GstElement *src = gst_element_factory_make ("videotestsrc", NULL); GstElement *src = gst_element_factory_make ("filesrc","videosrc"); GstElement *glupload = gst_element_factory_make ("glupload", NULL); GstElement *decodebin = gst_element_factory_make("decodebin", NULL); /* the plugin must be loaded before loading the qml file to register the * GstGLVideoItem qml item */ GstElement *sink = gst_element_factory_make ("qmlglsink", NULL); g_assert (src && glupload && sink); g_object_set (G_OBJECT (src), "location", "/home/user/Downloads/small.mp4", NULL); gst_bin_add_many (GST_BIN (pipeline), src, decodebin, glupload, sink, NULL); gst_element_link_many (src, decodebin, glupload, sink, NULL); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); QQuickItem *videoItem; QQuickWindow *rootObject; /* find and set the videoItem on the sink */ rootObject = static_cast<QQuickWindow *> (engine.rootObjects().first()); videoItem = rootObject->findChild<QQuickItem *> ("videoItem"); g_assert (videoItem); g_object_set(sink, "widget", videoItem, NULL); rootObject->scheduleRenderJob (new SetPlaying (pipeline), QQuickWindow::BeforeSynchronizingStage); ret = app.exec(); gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline); } gst_deinit (); return ret;
so there is perhaps a problem with my debian 9 or it lacks a library
-
Do you get any error message on the console ?
-
Does it work if you follow GStreamer's Qt example ?
-
-
Then I would gradually modify the example until it does play the file you are trying to play with your code.
-
Hey @SGaist and @stephane78-0 ,
Did anyone managed to run that example with "filesrc" instead of "videotestsrc" ?This example works for me, but it uses "videotestsrc" as Source, but I would like to use "filesrc".
Because, I want to be able to use a custom video.I'm guessing that I need help with GStreamer, and not QT necessarily. But it's worth taking a shot.
-
you can try:
MediaPlayer{ id: playVideo source: "gst-pipeline: filesrc location=/home/root/skim-debris.mp4 ! qtdemux ! avdec_h264 ! qtvideosink" autoLoad: true autoPlay: true playbackRate: 1.0 loops: 10 } VideoOutput { anchors.fill: parent source: playVideo }