这实际上早在 Qt 4.7 就可以通过使用 QVideoFrame 和 QAbstractVideoSurface 来实现。Qt 甚至有这个很好的例子来创建一个可以显示编程构造的 QVideoFrames 的视频小部件:
http://qt-project.org/doc/qt-4.8/multimedia-videowidget.html
您可以将此小部件与 QVideoFrame 的映射功能结合使用,以使用格式正确的数据填充单个视频帧。这应该看起来像这样:
实例化你的 videoWidget:
VideoWidgetSurface * videoWidget = new VideoWidgetSurface();
QSize videoSize(500,500); // supplement with your video dimensions
// look at VideoWidgetSurface::supportedPixelFormats for supported formats
QVideoSurfaceFormat format( videoSize, QVideoFrame::Format_RGB32, QAbstractVideoBuffer::QPixmapHandle)
// possibly fill with initial frame?
videoWidget->start(format);
...以及当您想要更新视频小部件的当前帧时:
// If you don't need the data in any past frames you can probably just create one frame
// and just use it repeadtly (as VideoWidgetSurface only keeps track of one frame at a time)
QVideoFrame aFrame(32 * format.frameWidth() * format.frameHeight(),format.frameSize(), 32 * format.frameWidth(),format.pixelFormat());
aFrame.map(QAbstractVideoBuffer::WriteOnly);
QRgb * pixels = aFrame.bits();
// perform pixel manipulation here...
aFrame.unmap();
videoWidget->present(aFrame);
.. 并结束播放...
videoWidget.stop();