QMediaFormat Class

Describes an encoding format for a multimedia file or stream. More...

Header: #include <QMediaFormat>
CMake: find_package(Qt6 REQUIRED COMPONENTS Multimedia)
target_link_libraries(mytarget PRIVATE Qt6::Multimedia)
qmake: QT += multimedia

Public Types

enum class AudioCodec { WMA, AC3, AAC, ALAC, DolbyTrueHD, …, Unspecified }
enum ConversionMode { Encode, Decode }
enum FileFormat { WMA, AAC, Matroska, WMV, MP3, …, UnspecifiedFormat }
enum ResolveFlags { NoFlags, RequiresVideo }
enum class VideoCodec { VP8, MPEG2, MPEG1, WMV, H265, …, Unspecified }

Properties

Public Functions

QMediaFormat(QMediaFormat::FileFormat format = UnspecifiedFormat)
QMediaFormat(const QMediaFormat &other)
QMediaFormat(QMediaFormat &&other)
~QMediaFormat()
QMediaFormat::AudioCodec audioCodec() const
QMediaFormat::FileFormat fileFormat() const
bool isSupported(QMediaFormat::ConversionMode mode) const
QMimeType mimeType() const
void resolveForEncoding(QMediaFormat::ResolveFlags flags)
void setAudioCodec(QMediaFormat::AudioCodec codec)
void setFileFormat(QMediaFormat::FileFormat f)
void setVideoCodec(QMediaFormat::VideoCodec codec)
QList<QMediaFormat::AudioCodec> supportedAudioCodecs(QMediaFormat::ConversionMode m)
QList<QMediaFormat::FileFormat> supportedFileFormats(QMediaFormat::ConversionMode m)
QList<QMediaFormat::VideoCodec> supportedVideoCodecs(QMediaFormat::ConversionMode m)
void swap(QMediaFormat &other)
QMediaFormat::VideoCodec videoCodec() const
bool operator!=(const QMediaFormat &other) const
QMediaFormat &operator=(QMediaFormat &&other)
QMediaFormat &operator=(const QMediaFormat &other)
bool operator==(const QMediaFormat &other) const

Static Public Members

QString audioCodecDescription(QMediaFormat::AudioCodec codec)
QString audioCodecName(QMediaFormat::AudioCodec codec)
QString fileFormatDescription(QMediaFormat::FileFormat fileFormat)
QString fileFormatName(QMediaFormat::FileFormat fileFormat)
QString videoCodecDescription(QMediaFormat::VideoCodec codec)
QString videoCodecName(QMediaFormat::VideoCodec codec)

Detailed Description

QMediaFormat describes an encoding format for a multimedia file or stream.

You can check whether a certain media format can be used for encoding or decoding using QMediaFormat.

Member Type Documentation

enum class QMediaFormat::AudioCodec

Describes the audio codec used in multimedia file or stream.

ConstantValueDescription
QMediaFormat::AudioCodec::WMA9Windows Media Audio
QMediaFormat::AudioCodec::AC32Dolby Digital
QMediaFormat::AudioCodec::AAC1Advanced Audio Coding
QMediaFormat::AudioCodec::ALAC10Apple Lossless Audio Codec
QMediaFormat::AudioCodec::DolbyTrueHD5Dolby TrueHD
QMediaFormat::AudioCodec::EAC33Dolby Digital Plus (EAC3)
QMediaFormat::AudioCodec::MP30MPEG-1 Audio Layer III or MPEG-2 Audio Layer III
QMediaFormat::AudioCodec::Wave8Waveform Audio File Format
QMediaFormat::AudioCodec::Vorbis7Ogg Vorbis
QMediaFormat::AudioCodec::FLAC4Free Lossless Audio Codec
QMediaFormat::AudioCodec::Opus6Opus Audio Format
QMediaFormat::AudioCodec::Unspecified-1Unspecified codec

enum QMediaFormat::ConversionMode

