Qt Multimedi 是提供了一组丰富 QML 类型和 C++ 类,以处理多媒体内容的附件模块。它包含易于使用的 API,用于回放音频和视频文件并在屏幕上渲染这些,及用于从系统摄像头和麦克风录制音频和视频的综合 API。
该模块功能分为下列子模块:
Qt Multimedia | 提供用于特定多媒体用例的 API。 |
Qt Multimedia Widgets | 提供基于 Widget 的多媒体 API。 |
Qt Spatial Audio | 提供用于在 3D 空间实现声场的 API。 |
若要从 Qt 5 移植到 Qt 6,见 Qt Multimedia 的变化 .
若是 Qt Multimedia 新手,QML 类型可以
imported
进应用程序使用以下语句在
.qml
文件。
import QtMultimedia
要链接到 C++ 库,添加以下到工程
CMakeLists.txt
文件。代入
my_project
采用工程名称。
find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(my_project PRIVATE Qt6::Multimedia)
见 从源代码构建 Qt Multimedia 了解从源代码构建 Qt Multimedia 的有关指导。
下表提纲了一些重要 QML 类型。
类型 | 描述 |
---|---|
MediaPlayer | 将音频/视频回放功能添加到场景。 |
CaptureSession | 创建用于捕获音频/视频的会话。 |
Camera | 访问连接到系统的摄像头。 |
AudioInput | 访问连接到系统的音频输入 (麦克风)。 |
AudioOutput | 访问连接到系统的音频输出 (扬声器、耳机)。 |
VideoOutput | 显示视频内容。 |
MediaRecorder | 录制音频/视频从 CaptureSession . |
ImageCapture | 从摄像头捕获静止图像。 |
视频 | 将视频回放功能添加到场景。使用 MediaPlayer and VideoOutput 类型以提供视频回放功能。 |
ScreenCapture | 捕获屏幕。 |
WindowCapture | 捕获顶层窗口。 |
下表提纲了一些重要 C++ 类
类 | 描述 |
---|---|
QMediaPlayer | 从源回放媒体。 |
QVideoWidget | 显示来自媒体播放器 (或捕获会话) 的视频。 |
QMediaCaptureSession | 捕获音频/视频。 |
QCamera | 访问连接到系统的摄像头 |
QAudioInput | 访问连接到系统的音频输入 (麦克风)。 |
QAudioOutput | 访问连接到系统的音频输出 (扬声器、耳机)。 |
QImageCapture | 以摄像头捕获静止图像。 |
QMediaRecorder | 从捕获会话录制媒体内容。 |
QVideoSink | 访问和渲染单个视频帧。 |
QAudioSink | 将原生音频数据发送给音频输出设备。 |
QScreenCapture | 捕获屏幕。 |
QWindowCapture | 捕获顶层窗口。 |
对于回放 QMediaPlayer , QAudioOutput 和 QVideoOutput 包含所有要求功能。其它类用于捕获音频和视频内容,其中 QMediaCaptureSession 是管理整个捕获/录制过程的中心类。
Qt Multimedia 模块在商业许可下是可用的来自 Qt 公司 。此外,它在自由软件许可下也是可用的。从 Qt 5.6 起,这些自由软件许可是 GNU LGPL (次一般公共许可) 第 3 版 ,或 GNU GPL (一般公共许可) 第 2 版 。见 Qt 许可 进一步了解细节。
Furthermore, Qt Multimedia in Qt 6.7.2 may contain third-party modules under following permissive licenses:
GNU Lesser General Public License v2.1 or later and BSD 3-Clause "New" or "Revised" License and BSD 2-Clause "Simplified" License and BSD Source Code Attribution and ISC License and MIT License and Mozilla Public License 2.0 | |
Boost 软件许可 1.0 | |
独立 JPEG 组许可 | |
zlib 许可类 |
Note that video compression standards, such as the H.264 media compression standard, may be covered by patents and can incur royalty fees. This can apply to any implementation, also if the implementation is provided as an operating system service, through a third party library, or through any of Qt Multimedia's backends. Such fees are not covered by the Qt licenses.
We aim to align the behavior on all the platforms but there are some issues to consider.
在大多数平台,有 2 种不同后端可以用于 Qt Multimedia。
In this release the FFmpeg 框架 is set as the default backend on Windows, macOS, Android, and Linux except Yocto distribution.
The version shipped with Qt binary packages is FFmpeg 6.1.1 and is tested by the maintainers.
注意: On the Windows and macOS platforms, Qt's FFmpeg media backend uses dynamic linking to the FFmpeg libraries. Windows and macOS applications must therefore bundle FFmpeg binaries in their installer, and make them visible to the application at runtime. On Windows, we recommend to store the FFmpeg dlls in the same directory as the application's executable file, because this guarantees that the correct build of FFmpeg is being used if multiple versions are available on the system. All necessary FFmpeg libraries are shipped with the Qt Online Installer and are automatically deployed if the windeployqt or macdeployqt tools are used to create the deployment. Applications can also deploy their own build of FFmpeg, as long as the FFmpeg major version matches the version used by Qt.
注意: 见 许可和归属 regarding what components are removed in the package shipped by Qt.
These are:
注意: These are still available but with limited support. The gstreamer backend is only available on Linux.
Maintainers will strive to fix critical issues with the native backends but don't guarantee fixing minor issues and won't implement new features for the native backends. Furthermore, even some major issues with the gstreamer backend (on Linux) won't be fixed since gstreamer is difficult to debug and is further complicated as it is dependent on Linux distributions.
We aim to align the behavior on all the platforms, especially, with the FFmpeg backend. Despite this fact we still have platform-dependent issues with formats, codecs, advanced camera features, and screen capturing due to the Qt Multimedia API relying on target platform APIs. For example, with FFmpeg, there are specific problems with hardware acceleration on Linux targets with ARM architectures.
Backend-dependent limitations will be documented and their status maintained in the respective classes.
In the case of issues with the default FFmpeg backend, we suggest testing with a native backend. You can switch to native backends by setting the
QT_MEDIA_BACKEND
环境变量到
windows
,
gstreamer
(在 Linux),
darwin
(在 macOS 和 iOS),或
android
:
export QT_MEDIA_BACKEND=darwin
In order to force assign FFmpeg as the used backend, set the variable to
ffmpeg
:
export QT_MEDIA_BACKEND=ffmpeg
在 Qt Multimedia 编译阶段,可以配置默认媒体后端凭借 cmake 变量
QT_DEFAULT_MEDIA_BACKEND
.
The following pages list issues for specific target platforms that are not related to the multimedia backed.
从 Qt 6.6 开始,Qt Multimedia 模块使用新 QPermission API 处理 camera and microphone permissions. This means that Qt itself no longer queries for these permissions, so this needs to be done directly from the client application.
请参考 应用程序权限 page for an example of how to integrate the new QPermission API into the application.