Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. Qt and gstreamer

Qt and gstreamer

Scheduled Pinned Locked Moved Unsolved 3rd Party Software
18 Posts 5 Posters 13.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stephane78 0
    wrote on 18 May 2019, 23:06 last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 19 May 2019, 21:14 last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply 20 May 2019, 18:53
      0
      • S SGaist
        19 May 2019, 21:14

        Hi,

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

        S Offline
        S Offline
        stephane78 0
        wrote on 20 May 2019, 18:53 last edited by stephane78 0
        #3

        @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

        R 1 Reply Last reply 20 May 2019, 19:15
        0
        • S stephane78 0
          20 May 2019, 18:53

          @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

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 20 May 2019, 19:15 last edited by
          #4

          @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

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          S 1 Reply Last reply 20 May 2019, 19:25
          1
          • R raven-worx
            20 May 2019, 19:15

            @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

            S Offline
            S Offline
            stephane78 0
            wrote on 20 May 2019, 19:25 last edited by stephane78 0
            #5

            @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;
            }

            R 1 Reply Last reply 20 May 2019, 19:30
            0
            • S stephane78 0
              20 May 2019, 19:25

              @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;
              }

              R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 20 May 2019, 19:30 last edited by
              #6

              @stephane78-0
              oh sry...i thought you are talking about the QtMultimedia module

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              S 1 Reply Last reply 20 May 2019, 19:38
              0
              • R raven-worx
                20 May 2019, 19:30

                @stephane78-0
                oh sry...i thought you are talking about the QtMultimedia module

                S Offline
                S Offline
                stephane78 0
                wrote on 20 May 2019, 19:38 last edited by
                #7

                @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

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 20 May 2019, 19:38 last edited by
                  #8

                  Did you check the winID value ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  S 1 Reply Last reply 20 May 2019, 19:47
                  1
                  • S SGaist
                    20 May 2019, 19:38

                    Did you check the winID value ?

                    S Offline
                    S Offline
                    stephane78 0
                    wrote on 20 May 2019, 19:47 last edited by stephane78 0
                    #9

                    @SGaist Hi,yes xwinId=228589573

                    S 1 Reply Last reply 16 Jun 2019, 12:25
                    0
                    • S stephane78 0
                      20 May 2019, 19:47

                      @SGaist Hi,yes xwinId=228589573

                      S Offline
                      S Offline
                      stephane78 0
                      wrote on 16 Jun 2019, 12:25 last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on 16 Jun 2019, 20:54 last edited by
                        #11

                        Do you get any error message on the console ?

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        S 1 Reply Last reply 16 Jun 2019, 21:30
                        1
                        • S SGaist
                          16 Jun 2019, 20:54

                          Do you get any error message on the console ?

                          S Offline
                          S Offline
                          stephane78 0
                          wrote on 16 Jun 2019, 21:30 last edited by
                          #12

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

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 17 Jun 2019, 21:33 last edited by
                            #13

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

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            S 1 Reply Last reply 20 Jun 2019, 18:29
                            1
                            • S SGaist
                              17 Jun 2019, 21:33

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

                              S Offline
                              S Offline
                              stephane78 0
                              wrote on 20 Jun 2019, 18:29 last edited by
                              #14

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

                              S 1 Reply Last reply 22 Jun 2019, 18:40
                              0
                              • S stephane78 0
                                20 Jun 2019, 18:29

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

                                S Offline
                                S Offline
                                stephane78 0
                                wrote on 22 Jun 2019, 18:40 last edited by stephane78 0
                                #15

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

                                S 1 Reply Last reply 22 Jun 2019, 18:48
                                0
                                • S stephane78 0
                                  22 Jun 2019, 18:40

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

                                  S Offline
                                  S Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 22 Jun 2019, 18:48 last edited by
                                  #16

                                  Then I would gradually modify the example until it does play the file you are trying to play with your code.

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  2
                                  • PeTroVicP Offline
                                    PeTroVicP Offline
                                    PeTroVic
                                    wrote on 4 Aug 2020, 22:18 last edited by
                                    #17

                                    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.

                                    1 Reply Last reply
                                    0
                                    • R Offline
                                      R Offline
                                      RajReddy
                                      wrote on 11 Jun 2021, 14:28 last edited by
                                      #18

                                      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
                                          }
                                      
                                      1 Reply Last reply
                                      0

                                      • Login

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • Users
                                      • Groups
                                      • Search
                                      • Get Qt Extensions
                                      • Unsolved