如何在基于GStreamer的Qt中实现一个视频窗口小部件? [英] How to implement a video widget in Qt that builds upon GStreamer?

查看:2221
本文介绍了如何在基于GStreamer的Qt中实现一个视频窗口小部件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Qt来创建一个简单的GUI应用程序,可以播放本地视频文件。我可以使用Phonon做幕后所有的工作,但我需要一个更多的控制。我已经成功地实现了一个GStreamer管道使用decodebin和autovideosink元素。现在我想使用一个Qt小部件来输出到。



有没有人成功地这样做? (我猜想,因为有基于Qt的视频播放器建立在GStreamer。)有人可以指向我正确的方向如何做吗?



注意:问题类似我以前发布的问题如何连接Qt与传入的RTP流。这似乎是相当具有挑战性。



更新1



Patrice建议使用libVLC非常有用已经。这里有一个更干净的版本的代码发现在VLC的网站:
Qt + libVLC示例
然而,我的原始问题仍然是:如何将GStreamer连接到Qt窗口小部件?



更新2



经过一些实验后,我最终获得了这项工作示例。具体取决于 GstWidget.h 和从我自己的小GstSupport库中 GstWidget.cpp 。但是,请注意,目前仅在Mac版本的Qt上测试。

解决方案

要将Gstreamer与QWidget连接需要使用 QWidget :: winId()获取窗口句柄,并将其传递给 gst_x_overlay_set_xwindow_id(); p>

粗糙示例代码:

  sink = gst_element_factory_make(xvimagesink,sink); 
gst_element_set_state(sink,GST_STATE_READY);

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

此外,您将希望您的窗口小部件由本机窗口支持, code> Qt :: AA_NativeWindows 属性或在窗口小部件级别的 Qt :: WA_NativeWindow 属性。


I want to use Qt to create a simple GUI application that can play a local video file. I could use Phonon which does all the work behind the scenes, but I need to have a little more control. I have already succeeded in implementing an GStreamer pipeline using the decodebin and autovideosink elements. Now I want to use a Qt widget to channel the output to.

Has anyone ever succeeded in doing this? (I suppose so since there are Qt-based video players that build upon GStreamer.) Can someone point me in the right direction on how to do it?

Note: This question is similar to my previous posted question on how to connect Qt with an incoming RTP stream. This seemed to be quite challenging. This question will be easier to answer I think.

Update 1

Patrice's suggestion to use libVLC is very helpful already. Here's a somewhat cleaner version of the code found on VLC's website: Sample for Qt + libVLC. However, my original question remains: How do I connect GStreamer to a Qt widget?

Update 2

After some experimentation I ended up with this working sample. It depends on GstWidget.h and GstWidget.cpp from my own little GstSupport library. However, take note that is is currently only tested on the Mac version of Qt.

解决方案

To connect Gstreamer with your QWidget, you need to get the window handle using QWidget::winId() and you pass it to gst_x_overlay_set_xwindow_id();

Rough sample code:

    sink = gst_element_factory_make("xvimagesink", "sink");
    gst_element_set_state(sink, GST_STATE_READY);

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

Also, you will want your widget to be backed by a native window which is achieved by setting the Qt::AA_NativeWindows attribute at the application level or the Qt::WA_NativeWindow attribute at the widget level.

这篇关于如何在基于GStreamer的Qt中实现一个视频窗口小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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