Qt Multimedia GStreamer 后端
本页介绍Qt Multimedia GStreamer 后端的限制。
限制和已知问题
GStreamer 未与 Qt 捆绑,但通常与 Linux 发行版一起部署。
- 某些错误可能是由于使用的 GStreamer 版本造成的。我们建议在你的平台上使用最新的 GStreamer 错误修复版本。
- 某些错误也可能与 GStreamer 使用的库有关,如 Pulseaudio。最值得注意的是 Pulseaudio v16 有一个已知的 bug,会导致 GStreamer 管道挂起,需要使用这两个补丁的反向移植:
- https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/745
- https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/764
该漏洞目前影响到大多数主流 Linux 发行版,包括 Ubuntu 22.04、23.10 和 24.04、Debian 11 和 12 以及 Fedora 39 和 40。
- 寻道、播放率、循环、切换汇集存在已知错误。
- 音频功能需要 PulseAudio。详情请参见Linux 平台说明。
自定义点
Qt Multimedia GStreamer 提供了某些自定义点,允许访问底层 GStreamer 管道。这些定制点被视为私有 API,可能会有变动。入口点是 。class QGStreamerPlatformSpecificInterface
原始管道访问
可访问QMediaPlayer 和QMediaCaptureSession 的底层GstPipeline
。
警告: 这是一个不安全的 API,因为管道仍由 Qt 实现管理。使用此 API 时需要格外小心。
#include <QtMultimedia/private/qgstreamer_platformspecificinterface_p.h> [...] QMediaMediaPlayer player; GstPipeline *pipeline = QGStreamerPlatformSpecificInterface::instance()->gstPipeline(&player); [...] QMediaCaptureSession session; GstPipeline *pipeline = QGSreamerPlatformSpecificInterface::instance()->gstPipeline(&session);
自定义 GStreamer 元素作为汇和源
可以从 GStreamer 管道说明中创建 GStreamer 元素,并将它们封装在QCamera
或QAudioDevice
中:
#include <QtMultimedia/private/qgstreamer_platformspecificinterface_p.h> [...] QByteArray pipelineString = "videotestsrc is-live=true ! gamma gamma=2.0"; QMediaCaptureSession session; session.setVideoSink(wid.videoSink()); QCamera *cam = QGStreamerPlatformSpecificInterface::instance()->makeCustomGStreamerCamera( pipelineString, &session); session.setCamera(cam);
QMediaPlayer:自定义源
QMediaPlayer
接受 GStreamer 管道说明作为源 URI:
QMediaPlayer player; player.setSource(u"gstreamer-pipeline: videotestsrc name=testsrc"_s);
这将尝试编译管道描述,作为QMediaPlayer 中的源,并自动连接到QMediaPlayer 的汇。
警告: Hic sunt dracones!自定义管道是一项试验性功能:自定义管道不能很好地映射到QMediaPlayer API,尤其是媒体状态、元数据 API 和传输状态。大多数调用会直接映射到 GStreamer 管道,这可能会导致未定义的行为,具体取决于管道。在大多数情况下,gstreamer-pipeline:
可能不是应用代码的正确选择:对于任意视频源,带有自定义摄像头(见上文)的QMediaCaptureSession
是首选。对于只想绘制到 Qt/QML GUI 中的任意复杂管道,GStreamer 的qml6glsink
(见下文)可能是更稳健的选择。
架构考虑因素
Qt Multimedia GStreamer 并非通用流框架,也不一定是将 GStreamer 与 Qt 结合使用的最佳架构方式。如果开发人员需要对 GStreamer 管道进行高度控制,但又只想在 Qt 上显示视频输出,那么他们可能会考虑使用 GStreamer 的qml6glsink。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.