問題描述
我想用 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模板網!