Qt Multimedia

"image of multimedia icons, courtesy of misirlou from the Noun Project"

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 the system's cameras and microphones.

该模块功能分为下列子模块:

Qt Multimedia Provides an API for multimedia-specific use cases.
Qt Multimedia Widgets Provides a widget-based multimedia API.
Qt Spatial Audio Provides an API for implementing sound fields in 3D space.

快速入门

If you are porting from Qt 5 to Qt 6 see Changes to Qt Multimedia .

If you are new to Qt Multimedia, the QML types can be imported into an application using the following statement in your .qml 文件。

import QtMultimedia
					

To link against the C++ libraries, add the following to your project's CMakeLists.txt file. Substitute my_project with the name of your project.

find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(my_project PRIVATE Qt6::Multimedia)
					

Overviews and Important Topics

QML 类型

The following table outlines some important QML types.

类型 描述
MediaPlayer Add audio/video playback functionality to a scene.
CaptureSession Create a session for capturing audio/video.
Camera Access a camera connected to the system.
AudioInput Access an audio input (microphone) connected to the system.
AudioOutput Access an audio output (speaker, headphone) connected to the system.
VideoOutput Display video content.
MediaRecorder Record audio/video from the CaptureSession .
ImageCapture Capture still images from the Camera.
Video Add Video playback functionality to a scene. Uses MediaPlayer and VideoOutput 类型以提供视频回放功能。

C++ 类

The following table outlines some important C++ Classes

描述
QMediaPlayer 从源回放媒体。
QVideoWidget Display video from a media player or a capture session.
QMediaCaptureSession Capture audio and video.
QCamera Access a camera connected to the system
QAudioInput Access an audio input (microphone) connected to the system.
QAudioOutput Access an audio output (speaker, headphone) connected to the system.
QImageCapture 以摄像头捕获静止图像。
QMediaRecorder Record media content from a capture session.
QVideoSink Access and render individual video frames.
QAudioSink Sends raw audio data to an audio output device.

For playback QMediaPlayer , QAudioOutput and QVideoOutput contain all the required functionality. The other classes are used for capturing audio and video content, where the QMediaCaptureSession is the central class managing the whole capture/recording process.

许可和归属

The Qt Multimedia module is available under commercial licenses from Qt 公司 . In addition, it is available under free software licenses. Since Qt 5.6, these free software licenses are GNU LGPL (次一般公共许可) 第 3 版 ,或 GNU GPL (一般公共许可) 第 2 版 。见 Qt 许可 进一步了解细节。

The FFmpeg backend uses the FFmpeg framework . FFmpeg is licensed under LGPLv2.1, GPLv2, or later versions of the licenses. Some optional components of FFmpeg are only available under GPL. The FFmpeg backend shipped with the Qt binary packages is configured to not contain any of the components that are available under GPLv2 only. See the FFmpeg licensing page 进一步了解细节。

Target platform and backend notes

On most platforms, there are two different backends that can be used for Qt Multimedia.

In Qt 6.5, we're setting FFmpeg framework as the default backend on Windows, macOS, Android, and Linux except Yocto distribution. Native backends, namely gstreamer on Linux, AVFoundation on macOS, WMF on Windows, and the MediaCodec framework on Android, were the default in 6.4. These are still available but with limited support. This means that we will strive to fix critical issues with the native backends, but don't guarantee fixing minor issues and won't implement new features with native backends. Furthermore, even some major issues with the gstreamer backend (on Linux) won't be fixed since gstreamer is the hardest for debugging and is dependent on linux distributives issues.

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. This happens since we use some platform API anyway, even with ffmpeg, and there are specific problems with ffmpeg hardware acceleration, mostly on Linux run on ARM architectures. Known backend-dependent limitations will be documented in the respective classes and methods.

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 Linux), darwin (on macOS), or 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
					

On the Qt Multimedia compilation stage the default media backend can be configured via cmake variable QT_DEFAULT_MEDIA_BACKEND .

Reference and Examples