In many cases, systems have asymmetric capabilities and can often decode more formats or codecs than can be encoded. This enum describes the requested conversion mode to be used when checking whether a certain file format or codec is supported.

ConstantValueDescription
QMediaFormat::Encode0Used to check whether a certain file format or codec can be encoded.
QMediaFormat::Decode1Used to check whether a certain file format or codec can be decoded.

See also supportedFileFormats, supportedAudioCodecs, and supportedVideoCodecs.

enum QMediaFormat::FileFormat

Describes the container format used in a multimedia file or stream.

ConstantValueDescription
QMediaFormat::WMA9Windows Media Audio
QMediaFormat::AAC8Advanced Audio Coding
QMediaFormat::Matroska2Matroska (MKV)
QMediaFormat::WMV0Windows Media Video
QMediaFormat::MP310MPEG-1 Audio Layer III or MPEG-2 Audio Layer III
QMediaFormat::Wave12Waveform Audio File Format
QMediaFormat::Ogg4Ogg
QMediaFormat::MPEG43MPEG-4
QMediaFormat::AVI1Audio Video Interleave
QMediaFormat::QuickTime5QuickTime
QMediaFormat::WebM6WebM
QMediaFormat::Mpeg4Audio7MPEG-4 Part 3 or MPEG-4 Audio (formally ISO/IEC 14496-3)
QMediaFormat::FLAC11Free Lossless Audio Codec
QMediaFormat::UnspecifiedFormat-1The format is unspecified.

enum QMediaFormat::ResolveFlags

Describes the requirements for resolving a suitable format for QMediaRecorder.

ConstantValueDescription
QMediaFormat::NoFlags0No requirements
QMediaFormat::RequiresVideo1A video codec is required

See also resolveForEncoding().

enum class QMediaFormat::VideoCodec

Describes the video coded used in multimedia file or stream.

ConstantValueDescription
QMediaFormat::VideoCodec::VP85VP8
QMediaFormat::VideoCodec::MPEG21MPEG-2
QMediaFormat::VideoCodec::MPEG10MPEG-1
QMediaFormat::VideoCodec::WMV9Windows Media Video
QMediaFormat::VideoCodec::H2654High Efficiency Video Coding (HEVC)
QMediaFormat::VideoCodec::H2643Advanced Video Coding
QMediaFormat::VideoCodec::MPEG42MPEG-4
QMediaFormat::VideoCodec::AV17AOMedia Video 1
QMediaFormat::VideoCodec::MotionJPEG10MotionJPEG
QMediaFormat::VideoCodec::VP96VP9
QMediaFormat::VideoCodec::Theora8Theora
QMediaFormat::VideoCodec::Unspecified-1Video codec not specified

Property Documentation

audioCodec : AudioCodec

This property holds the audio codec of the media.

Access functions:

QMediaFormat::AudioCodec audioCodec() const
void setAudioCodec(QMediaFormat::AudioCodec codec)

See also QMediaFormat::AudioCodec.

fileFormat : FileFormat

This property holds the file (container) format of the media.

Access functions:

QMediaFormat::FileFormat fileFormat() const
void setFileFormat(QMediaFormat::FileFormat f)

See also QMediaFormat::FileFormat.

videoCodec : VideoCodec

This property holds the video codec of the media.

Access functions:

QMediaFormat::VideoCodec videoCodec() const
void setVideoCodec(QMediaFormat::VideoCodec codec)

See also QMediaFormat::VideoCodec.

Member Function Documentation

QMediaFormat::QMediaFormat(QMediaFormat::FileFormat format = UnspecifiedFormat)

Constructs a QMediaFormat object for format.

[noexcept] QMediaFormat::QMediaFormat(const QMediaFormat &other)

Constructs a QMediaFormat object by copying from other.

[noexcept] QMediaFormat::QMediaFormat(QMediaFormat &&other)

Constructs a QMediaFormat objects by moving from other.

[noexcept] QMediaFormat::~QMediaFormat()

Destroys the QMediaFormat object.

