我想用 Qt 创建一个简单的 GUI 应用程序,可以播放本地视频文件.我可以使用 Phonon 来完成幕后的所有工作,但我需要更多的控制权.我已经成功地使用 decodebin 和 autovideosink 元素实现了 GStreamer 管道.现在我想使用 Qt 小部件将输出引导至.
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.
有没有人成功地做到了这一点?(我想是的,因为有基于 GStreamer 的基于 Qt 的视频播放器.)有人能指出我正确的方向吗?
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?
注意:这个问题类似于我之前发布的关于如何将 Qt 与传入的 RTP 流连接的问题.这似乎很有挑战性.我想这个问题会更容易回答.
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.
Patrice 的使用 libVLC 的建议已经很有帮助了.这是在 VLC 网站上找到的代码的更清晰版本:Qt + libVLC 示例.但是,我最初的问题仍然是:如何将 GStreamer 连接到 Qt 小部件?
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?
经过一些实验,我最终得到了这个工作示例.这取决于 GstWidget.h 和 GstWidget.cpp来自我自己的小 GstSupport 库.但是,请注意,目前仅在 Mac 版本的 Qt 上进行了测试.
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.
要将 Gstreamer 与您的 QWidget 连接,您需要使用 QWidget::winId()
获取窗口句柄并将其传递给gst_x_overlay_set_xwindow_id();
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();
粗略示例代码:
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());
此外,您还希望您的小部件由本机窗口支持,这是通过在应用程序级别设置 Qt::AA_NativeWindows
属性或 Qt::WA_NativeWindow
来实现的code> 小部件级别的属性.
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 中实现视频小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!