如何将gstreamer 1.0视频元素添加到qt5应用程序

时间:2016-07-21 19:31:55

标签: c++ linux qt gstreamer

我试图在Linux上的Qt小部件中播放视频。

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

上述问题与我想要的非常接近,但是6岁。 qt5中不再存在QApplication::syncX();所以我放弃了它。我已将gst_x_overlay_set_xwindow_id()更改为gst_video_overlay_set_window_handle以更改gstreamer版本。

如果我没有将任何窗口句柄传递给视频接收器(我只是弹出一个带视频的新窗口),我的管道就可以工作。我不确定我是否错过了让它在Qt内部呈现的东西。

修改

我可以将整个应用程序窗口设置为叠加层,但不是主窗口小部件的子部分。此外,无法使应用程序正常工作,但glimagesink似乎有效。

// 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);

1 个答案:

答案 0 :(得分:2)

如果此处的目的只是渲染视频,您可以使用appsink,这将为您创建一个合适的窗口,您无需担心手动处理。

但是,如果您仍希望在窗口小部件窗口上呈现此内容,请尝试onPaint,读取接收器上的帧并使用窗口小部件中的videoconvert事件来呈现帧。只需确保帧的格式可以像RGB一样呈现,您可以通过capsfilter或通过glimagesink确保格式。您也可以使用qvideowidget并传递窗口ID来渲染帧。

如果您想使用上面提到的appsinkvideo_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); 上呈现视频,可以尝试:

(gdb) where
#0  0x001aa81b in do_lookup_x () from /lib/ld-linux.so.2
#1  0x001ab0da in _dl_lookup_symbol_x () from /lib/ld-linux.so.2
#2  0x001afa05 in _dl_fixup () from /lib/ld-linux.so.2
#3  0x001b5c90 in _dl_runtime_resolve () from /lib/ld-linux.so.2
#4  0x00275e4c in __gxx_personality_v0 () from /opt/gnatpro/lib/libstdc++.so.6
#5  0x00645cfe in _Unwind_RaiseException_Phase2 (exc=0x2a7b10, context=0xffd58434) at ../../../src/libgcc/../gcc/unwind.inc:67
#6  0x00646082 in _Unwind_RaiseException (exc=0x2a7b10) at ../../../src/libgcc/../gcc/unwind.inc:136
#7  0x0027628d in __cxa_throw () from /opt/gnatpro/lib/libstdc++.so.6
#8  0x00276e4f in operator new(unsigned int) () from /opt/gnatpro/lib/libstdc++.so.6
#9  0x08053737 in Receptor::receive (this=0x93c12d8, msj=...) at Receptor.cc:477
#10 0x08099666 in EventProcessor::run (this=0xffd75580) at EventProcessor.cc:437
#11 0x0809747d in SEventProcessor::run (this=0xffd75580) at SEventProcessor.cc:80
#12 0x08065564 in main (argc=1, argv=0xffd76734) at my_project.cc:20