Qt Multimedia is an add-on module that provides a rich set of QML types and C++ classes to handle multimedia content. It contains an easy to use API for playing back audio and video files and rendering those on screen, as well as a comprehensive API for recording audio and video from various sources, including system cameras and microphones, screen or window captures, and audio or video memory buffers.
該模塊功能分為下列子模塊:
| 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 | 捕獲頂層窗口。 |
| QVideoFrameInput | 用於顯示 (或錄製) 來自內存緩衝的視頻幀。 |
| QAudioBufferInput | 支持播放 (或錄製) 來自內存緩衝的音頻。 |
對於音頻和視頻的迴放, QMediaPlayer , QAudioOutput ,和 QVideoWidget contain all necessary functionality. Other classes are dedicated to capturing audio and video content, with QMediaCaptureSession serving as the central class that manages the entire capture and recording process.
Qt Multimedia 模塊在商業許可下是可用的來自 Qt 公司 。此外,它在自由軟件許可下也是可用的。從 Qt 5.6 起,這些自由軟件許可是 GNU LGPL (次一般公共許可) 第 3 版 ,或 GNU GPL (一般公共許可) 第 2 版 。見 Qt 許可 進一步瞭解細節。
Furthermore, Qt Multimedia in Qt 6.10.1 may contain third-party modules under the following permissive licenses:
| MIT No Attribution | |
| 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 | |
| MIT 許可 | |
| BSD 3 條款新 (或修訂) 許可 | |
| 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 any of Qt Multimedia's backends. The Qt licenses do not cover such fees.
Qt Multimedia offers user-friendly, cross-platform APIs for media playback, recording, and device management. The implementation of core APIs, including
QMediaDevices
,
QAudioDevice
,
QSoundEffect
,
QAudioSink
,和
QAudioSource
are integrated into the main Qt Multimedia library, eliminating the need for additional libraries. Other Qt Multimedia APIs are implemented using plugin libraries known as media backends. The main media backend, built on
FFmpeg
, ensures seamless cross-platform functionality, and is the default on all platforms except WebAssembly and embedded Linux/Boot2Qt. With Boot2Qt, the default backend is built on top of
GStreamer
, but the FFmpeg media backend can be enabled using the
QT_MEDIA_BACKEND
環境變量。
The FFmpeg media backend relies on the FFmpeg 7.1 libraries, which are included with the Qt Online Installer and tested by the maintainers. The binary packages from the online installer use dynamic linking to FFmpeg. Therefore, applications must either bundle FFmpeg binaries in their installer or depend on FFmpeg being installed on the operating system. The FFmpeg libraries are automatically deployed using Qt's deployment tools as described in the 部署 Qt 應用程序 documentation, except for Linux/X11 . Applications can also deploy their own build of FFmpeg, either as shared or static libraries, provided the FFmpeg major version matches the version used by Qt.
While Qt Multimedia leverages the FFmpeg media backend on most operating systems, platform specific functional or visual differences may arise between applications on different platforms. FFmpeg does not provide identical codec and format support across all platforms, and the performance of Qt Multimedia features may depend on hardware support that is only available on certain platforms. For instance, FFmpeg encounters specific issues with hardware acceleration on Linux targets with ARM architectures. Therefore, it is recommended to test Qt Multimedia applications on all target platforms.
注意: The FFmpeg project provides features under various licenses. The pre-built FFmpeg libraries that are provided through the Online Installer are only including features that agree with the permissive licenses listed under 許可和歸屬 .
To ease development and debugging, some FFmpeg functionality is configurable via environment varibles which are part of the private Qt Multimedia API.
For compatibility with existing applications, we maintain native media backends for each operating system:
注意: The FFmpeg media backend is the default backend except on WebAssembly, native backends are still available but with limited support. The GStreamer backend is only available on Linux, and is only recommended for embedded applications.
注意: MediaCodec on Android is deprecated as of Qt 6.8 and will be removed in the next major release.
注意: The Windows media backend built on top of Windows Media Foundation is deprecated as of Qt 6.10 and will be removed in the next major release.
Qt Maintainers will strive to fix critical issues with the native backends but don't guarantee fixing minor issues, including inconsistent behavior across platforms. New features will only be implemented on the FFmpeg media backend, with the exception of WebAssembly.
The GStreamer backend has some private APIs to allow more fine-grained control. However, there are known bugs in the GStreamer backend. More details can be found in platform notes for the GStreamer backend .
Backend limitations will be documented, and their status will be 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
(on Embedded Linux),
darwin
(在 macOS 和 iOS),或
android
:
export QT_MEDIA_BACKEND=darwin
To force assign FFmpeg as the used backend, set the variable to
ffmpeg
:
export QT_MEDIA_BACKEND=ffmpeg
On the Qt Multimedia compilation stage, the default media backend can be configured via cmake variable
QT_DEFAULT_MEDIA_BACKEND
.
以下頁列齣瞭針對特定目標平颱的問題。
從 Qt 6.6 開始,Qt Multimedia 模塊使用新的 QPermission API 處理 camera and microphone 權限。這意味著 Qt 自身不再查詢這些權限,所以,做到這需要直接從客戶端應用程序。
請參考 應用程序權限 頁瞭解範例如何集成新 QPermission API 進應用程序。