Rendering live video stream into graphics view in Qt
-
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;
}@
-
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
-
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
-
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().