Important: Please read the Qt Code of Conduct -

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.
    # 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\
    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 ?

  • Lifetime Qt Champion


    What Linux distribution are you running ?
    What Desktop Environment are you using ?
    What window manager are you using ?

  • @SGaist Hi, I was (at home) on my debian 9 with kde5 plasma but I should try too on centOs (because the target is RHEL).I can display my video with gst-launch but not with my program

  • Moderators

    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;

    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;

    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_element_set_state (pipeline, GST_STATE_NULL);
    gst_object_unref (pipeline);
    // Exit application
    QTimer::singleShot(0, QApplication::activeWindow(), SLOT(quit()));

    int ret = app.exec();


    gst_element_set_state (pipeline, GST_STATE_NULL);
    gst_object_unref (pipeline);

    return ret;

  • Moderators

    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

  • Lifetime Qt Champion

    Did you check the winID value ?

  • @SGaist Hi,yes xwinId=228589573

  • 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;
        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),
        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

  • Lifetime Qt Champion

    Do you get any error message on the console ?

  • @SGaist No there isn't any error message in the console

  • Lifetime Qt Champion

    Does it work if you follow GStreamer's Qt example ?

  • @SGaist I will try it,because I have modified it to have as source my I will try the example not modified and come here again.

  • @SGaist the example without my modifications runs there is something with my filesrc.but I can play my video with gstlaunch and decodebin and xvimagesink.

  • Lifetime Qt Champion

    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.

Log in to reply