本页内容

QGStreamerVideoSource Class

QGStreamerVideoSource 类提供了一个由自定义 GStreamer 元素支持的视频源。更多内容...

头文件: #include <QGStreamerVideoSource>
CMake: find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
qmake: QT += multimedia
自: Qt 6.12
在 QML 中: GStreamerVideoSource
继承自: QObject

属性

公共函数

QGStreamerVideoSource(GstElement *gstElement, QObject *parent = nullptr)
QGStreamerVideoSource(const QString &gstBinDescription, QObject *parent = nullptr)
QString gstBinDescription() const
GstElement *gstElement() const
bool isActive() const

公共槽位

void setActive(bool active)
void start()
void stop()

信号

void activeChanged(bool active)

详细说明

警告: GStreamerVideoSource 类 提供的兼容性保证有限。对于这些类,不提供源代码或二进制兼容性保证,这意味着仅保证该API可在应用程序所基于的Qt版本上正常运行。 不过,我们会尽量将不兼容的更改控制在最低限度,且仅在小版本更新中进行此类更改。要在应用程序中使用该类,请链接到Qt::MultimediaPrivate (若使用 CMake),并包含头文件 #include <spi/qgstreamervideosource.h>。

根据 GStreamer bin 描述或现有的GstElement 实例构建 QGStreamerVideoSource,并通过QMediaCaptureSession::setNativeVideoSource() 将其附加到QMediaCaptureSession 上。

对于任何标准情况,我们建议使用QCamera 而非本类,除非您需要 GStreamer 特定的配置来处理任何自定义视频源。

默认情况下,该类在 meta-qt6 构建中可用。在支持 GStreamer 的自定义构建中,可通过启用gstreamer_qt_api 功能来启用它。

QtMultimedia 必须配合gstreamer 媒体后端运行,该类才能正常工作。

QMediaCaptureSession session;
QGStreamerVideoSource videoSource(QStringLiteral("videotestsrc name=testsrc"));

session.setNativeVideoSource(&videoSource);
videoSource.start();

另请参阅 QMediaCaptureSession 和QCamera 。

属性文档

active : bool

描述视频源当前是否处于活动状态。

如果视频源已连接到QMediaCaptureSession ,则该属性表示底层的GstElement 是否已在媒体捕获会话中附加到GstPipeline 。

访问函数:

bool isActive() const
void setActive(bool active)

通知信号:

void activeChanged(bool active)

[read-only] gstBinDescription : const QString

描述与视频源关联的 GStreamer bin 描述。

如果视频源无法正常工作,或者是由现有的GstElement 构建而成的,则该属性的字符串为空。

访问函数:

QString gstBinDescription() const

成员函数文档

[explicit] QGStreamerVideoSource::QGStreamerVideoSource(GstElement *gstElement, QObject *parent = nullptr)

根据现有的gstElement 和parent ,构建一个QGStreamerVideoSource。

该元素必须提供一个捕获会话可用的视频源。GstElement 类型已在QGStreamerVideoSource 头文件中向前声明,因此必须使用GStreamer库中的对应类型。

如果指定的元素为 null,则构建的视频源将无法正常工作。

注意:该类 不会对提供的元素进行任何额外验证,因此,如果指定的元素不代表GstPipeline 的视频输入,则 QGStreamerVideoSource 及其关联的QMediaCaptureSession 可能会出现异常行为。

注意:QGStreamerVideoSource 与调用方共享所提供的GstElement 的所有权。

[explicit] QGStreamerVideoSource::QGStreamerVideoSource(const QString &gstBinDescription, QObject *parent = nullptr)

根据 GStreamer 存储库描述gstBinDescription 和parent 构建一个 QGStreamerVideoSource 对象。

GStreamer 后端会解析该描述,并创建一个可作为捕获会话视频源的 bin。使用方法gstElement() 访问创建的 bin。

有关描述字符串的语法,请参阅GStreamer 文档。

如果无法解析指定的描述,导致无法创建GstBin ,则构建的 QGStreamerVideoSource 将无法正常工作,gstElement() 将返回nullptr ,而gstBinDescription() 将返回一个空字符串。

注意:QGStreamerVideoSource 不会对提供的 bin 描述进行任何额外验证,因此如果创建的GstBin 不能作为GstPipeline 的视频输入,则 QGStreamerVideoSource 及其关联的QMediaCaptureSession 可能会出现异常行为。

为了更好地控制底层的 GStreamer 元素,您可以改用现有的GstElement 来构造 QGStreamerVideoSource。

另请参阅 gstElement() 和gstBinDescription()。

GstElement *QGStreamerVideoSource::gstElement() const

返回视频源所使用的底层GstElement 对象;如果视频源无法正常工作,则返回nullptr 。

如果视频源是根据 GStreamer bin 描述构建的,则返回的 `GstElement ` 可以转换为 `GstBin ` 的子类。

注意:该 方法不会转移GstElement 的所有权。

[slot] void QGStreamerVideoSource::start()

启动视频源。

这相当于将active 属性设置为true 。

[slot] void QGStreamerVideoSource::stop()

停止视频源。

这相当于将active 属性设置为false 。

© 2026 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.