Qt Multimedia 的变化

Qt 6 是努力使框架更高效,且更易于使用的结果。

为兼容每个发行的所有公共 API,我们试着维护二进制和源代码。但是,为使 Qt 成为更优框架,一些改变是不可避免的。

模块已显著重构且更改了分类,从必需到附件。Qt 6 中的 Qt Multimedia 模块替换来自 Qt 5.x 的 Qt Multimedia 模块。使用来自 Qt 5 的 Qt Multimedia 的现有代码,通过有限努力可以移植。

Qt 6 的新特征

Qt Multimedia 有许多新特征:

  • QMediaCaptureSession 类是媒体捕获的中心对象。
  • QMediaRecorder 类现在是局限于录制音频和视频的类。它处理捕获会话中产生的数据编码。
  • 使用 QMediaFormat and QMediaRecorder , setting up the desired encoding when recording has changed significantly.
  • You can now also monitor the audio recorded by a capture session.
  • Support for selection of audio, video and subtitle tracks when playing back media files has been added.
  • QAudioDecoder 现在支持所有平台。

移除特征

移除特征 注意事项或建议替代
Playlist in QMediaPlayer QMediaPlayer does not do any playlist handling anymore in Qt 6.
QMediaPlayList This class has been removed from the API. It does however still exist as part of the 媒体播放器范例 .
QAudioProbe and QVideoProbe The audio and video probing API has been removed.
QAudioRecorder 使用 QMediaCaptureSession or CaptureSession QML 类型。
Audio QML type 使用 MediaPlayer QML 类型。
QMediaObject and QMediaBindableInterface These classes have been removed in favor of a more direct API for setting up connections between objects using, for example, setVideoOutput and QMediaCaptureSession .
QCameraViewFinderSettings This class has been removed. Use QCameraFormat to define the resolution and frame rate the camera should be using.
QMediaContent 类已被移除。使用 QUrl for individual media files instead.
QSound 使用 QSoundEffect 代替。
QVideoFilterRunnable 使用 着色器效果 in QML instead or access the QVideoFrame 's content in C++.
Public back-end API The back-end API of Qt Multimedia is private in Qt 6. This improves response time for supporting new multimedia use cases. Any classes that contain the words "Control" or "Abstract" in the class name in Qt 5 are now private in Qt 6.
Back-end plugins Qt Multimedia in Qt 6 does not use a plugin infrastructure for its back ends anymore. This means that users no longer need to ship those back ends with their application. Instead, the back end being used is determined at compile time based on the underlying operating system. Qt uses gstreamer on Linux, WMF on Windows, AVFoundation on macOS and iOS and the Android multimedia APIs on Android.

变化特征

A number of classes previously offered in Qt Multimedia have changed in ways that may affect previously written code. The following table highlights these changes.

变化特征 注意事项
摄像头分辨率和帧速率的处理 Handling of these has been simplified and a new QCameraFormat class helps with selecting the correct resolution and frame rate for the camera.
Video output handling on the C++ side has changed significantly. QAbstractVideoSurface has been replaced by the QVideoSink class, and generic rendering support has been enhanced to cover all pixel format s supported by Qt Multimedia.
元数据类型 QMediaMetaData has changed significantly: mainly moving from string based to enum based keys, and reducing the set of supported keys to the ones that can be supported on most platforms.
QMediaFormat Handling of formats for encoded media and the settings for the media recorder have changed significantly. Qt 5 provides a string-based API, a separated file format, and audio and video codecs into three classes. However, Qt 6 unifies the formats in the QMediaFormat class. Additional settings are directly specified in QMediaRecorder . Setting up file formats and codecs is now implemented with enums and no longer uses strings. This puts some limitations on the set of codecs that can be used, but helps provide a consistent cross-platform API.
QCameraImageCapture 重命名 QImageCapture None
音频输入和输出 QMediaPlayer and QMediaCaptureSession (and the corresponding QML types MediaPlayer and CaptureSession ) are not connected to any audio devices by default. Explicitly connect them to a QAudioInput / AudioInput or QAudioOutput / AudioOutput to capture or play back audio.
捕获视频 A capture session is by default not connected to a Camera. Connect it to a QCamera object (Camera item) to be able to capture video or still images.