将Gstreamer与Qt连接以便在Qt小部件中播放gstreamer视频 [英] To connect Gstreamer with Qt in order to play a gstreamer video in the Qt Widget

查看:847
本文介绍了将Gstreamer与Qt连接以便在Qt小部件中播放gstreamer视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用声子播放视频,但无法成功.后来通过Qt论坛得知,即使最新版本的Qt也不支持声子.那就是我开始使用Gstreamer的时候.关于如何将Gstreamer窗口与Qt小部件连接的任何建议?我的目的是在Qt小部件上使用Gstreamer播放视频.那么如何链接Gstreamer窗口和Qt小部件?

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. That's 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?

我成功地通过winid()获得了小部件的Id. 进一步在Gregory Pakosz的帮助下,我在应用程序中添加了以下两行代码-

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());

但是无法将Qt小部件与gstreamer视频窗口链接.

这是我的示例代码的样子:-

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

}

您能否详细说明我在上下文中使用gst_x_overlay_set_xwindow_id()的情况?

我能否获得有关如何在Qt下集成gstreamer的任何提示? 请帮我解决这个问题.

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

推荐答案

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

有一个最小的Qt示例.

has a minimal Qt example.

在您的代码中,您可能应该在状态更改为就绪之前设置窗口ID(尽管我不是100%确信这是问题所在).

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).

要进行播放,您应该闲置地使用playbin2元素,如下所示(完全未经测试):

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

..检查管道/playbin总线上的错误/状态更改/标签/eos之类的消息

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

这篇关于将Gstreamer与Qt连接以便在Qt小部件中播放gstreamer视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