4

I'm trying to play video in a Qt widget on linux.

How to implement a video widget in Qt that builds upon GStreamer?

The above question is pretty close to what I want, but 6 years old. QApplication::syncX(); no longer exists in qt5 so I dropped that. I've also changed gst_x_overlay_set_xwindow_id() to gst_video_overlay_set_window_handle for the gstreamer version change.

My pipeline works if I don't pass any window handle to the video sink (it just pops up a new window with the video). I'm not sure if I'm missing something to get it to render inside of Qt though.


EDIT

I can set the entire app window as the overlay, but not a subsection of the main widget. Also, couldn't get the appsink working, but glimagesink seems to work.

// QWidget* widget = QApplication::activeWindow(); // this works
QWidget* widget = new QWidget(ui->base_widget); // this doesn't work
widget->setAttribute(Qt::WA_NativeWindow, true);
widget->resize(320,240);
widget->update();
widget->setStyleSheet("background-color: red");
widget->show();
winId = widget->winId();
QApplication::sync();
gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(sink) , winId);
Community
  • 1
  • 1
James
  • 2,742
  • 1
  • 20
  • 43

1 Answers1

3

If the purpose here is to just render video you can use autovideosink which will create a suitable window for you and you would not need to worry about handling this manually.

However if you still want to render this on a widget window say, try the appsink, read the frames on the sink and use the onPaint event in your widget to render the frames. Just be sure the frames are in format which can be rendered like RGB you can do that via the videoconvert or ensure format via the capsfilter. You might also be able to use glimagesink and pass that your window id to render the frames.

if you want to render the video on a qvideowidget using appsink as mentioned above you could try:

video_widget->setAttribute(Qt::WA_NativeWindow, true);
WId win_id = video_widget->winId();
QApplication::sync();
gst_x_overlay_set_window_handle(GST_X_OVERLAY(data->appsink), win_id);
Samer Tufail
  • 1,835
  • 15
  • 25
  • Thanks Samer, I'll try out appsink. What is this onPaint event you are suggesting me use? A cursory googling has failed me. Are there any references that I could check out. – James Aug 05 '16 at 01:50
  • onPaint was using a Canvas type. See here for more details: http://doc.qt.io/qt-5/qml-qtquick-canvas.html. The quickest way would be to use a qvideowidget with the code I pasted above. That allows you to link your videowidget with the appsink. – Samer Tufail Aug 05 '16 at 07:57
  • I'm still having a little trouble getting everything working, might come back to ask you a couple more questions if that's okay with you Samer =) – James Aug 09 '16 at 19:10
  • Sure thing, thats why we are all here ;) – Samer Tufail Aug 09 '16 at 19:27
  • I couldn't find gst_x_overlay_set_window_handle but I do have gst_video_overlay_set_window_handle. is gst_x_overlay_set_window_handle still part of gstreamer 1.0? – James Aug 11 '16 at 22:32
  • I got it working for OSX but have been having trouble on linux. – James Aug 11 '16 at 22:46
  • gst_x_overlay_set_window_handle is gst 0.10, however you can use the alternate, gst_video_overlay_set_window_handle. There is a Qt example in the documentation: https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/gst-plugins-base-libs-gstvideooverlay.html. What problems are you having? – Samer Tufail Aug 12 '16 at 09:12
  • The video doesn't render. I see a black square. – James Aug 12 '16 at 21:31
  • What do the connected elements look like? Try adding a color space filter? – Samer Tufail Aug 12 '16 at 22:55
  • right now its just "videotestsrc ! glimagesink". What would a color space filter do? – James Aug 23 '16 at 06:12
  • Rendering problems are generally related to color space that's why, I remember seeing this along time back. Can you try videotestsrc ! "video/x-raw, format=xyz" ! glimagesink where xyz can be replaced with RGB, RGBA, YV12, NV12, I420, YUY2, UYVY – Samer Tufail Aug 23 '16 at 07:48