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.
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);
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With