QMediaFormat::AudioCodec QMediaFormat::audioCodec() const

Returns the audio codec used in this format.

Note: Getter function for property audioCodec.

See also setAudioCodec() and QMediaFormat::AudioCodec.

[static invokable] QString QMediaFormat::audioCodecDescription(QMediaFormat::AudioCodec codec)

Returns a description for codec.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

[static invokable] QString QMediaFormat::audioCodecName(QMediaFormat::AudioCodec codec)

Returns a string based name for codec.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

[static invokable] QString QMediaFormat::fileFormatDescription(QMediaFormat::FileFormat fileFormat)

Returns a description for fileFormat.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

[static invokable] QString QMediaFormat::fileFormatName(QMediaFormat::FileFormat fileFormat)

Returns a string based name for fileFormat.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

[invokable] bool QMediaFormat::isSupported(QMediaFormat::ConversionMode mode) const

Returns true if Qt Multimedia can encode or decode this format, depending on mode.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

QMimeType QMediaFormat::mimeType() const

Returns the MIME type for the file format used in this media format.

void QMediaFormat::resolveForEncoding(QMediaFormat::ResolveFlags flags)

Resolves the format, based on flags, to a format that is supported by QMediaRecorder.

This method tries to find the best possible match for unspecified settings. Settings that are not supported by the recorder will be modified to the closest match that is supported.

When resolving, priority is given in the following order:

  1. File format
  2. Video codec
  3. Audio codec

void QMediaFormat::setAudioCodec(QMediaFormat::AudioCodec codec)

Sets the audio codec to codec.

Note: Setter function for property audioCodec.

See also audioCodec() and QMediaFormat::AudioCodec.

void QMediaFormat::setVideoCodec(QMediaFormat::VideoCodec codec)

Sets the video codec to codec.

Note: Setter function for property videoCodec.

See also videoCodec() and QMediaFormat::VideoCodec.

[invokable] QList<QMediaFormat::AudioCodec> QMediaFormat::supportedAudioCodecs(QMediaFormat::ConversionMode m)

Returns a list of audio codecs for the chosen file format and video codec (m).

To get all supported audio codecs, run this query on a default constructed QMediaFormat.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

See also QMediaFormat::ConversionMode.

[invokable] QList<QMediaFormat::FileFormat> QMediaFormat::supportedFileFormats(QMediaFormat::ConversionMode m)

Returns a list of file formats for the audio and video codec indicated by m.

To get all supported file formats, run this query on a default constructed QMediaFormat.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

See also QMediaFormat::ConversionMode.

[invokable] QList<QMediaFormat::VideoCodec> QMediaFormat::supportedVideoCodecs(QMediaFormat::ConversionMode m)

Returns a list of video codecs for the chosen file format and audio codec (m).

To get all supported video codecs, run this query on a default constructed MediaFormat.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

See also QMediaFormat::ConversionMode.

[noexcept] void QMediaFormat::swap(QMediaFormat &other)

Swaps the media format with other.

QMediaFormat::VideoCodec QMediaFormat::videoCodec() const

Returns the video codec used in this format.

Note: Getter function for property videoCodec.

See also setVideoCodec() and QMediaFormat::VideoCodec.

[static invokable] QString QMediaFormat::videoCodecDescription(QMediaFormat::VideoCodec codec)

Returns a description for codec.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

[static invokable] QString QMediaFormat::videoCodecName(QMediaFormat::VideoCodec codec)

Returns a string based name for codec.

Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.

bool QMediaFormat::operator!=(const QMediaFormat &other) const

Returns true if other is not equal to the current media format, otherwise returns false.

[noexcept] QMediaFormat &QMediaFormat::operator=(QMediaFormat &&other)

Moves other into this QMediaFormat objects.

[noexcept] QMediaFormat &QMediaFormat::operator=(const QMediaFormat &other)

Copies other into this QMediaFormat object.

bool QMediaFormat::operator==(const QMediaFormat &other) const

Returns true if other is equal to the current media format, otherwise returns false.