tags:

views:

1905

answers:

7

I tried using phonon to play the video but could not succeed. Off-late came to know through the Qt forums that even the latest version of Qt does not support phonon. Thats when i started using Gstreamer.Any suggestions as to how to connect the Gstreamer window with the Qt widget?My aim is to play a video using Gstreamer on the Qt widget.So how do i link the gstreamer window and the Qt widget?

I am successful in getting the Id of the widget through winid(). Further with the help of Gregory Pakosz, I have added the below 2 lines of code in my application -

QApplication::syncX();
gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(sink), widget->winId());

However am not able to link the Qt widget with the gstreamer video window.

This is what my sample code would look like :-

int main(int argc, char *argv[])
{
printf("winid=%d\n", w.winId());
    gst_init (NULL,NULL);
    /* create a new bin to hold the elements */
    bin = gst_pipeline_new ("pipeline");

      /* create a disk reader */
  filesrc = gst_element_factory_make ("filesrc", "disk_source");
  g_assert (filesrc);



  g_object_set (G_OBJECT (filesrc), "location", "PATH_TO_THE_EXECUTABLE", NULL);

  demux = gst_element_factory_make ("mpegtsdemux", "demuxer");
  if (!demux) {
    g_print ("could not find plugin \"mpegtsmux\"");
    return -1;
  }

  vdecoder = gst_element_factory_make ("mpeg2dec", "decode");
  if (!vdecoder) {
    g_print ("could not find plugin \"mpeg2dec\"");
    return -1;
  }

  videosink = gst_element_factory_make ("xvimagesink", "play_video");
  g_assert (videosink);


  /* add objects to the main pipeline */

  gst_bin_add_many (GST_BIN (bin), filesrc, demux, vdecoder, videosink, NULL);


  /* link the elements */
  gst_element_link_many (filesrc, demux, vdecoder, videosink, NULL);

    gst_element_set_state(videosink, GST_STATE_READY);

    QApplication::syncX();
    gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(videosink), w.winId());



  /* start playing */
  gst_element_set_state (bin, GST_STATE_PLAYING);

}

Could you explain more in detail about the usage of gst_x_overlay_set_xwindow_id() wrt my context?

Could i get any hint as to how i can integrate gstreamer under Qt? Please help me solve this problem

A: 

A project wrapping gstreamer into usable C++/Qt classes including example code: http://code.google.com/p/qbtgstreamer/

I don't know about a direct approach, as I am not familiar with gstreamer itself.

penguinpower
this link is dead, im looking for away to stream rtsp in qt also without success any help will be great!
A: 

Phonon is part of Qt (at least for now) so I think you can use it to access the underlying gstreamer back-end. I don't know how you could be concerned about what back-end is phonon using, though.

jgblanco
n1ce copy and paste from my comment though...
penguinpower
I tried using phonon to play the video but could not succeed. Oflate came to know through the Qt forums that even the latest version of Qt does not support phonon.Thats when i started using Gstreamer.Any suggestions as to how to connect the Gstreamer window with the Qt widget?
raggio
A: 

Many thanks for your attention to my problem. But am still clueless as to how to force the Gstreamer video to be played on Qt Widget. How do i link the GstXOverlay() and Qt ? In anticipation for a reply

raggio
A: 

I have also attached the code in the start of this post. Could anyone say if am going in the right direction?
The code compiles without any warnings and errors but the video does not get displayed. I am able to play the video with gstreamer command from the terminal but please do suggest how i can integrate it with Qt and get it played on the qt widget?

Please can you suggest what the mistake(s) might be?

raggio
+1  A: 

http://cgit.freedesktop.org/gstreamer/gst-plugins-base/tree/tests/examples/overlay

has a minimal Qt example.

In your code, you should probably set the window ID before you do the state change to ready (I'm not 100% sure this is the problem though).

For playback, you should idally use the playbin2 element, something like this (completely untested):

GstElement *playbin, *videosink; gchar *uri;

playbin = gst_element_factory_make ("playbin2", "myplaybin"); videosink = gst_element_factory_make ("xvimagesink", NULL);

g_object_set (playbin, "video-sink", videosink, NULL);

uri = g_filename_to_uri ("/path/to/file", NULL, NULL); g_object_set (playbin, "uri", uri, NULL); g_free (uri);

/* NOTE: at this point your main window needs to be realized, * ie visible on the screen, and you might need to make sure * that your widget w indeed has a 'native window' (just some * things to check for if it doesn't work; there should be Qt * API for this kind of thing if needed) */ QApplication::syncX();  gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(videosink), w.winId());

gst_element_set_state (playbin, GST_STATE_PLAYING);

.. check for messages like error/statechanges/tags/eos on pipeline/playbin bus

Tim
A: 

I just did this same thing using python. What I had to do was connect to 'sync-message::element' on the bus and listen for a message called 'prepare-xwindow-id' (disregard the name as it works on all platforms, not just X11) sent after the video sink is setup. It sends you the sink inside that message, and that is where you pass it the window id.

bparker