English 中文(简体)
How to implement a video widget in Qt that builds upon GStreamer?
原标题:

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.

问题回答

Since Phonon is based on gstreamer, the place to look for details is the Phonon source tree (available here: http://gitorious.org/phonon/import/trees/master). For a video player you are most likely going to need a video display widget, such as the gstreamer/videowidget.h (cpp) that in turn used the X11 renderer (gstreamer/x11renderer.h, cpp). The sink used is the xvimagesink, falling back onto the ximagesink if the first cannot be created.

The basic trick is to overlay the VideoWidget with the video output. The X11 handle needed to do this is retrieved using the QWidget::winId method, which is platform specific (as are the sinks, so no biggie).

Also, if overlay is unavailable, a QWidgetVideoSink is used, which converts the video frames into individual frames for the WidgetRenderer class. This class, in turn, makes the current frame available as a QImage object, ready for any type of processing.

So to answer your question - use either overlays (as X11Renderer) or extract individual QImages from the video stream (as QWidgetVideoSink).

VLC version is a QT-based video player (since version 0.99). It allows too to stream or read a stream: You can find all information you need here: http://wiki.videolan.org/Developers_Corner. You only have create an instance of the player and associate it to a widget. Then you have full control on the player.

I have already tested it (on Linux and Windows) playing local music and video files and it works fine.

Give it a try and see by yourself.

Hope that helps.

Edit: It seems if you want to use VLC, you need to write or find (I do not know if one exists) a GStreamer codec as explain on the videolan wiki. I think I would do that.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签