Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Rendering live video stream into graphics view in Qt

Rendering live video stream into graphics view in Qt

Scheduled Pinned Locked Moved Mobile and Embedded
5 Posts 3 Posters 3.2k 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
    sreeshreya
    wrote on last edited by
    #1

    Hello,

    I am working on a Qt application, which records and playback the live stream from the analog camera module(with video decoder ADV7180) connected to my computer on module. My aim is to render the live video coming from camera to a particular region(on to graphics view) in my Qt application.

    But when I click on the Play button, the live video is coming by creating its own separate window, where the other sides of the window showing as black and my Qt application is invisible from then.

    I have tried using gst_x_overlay_set_window_handle() and gst_x_overlay_set_render_rectangle() for setting the video only to the region of graphics view but with no success.

    Can someone guide me to the right direction in achieving this.

    I am using Linux qt image on to ColibriT20 COM and Qt version 4.8.5 and gstreamer-0.10 for playing my video pipeline

    Here is my code:

    @gboolean MainWindow::init_video_play_pipeline()
    {

    source = gst_element_factory_make ("v4l2src", "videosource");
    filter = gst_element_factory_make ("deinterlace", "filter");
    mixer = gst_element_factory_make ("nv_omx_videomixer", "videomixer");
    video_sink_caps_filter = gst_element_factory_make ("capsfilter","vCapsfilter");
    sink = gst_element_factory_make ("nv_gl_eglimagesink", "sink");

    if (!pipeline || !source || !filter || !mixer || !video_sink_caps_filter || !sink)
    {
    g_printerr ("Not all the elements were created. Exiting.\n");
    return false;
    }

    video_sink_caps = gst_caps_from_string("video/x-raw-gl,width=(int)720,height=(int)576");

    if(video_sink_caps == NULL)
    {
    g_print("\nCould not create caps string");
    }

    g_object_set(G_OBJECT(video_sink_caps_filter), "caps", video_sink_caps, NULL);
    gst_caps_unref(video_sink_caps);

    QApplication::syncX();
    setCentralWidget(ui->graphicsView);
    gst_x_overlay_set_window_handle(GST_X_OVERLAY(sink),ui->graphicsView->winId());

    /* creating bin*/
    bin_live = gst_bin_new ("bin");

    /* we add all elements into the pipeline /
    /
    file-source | filter | mixer | sink */
    gst_bin_add_many (GST_BIN (bin_live), source,filter,mixer,video_sink_caps_filter, sink,NULL);

    /* we link the elements together */
    if (gst_element_link_many(source, filter, mixer, video_sink_caps_filter, sink, NULL) != TRUE)
    {
    g_printerr ("Not all live video elements were linked.\n");
    return FALSE;
    }

    bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
    gst_bus_set_sync_handler (bus, bus_message_callback, this);
    g_print (" init_video_pipeline is called \n");

    return true;
    }

    gboolean MainWindow::add_bin_live_to_pipe()
    {
    if((gst_bin_add(GST_BIN (pipeline), bin_live)) != true)
    {
    g_print("\nbin_live not added to pipeline\n");
    return false;
    }

    // g_print ("add_bin_live_to_pipe function is called\n");
    if(gst_element_set_state (pipeline, GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS)
    {
    //g_print("element state is %s \n",gst_element_get_state(sink, NULL));
    return true;
    }
    else
    {
    g_print("\nFailed to set pipeline state to NULL\n");
    return false;
    }
    }

    gboolean MainWindow::start_video_play_pipe()
    {

    //GError *err;
    //gchar *debug;

    gst_element_set_state (pipeline, GST_STATE_PLAYING);
    g_print("start_video_play_pipe function is called\n");
    // gst_message_parse_error(msg,&err,&debug);
    //msg = gst_bus_timed_pop_filtered(bus,GST_CLOCK_TIME_NONE,GST_MESSAGE_ERROR | GST_MESSAGE_STREAM_STATUS);

    while(gst_element_get_state(pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) != GST_STATE_CHANGE_SUCCESS);
    return true;
    }

    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Not necessarily the answer you are looking for, but did you took a look at "QtGStreamer":http://gstreamer.freedesktop.org/modules/qt-gstreamer.html ? It proposes the Qt integration gstreamer

      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
      0
      • A Offline
        A Offline
        andreyc
        wrote on last edited by
        #3

        I don't think you will be able to use xoverlay with graphics framework.
        You need to use appsink and paint frames manually in QGraphicsItem

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sreeshreya
          wrote on last edited by
          #4

          Thank you for the suggestions. I was able to render the video to graphics view by adding a couple of widgets in the central widget.
          The sequence goes like this, on central widget added horizontal layout and over that added widget and then graphics view.
          In the code i have removed the setcentralwidget(ui->graphicsView), with this the video got rendered only on to the graphicsView window.

          The reason could be now the graphicsview gets the winId from its parent widget "widget" and to it by "horizontal layout" which wont allow in spreading the omx video window(from the pipeline) completely to the Qt application window like as central widget and confines the video only to graphicsView

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andreyc
            wrote on last edited by
            #5

            Glad you solved it.
            [quote author="sreeshreya" date="1416459574"]
            The reason could be now the graphicsview gets the winId from its parent widget "widget" and to it by "horizontal layout" which wont allow in spreading the omx video window(from the pipeline) completely to the Qt application window like as central widget and confines the video only to graphicsView[/quote]
            I think you won't be able to add any other graphic items on the same graphicsView with this architecture. If it is so and you don't need other QGraphicsItems then why not use QWidget::winId().

            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