Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qmediaformat.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qmediaformat.h"
5#include "private/qplatformmediaintegration_p.h"
6#include "private/qplatformmediaformatinfo_p.h"
7#include "private/qmultimedia_enum_to_string_converter_p.h"
8#if QT_CONFIG(mimetype)
9#include <QtCore/qmimedatabase.h>
10#endif
11
13
14// clang-format off
15
17
18QT_MM_MAKE_STRING_RESOLVER(QMediaFormat::FileFormat, QtMultimediaPrivate::EnumName,
19 (QMediaFormat::UnspecifiedFormat, "Unspecified")
20 (QMediaFormat::WMV, "WMV")
21 (QMediaFormat::AVI, "AVI")
22 (QMediaFormat::Matroska, "Matroska")
23 (QMediaFormat::MPEG4, "MPEG-4")
24 (QMediaFormat::Ogg, "Ogg")
25 (QMediaFormat::QuickTime, "QuickTime")
26 (QMediaFormat::WebM, "WebM")
27 // Audio Formats
28 (QMediaFormat::Mpeg4Audio, "MPEG-4 Audio")
29 (QMediaFormat::AAC, "AAC")
30 (QMediaFormat::WMA, "WMA")
31 (QMediaFormat::MP3, "MP3")
32 (QMediaFormat::FLAC, "FLAC")
33 (QMediaFormat::Wave, "Wave")
34 );
35
37 (QMediaFormat::UnspecifiedFormat, "Unspecified File Format")
38 (QMediaFormat::WMV, "Windows Media Video")
39 (QMediaFormat::AVI, "Audio Video Interleave")
40 (QMediaFormat::Matroska, "Matroska Multimedia Container")
41 (QMediaFormat::MPEG4, "MPEG-4 Video Container")
42 (QMediaFormat::Ogg, "Ogg")
43 (QMediaFormat::QuickTime, "QuickTime Container")
44 (QMediaFormat::WebM, "WebM")
45 // Audio Formats
46 (QMediaFormat::Mpeg4Audio, "MPEG-4 Audio")
47 (QMediaFormat::AAC, "AAC")
48 (QMediaFormat::WMA, "Windows Media Audio")
49 (QMediaFormat::MP3, "MP3")
50 (QMediaFormat::FLAC, "Free Lossless Audio Codec (FLAC)")
51 (QMediaFormat::Wave, "Wave File")
52 );
53
54QT_MM_MAKE_STRING_RESOLVER(QMediaFormat::AudioCodec, QtMultimediaPrivate::EnumName,
55 (QMediaFormat::AudioCodec::Unspecified, "Unspecified")
56 (QMediaFormat::AudioCodec::MP3, "MP3")
57 (QMediaFormat::AudioCodec::AAC, "AAC")
58 (QMediaFormat::AudioCodec::AC3, "AC3")
59 (QMediaFormat::AudioCodec::EAC3, "EAC3")
60 (QMediaFormat::AudioCodec::FLAC, "FLAC")
61 (QMediaFormat::AudioCodec::DolbyTrueHD, "DolbyTrueHD")
62 (QMediaFormat::AudioCodec::Opus, "Opus")
63 (QMediaFormat::AudioCodec::Vorbis, "Vorbis")
64 (QMediaFormat::AudioCodec::Wave, "Wave")
65 (QMediaFormat::AudioCodec::WMA, "WMA")
66 (QMediaFormat::AudioCodec::ALAC, "ALAC")
67 );
68
70 (QMediaFormat::AudioCodec::Unspecified, "Unspecified Audio Codec")
71 (QMediaFormat::AudioCodec::MP3, "MP3")
72 (QMediaFormat::AudioCodec::AAC, "Advanced Audio Codec (AAC)")
73 (QMediaFormat::AudioCodec::AC3, "Dolby Digital (AC3)")
74 (QMediaFormat::AudioCodec::EAC3, "Dolby Digital Plus (E-AC3)")
75 (QMediaFormat::AudioCodec::FLAC, "Free Lossless Audio Codec (FLAC)")
76 (QMediaFormat::AudioCodec::DolbyTrueHD, "Dolby True HD")
77 (QMediaFormat::AudioCodec::Opus, "Opus")
78 (QMediaFormat::AudioCodec::Vorbis, "Vorbis")
79 (QMediaFormat::AudioCodec::Wave, "Wave")
80 (QMediaFormat::AudioCodec::WMA, "Windows Media Audio")
81 (QMediaFormat::AudioCodec::ALAC, "Apple Lossless Audio Codec (ALAC)")
82 );
83
84
85QT_MM_MAKE_STRING_RESOLVER(QMediaFormat::VideoCodec, QtMultimediaPrivate::EnumName,
86 (QMediaFormat::VideoCodec::Unspecified, "Unspecified")
87 (QMediaFormat::VideoCodec::MPEG1, "MPEG1")
88 (QMediaFormat::VideoCodec::MPEG2, "MPEG2")
89 (QMediaFormat::VideoCodec::MPEG4, "MPEG4")
90 (QMediaFormat::VideoCodec::H264, "H264")
91 (QMediaFormat::VideoCodec::H265, "H265")
92 (QMediaFormat::VideoCodec::VP8, "VP8")
93 (QMediaFormat::VideoCodec::VP9, "VP9")
94 (QMediaFormat::VideoCodec::AV1, "AV1")
95 (QMediaFormat::VideoCodec::Theora, "Theora")
96 (QMediaFormat::VideoCodec::WMV, "WMV")
97 (QMediaFormat::VideoCodec::MotionJPEG, "MotionJPEG")
98 );
99
101 (QMediaFormat::VideoCodec::Unspecified, "Unspecified Video Codec")
102 (QMediaFormat::VideoCodec::MPEG1, "MPEG-1 Video")
103 (QMediaFormat::VideoCodec::MPEG2, "MPEG-2 Video")
104 (QMediaFormat::VideoCodec::MPEG4, "MPEG-4 Video")
105 (QMediaFormat::VideoCodec::H264, "H.264")
106 (QMediaFormat::VideoCodec::H265, "H.265")
107 (QMediaFormat::VideoCodec::VP8, "VP8")
108 (QMediaFormat::VideoCodec::VP9, "VP9")
109 (QMediaFormat::VideoCodec::AV1, "AV1")
110 (QMediaFormat::VideoCodec::Theora, "Theora")
111 (QMediaFormat::VideoCodec::WMV, "Windows Media Video")
112 (QMediaFormat::VideoCodec::MotionJPEG, "MotionJPEG")
113 );
114// clang-format on
115
116/*!
117 \class QMediaFormat
118 \ingroup multimedia
119 \inmodule QtMultimedia
120 \brief Describes an encoding format for a multimedia file or stream.
121 \since 6.2
122
123 QMediaFormat describes an encoding format for a multimedia file or stream.
124
125 You can check whether a certain media format can be used for encoding
126 or decoding using QMediaFormat.
127*/
128
129/*!
130 \qmlvaluetype mediaFormat
131 \ingroup qmlvaluetypes
132 \since 6.2
133 //! \nativetype QMediaFormat
134 \brief MediaFormat describes the format of a media file.
135 \inqmlmodule QtMultimedia
136 \ingroup multimedia_qml
137
138 The MediaFormat type describes the format of a media file. It contains
139 three properties that describe the file type and the audio and video codecs
140 that are being used.
141
142 MediaFormat can be used to specify the type of file that should be created
143 by a MediaRecorder. The snippet below shows an example that sets up the
144 recorder to create an mpeg4 video with AAC encoded audio and H265 video:
145
146 \qml
147 CaptureSession {
148 ... // setup inputs
149 MediaRecorder {
150 mediaFormat {
151 fileFormat: MediaFormat.MPEG4
152 audioCodec: MediaFormat.AudioCodec.AAC
153 videoCodec: MediaFormat.VideoCodec.H265
154 }
155 }
156 }
157 \endqml
158
159 If the specified mediaFormat is not supported, the MediaRecorder will automatically try
160 to find the best possible replacement format and use that instead.
161
162 \sa MediaRecorder, CaptureSession
163*/
164
165namespace {
166
167const char *mimeTypeForFormat[QMediaFormat::LastFileFormat + 2] =
168{
169 "",
170 "video/x-ms-wmv",
171 "video/x-msvideo",
172 "video/x-matroska",
173 "video/mp4",
174 "video/ogg",
175 "video/quicktime",
176 "video/webm",
177 // Audio Formats
178 "audio/mp4",
179 "audio/aac",
180 "audio/x-ms-wma",
181 "audio/mpeg",
182 "audio/flac",
183 "audio/wav"
184};
185
186constexpr QMediaFormat::FileFormat videoFormatPriorityList[] =
187{
188 QMediaFormat::MPEG4,
189 QMediaFormat::QuickTime,
190 QMediaFormat::AVI,
191 QMediaFormat::WebM,
192 QMediaFormat::WMV,
193 QMediaFormat::Matroska,
194 QMediaFormat::Ogg,
195 QMediaFormat::UnspecifiedFormat
196};
197
198constexpr QMediaFormat::FileFormat audioFormatPriorityList[] =
199{
200 QMediaFormat::Mpeg4Audio,
201 QMediaFormat::MP3,
202 QMediaFormat::WMA,
203 QMediaFormat::FLAC,
204 QMediaFormat::Wave,
205 QMediaFormat::UnspecifiedFormat
206};
207
208constexpr QMediaFormat::AudioCodec audioPriorityList[] =
209{
210 QMediaFormat::AudioCodec::AAC,
211 QMediaFormat::AudioCodec::MP3,
212 QMediaFormat::AudioCodec::AC3,
213 QMediaFormat::AudioCodec::Opus,
214 QMediaFormat::AudioCodec::EAC3,
215 QMediaFormat::AudioCodec::DolbyTrueHD,
216 QMediaFormat::AudioCodec::WMA,
217 QMediaFormat::AudioCodec::FLAC,
218 QMediaFormat::AudioCodec::Vorbis,
219 QMediaFormat::AudioCodec::Wave,
220 QMediaFormat::AudioCodec::Unspecified
221};
222
223constexpr QMediaFormat::VideoCodec videoPriorityList[] =
224{
225 QMediaFormat::VideoCodec::H265,
226 QMediaFormat::VideoCodec::VP9,
227 QMediaFormat::VideoCodec::H264,
228 QMediaFormat::VideoCodec::AV1,
229 QMediaFormat::VideoCodec::VP8,
230 QMediaFormat::VideoCodec::WMV,
231 QMediaFormat::VideoCodec::Theora,
232 QMediaFormat::VideoCodec::MPEG4,
233 QMediaFormat::VideoCodec::MPEG2,
234 QMediaFormat::VideoCodec::MPEG1,
235 QMediaFormat::VideoCodec::MotionJPEG,
236};
237
238}
239
241{};
242
244
245/*! \enum QMediaFormat::FileFormat
246
247 Describes the container format used in a multimedia file or stream.
248
249 \value WMA
250 \l {Windows Media Audio}
251 \value AAC
252 \l{Advanced Audio Coding}
253 \value Matroska
254 \l{Matroska (MKV)}
255 \value WMV
256 \l{Windows Media Video}
257 \value MP3
258 \l{MPEG-1 Audio Layer III or MPEG-2 Audio Layer III}
259 \value Wave
260 \l{Waveform Audio File Format}
261 \value Ogg
262 \l{Ogg}
263 \value MPEG4
264 \l{MPEG-4}
265 \value AVI
266 \l{Audio Video Interleave}
267 \value QuickTime
268 \l{QuickTime}
269 \value WebM
270 \l{WebM}
271 \value Mpeg4Audio
272 \l{MPEG-4 Part 3 or MPEG-4 Audio (formally ISO/IEC 14496-3)}
273 \value FLAC
274 \l{Free Lossless Audio Codec}
275 \value UnspecifiedFormat
276 The format is unspecified.
277
278 \omitvalue LastFileFormat
279*/
280
281/*! \qmlproperty enumeration QtMultimedia::mediaFormat::fileFormat
282
283 Describes the container format used in a multimedia file or stream.
284 It can take one of the following values:
285
286 \table
287 \header \li Property value
288 \li Description
289 \row \li MediaFormat.WMA
290 \li \l{Windows Media Audio}
291 \row \li MediaFormat.AAC
292 \li \l{Advanced Audio Coding}
293 \row \li MediaFormat.Matroska
294 \li \l{Matroska (MKV)}
295 \row \li MediaFormat.WMV
296 \li \l{Windows Media Video}
297 \row \li MediaFormat.MP3
298 \li \l{MPEG-1 Audio Layer III or MPEG-2 Audio Layer III}
299 \row \li MediaFormat.Wave
300 \li \l{Waveform Audio File Format}
301 \row \li MediaFormat.Ogg
302 \li \l{Ogg}
303 \row \li MediaFormat.MPEG4
304 \li \l{MPEG-4}
305 \row \li MediaFormat.AVI
306 \li \l{Audio Video Interleave}
307 \row \li MediaFormat.QuickTime
308 \li \l{QuickTime}
309 \row \li MediaFormat.WebM
310 \li \l{WebM}
311 \row \li MediaFormat.Mpeg4Audio
312 \li \l{MPEG-4 Part 3 or MPEG-4 Audio (formally ISO/IEC 14496-3)}
313 \row \li MediaFormat.FLAC
314 \li \l{Free Lossless Audio Codec}
315 \row \li MediaFormat.UnspecifiedFormat
316 \li The format is unspecified.
317 \endtable
318*/
319
320/*! \enum QMediaFormat::AudioCodec
321
322 Describes the audio codec used in multimedia file or stream.
323
324 \value WMA
325 \l {Windows Media Audio}
326 \value AC3
327 \l {Dolby Digital}
328 \value AAC
329 \l{Advanced Audio Coding}
330 \value ALAC
331 \l{Apple Lossless Audio Codec}
332 \value DolbyTrueHD
333 \l{Dolby TrueHD}
334 \value EAC3
335 \l {Dolby Digital Plus (EAC3)}
336 \value MP3
337 \l{MPEG-1 Audio Layer III or MPEG-2 Audio Layer III}
338 \value Wave
339 \l{Waveform Audio File Format}
340 \value Vorbis
341 \l{Ogg Vorbis}
342 \value FLAC
343 \l{Free Lossless Audio Codec}
344 \value Opus
345 \l{Opus Audio Format}
346 \value Unspecified
347 Unspecified codec
348
349 \omitvalue LastAudioCodec
350*/
351
352/*! \qmlproperty enumeration QtMultimedia::mediaFormat::audioCodec
353
354 Describes the audio codec used in multimedia file or stream.
355 It can take one of the following values:
356
357 \table
358 \header \li Property value
359 \li Description
360 \row \li MediaFormat.WMA
361 \li \l {Windows Media Audio}
362 \row \li MediaFormat.AC3
363 \li \l {Dolby Digital}
364 \row \li MediaFormat.AAC
365 \li \l{Advanced Audio Coding}
366 \row \li MediaFormat.ALAC
367 \li \l{Apple Lossless Audio Codec}
368 \row \li MediaFormat.DolbyTrueHD
369 \li \l{Dolby TrueHD}
370 \row \li MediaFormat.EAC3
371 \li \l {Dolby Digital Plus (EAC3)}
372 \row \li MediaFormat.MP3
373 \li \l{MPEG-1 Audio Layer III or MPEG-2 Audio Layer III}
374 \row \li MediaFormat.Wave
375 \li \l{Waveform Audio File Format}
376 \row \li MediaFormat.Vorbis
377 \li \l{Ogg Vorbis}
378 \row \li MediaFormat.FLAC
379 \li \l{Free Lossless Audio Codec}
380 \row \li MediaFormat.Opus
381 \li \l{Opus Audio Format}
382 \row \li MediaFormat.Unspecified
383 \li Unspecified codec
384 \endtable
385*/
386
387/*! \enum QMediaFormat::VideoCodec
388
389 Describes the video coded used in multimedia file or stream.
390
391 \value VP8
392 \l{VP8}
393 \value MPEG2
394 \l{MPEG-2}
395 \value MPEG1
396 \l{MPEG-1}
397 \value WMV
398 \l{Windows Media Video}
399 \value H265
400 \l{High Efficiency Video Coding (HEVC)}
401 \value H264
402 \l{Advanced Video Coding}
403 \value MPEG4
404 \l{MPEG-4}
405 \value AV1
406 \l{AOMedia Video 1}
407 \value MotionJPEG
408 \l{MotionJPEG}
409 \value VP9
410 \l{VP9}
411 \value Theora
412 \l{Theora}
413 \value Unspecified
414 Video codec not specified
415
416 \omitvalue LastVideoCodec
417*/
418
419/*! \qmlproperty enumeration QtMultimedia::mediaFormat::videoCodec
420
421 Describes the video codec used in multimedia file or stream.
422 It can take one of the following values:
423
424 \table
425 \header \li Property value
426 \li Description
427 \row \li MediaFormat.VP8
428 \li \l{VP8}
429 \row \li MediaFormat.MPEG2
430 \li \l{MPEG-2}
431 \row \li MediaFormat.MPEG1
432 \li \l{MPEG-1}
433 \row \li MediaFormat.WMV
434 \li \l{Windows Media Video}
435 \row \li MediaFormat.H265
436 \li \l{High Efficiency Video Coding (HEVC)}
437 \row \li MediaFormat.H264
438 \li \l{Advanced Video Coding}
439 \row \li MediaFormat.MPEG4
440 \li \l{MPEG-4}
441 \row \li MediaFormat.AV1
442 \li \l{AOMedia Video 1}
443 \row \li MediaFormat.MotionJPEG
444 \li \l{MotionJPEG}
445 \row \li MediaFormat.VP9
446 \li \l{VP9}
447 \row \li MediaFormat.Theora
448 \li \l{Theora}
449 \row \li MediaFormat.Unspecified
450 \li Video codec not specified
451 \endtable
452*/
453
454// these are non inline to make a possible future addition of a d pointer binary compatible
455
456/*!
457 Constructs a QMediaFormat object for \a format.
458*/
459QMediaFormat::QMediaFormat(FileFormat format)
460 : fmt(format)
461{
462}
463
464/*!
465 Destroys the QMediaFormat object.
466*/
467QMediaFormat::~QMediaFormat() = default;
468
469/*!
470 Constructs a QMediaFormat object by copying from \a other.
471*/
472QMediaFormat::QMediaFormat(const QMediaFormat &other) noexcept = default;
473
474/*!
475 \fn void QMediaFormat::swap(QMediaFormat &other) noexcept
476
477 Swaps the media format with \a other.
478*/
479/*!
480 Copies \a other into this QMediaFormat object.
481*/
482QMediaFormat &QMediaFormat::operator=(const QMediaFormat &other) noexcept = default;
483
484/*! \fn QMediaFormat::QMediaFormat(QMediaFormat &&other)
485
486 Constructs a QMediaFormat objects by moving from \a other.
487*/
488
489/*! \fn QMediaFormat &QMediaFormat::operator=(QMediaFormat &&other)
490
491 Moves \a other into this QMediaFormat objects.
492*/
493
494// Properties
495/*! \property QMediaFormat::fileFormat
496
497 \brief The file (container) format of the media.
498
499 \sa QMediaFormat::FileFormat
500*/
501
502/*! \property QMediaFormat::audioCodec
503
504 \brief The audio codec of the media.
505
506 \sa QMediaFormat::AudioCodec
507*/
508
509/*! \property QMediaFormat::videoCodec
510
511 \brief The video codec of the media.
512
513 \sa QMediaFormat::VideoCodec
514*/
515
516/*! \fn void QMediaFormat::setVideoCodec(VideoCodec codec)
517
518 Sets the video codec to \a codec.
519
520 \sa videoCodec(), QMediaFormat::VideoCodec
521*/
522
523/*! \fn QMediaFormat::VideoCodec QMediaFormat::videoCodec() const
524
525 Returns the video codec used in this format.
526
527 \sa setVideoCodec(), QMediaFormat::VideoCodec
528*/
529
530/*! \fn void QMediaFormat::setAudioCodec(AudioCodec codec)
531
532 Sets the audio codec to \a codec.
533
534 \sa audioCodec(), QMediaFormat::AudioCodec
535*/
536
537/*! \fn QMediaFormat::AudioCodec QMediaFormat::audioCodec() const
538
539 Returns the audio codec used in this format.
540
541 \sa setAudioCodec(), QMediaFormat::AudioCodec
542*/
543
544/*!
545 Returns \c true if Qt Multimedia can encode or decode this format,
546 depending on \a mode.
547*/
548
549bool QMediaFormat::isSupported(ConversionMode mode) const
550{
551 return QPlatformMediaIntegration::instance()->formatInfo()->isSupported(*this, mode);
552}
553
554/*!
555 Returns the \l{MIME type} for the file format used in this media format.
556*/
557
558#if QT_CONFIG(mimetype)
559QMimeType QMediaFormat::mimeType() const
560{
561 return QMimeDatabase().mimeTypeForName(QString::fromLatin1(mimeTypeForFormat[fmt + 1]));
562}
563#endif
564
565/*!
566 \enum QMediaFormat::ConversionMode
567
568 In many cases, systems have asymmetric capabilities and can often decode more formats
569 or codecs than can be encoded. This enum describes the requested conversion mode to
570 be used when checking whether a certain file format or codec is supported.
571
572 \value Encode
573 Used to check whether a certain file format or codec can be encoded.
574 \value Decode
575 Used to check whether a certain file format or codec can be decoded.
576
577 \sa supportedFileFormats, supportedAudioCodecs, supportedVideoCodecs
578*/
579
580/*!
581 \qmlmethod list<FileFormat> QtMultimedia::mediaFormat::supportedFileFormats(conversionMode)
582 Returns a list of file formats for the audio and video
583 codec indicated by \a{conversionMode}.
584
585 To get all supported file formats, run this query on a default constructed MediaFormat. To
586 get a list of file formats supporting a specific combination of an audio and video codec,
587 you can set the audioCodec and videoCodec properties before running this query.
588
589 \sa QMediaFormat::ConversionMode
590*/
591
592/*!
593 Returns a list of file formats for the audio and video
594 codec indicated by \a{m}.
595
596 To get all supported file formats, run this query on a default constructed
597 QMediaFormat.
598
599 \sa QMediaFormat::ConversionMode
600*/
601QList<QMediaFormat::FileFormat> QMediaFormat::supportedFileFormats(QMediaFormat::ConversionMode m)
602{
603 return QPlatformMediaIntegration::instance()->formatInfo()->supportedFileFormats(*this, m);
604}
605
606/*!
607 \qmlmethod list<VideoCodec> QtMultimedia::mediaFormat::supportedVideoCodecs(conversionMode)
608 Returns a list of video codecs for the chosen file format and
609 audio codec (\a conversionMode).
610
611 To get all supported video codecs, run this query on a default constructed MediaFormat. To
612 get a list of supported video codecs for a specific combination of a file format and an audio
613 codec, you can set the fileFormat and audioCodec properties before running this query.
614
615 \sa QMediaFormat::ConversionMode
616*/
617
618/*!
619 Returns a list of video codecs for the chosen file format and
620 audio codec (\a m).
621
622 To get all supported video codecs, run this query on a default constructed
623 MediaFormat.
624
625 \sa QMediaFormat::ConversionMode
626*/
627QList<QMediaFormat::VideoCodec> QMediaFormat::supportedVideoCodecs(QMediaFormat::ConversionMode m)
628{
629 return QPlatformMediaIntegration::instance()->formatInfo()->supportedVideoCodecs(*this, m);
630}
631
632/*!
633 \qmlmethod list<AudioCodec> QtMultimedia::mediaFormat::supportedAudioFormats(conversionMode)
634 Returns a list of audio codecs for the chosen file format and
635 video codec (\a conversionMode).
636
637 To get all supported audio codecs, run this query on a default constructed MediaFormat. To get
638 a list of supported audio codecs for a specific combination of a file format and a video codec,
639 you can set the fileFormat and videoCodec properties before running this query.
640
641 \sa QMediaFormat::ConversionMode
642*/
643
644/*!
645 Returns a list of audio codecs for the chosen file format and
646 video codec (\a m).
647
648 To get all supported audio codecs, run this query on a default constructed
649 QMediaFormat.
650
651 \sa QMediaFormat::ConversionMode
652*/
653QList<QMediaFormat::AudioCodec> QMediaFormat::supportedAudioCodecs(QMediaFormat::ConversionMode m)
654{
655 return QPlatformMediaIntegration::instance()->formatInfo()->supportedAudioCodecs(*this, m);
656}
657
658/*!
659 \qmlmethod string QtMultimedia::mediaFormat::fileFormatName(fileFormat)
660 Returns a string based name for \a fileFormat.
661*/
662
663/*!
664 Returns a string based name for \a fileFormat.
665*/
666QString QMediaFormat::fileFormatName(QMediaFormat::FileFormat fileFormat)
667{
668 return QtMultimediaPrivate::StringResolver<QMediaFormat::FileFormat>::toQString(fileFormat)
669 .value_or(QStringLiteral("Unknown File Format"));
670}
671
672/*!
673 \qmlmethod string QtMultimedia::mediaFormat::audioCodecName(codec)
674 Returns a string based name for \a codec.
675*/
676
677/*!
678 Returns a string based name for \a codec.
679*/
680QString QMediaFormat::audioCodecName(QMediaFormat::AudioCodec codec)
681{
682 return QtMultimediaPrivate::StringResolver<QMediaFormat::AudioCodec>::toQString(codec).value_or(
683 QStringLiteral("Unknown Audio Codec"));
684}
685
686/*!
687 \qmlmethod string QtMultimedia::mediaFormat::videoCodecName(codec)
688 Returns a string based name for \a codec.
689*/
690
691/*!
692 Returns a string based name for \a codec.
693*/
694QString QMediaFormat::videoCodecName(QMediaFormat::VideoCodec codec)
695{
696 return QtMultimediaPrivate::StringResolver<QMediaFormat::VideoCodec>::toQString(codec).value_or(
697 QStringLiteral("Unknown Video Codec"));
698}
699
700/*!
701 \qmlmethod string QtMultimedia::mediaFormat::fileFormatDescription(fileFormat)
702 Returns a description for \a fileFormat.
703*/
704
705/*!
706 Returns a description for \a fileFormat.
707*/
708QString QMediaFormat::fileFormatDescription(QMediaFormat::FileFormat fileFormat)
709{
710 return QtMultimediaPrivate::StringResolver<QMediaFormat::FileFormat,
711 DescriptionRole>::toQString(fileFormat)
712 .value_or(QStringLiteral("Unknown File Format"));
713}
714
715/*!
716 \qmlmethod string QtMultimedia::mediaFormat::audioCodecDescription(codec)
717 Returns a description for \a codec.
718*/
719
720/*!
721 Returns a description for \a codec.
722*/
723QString QMediaFormat::audioCodecDescription(QMediaFormat::AudioCodec codec)
724{
725 return QtMultimediaPrivate::StringResolver<QMediaFormat::AudioCodec,
726 DescriptionRole>::toQString(codec)
727 .value_or(QStringLiteral("Unknown Audio Codec"));
728}
729
730/*!
731 \qmlmethod string QtMultimedia::mediaFormat::videoCodecDescription(codec)
732 Returns a description for \a codec.
733*/
734
735/*!
736 Returns a description for \a codec.
737*/
738QString QMediaFormat::videoCodecDescription(QMediaFormat::VideoCodec codec)
739{
740 return QtMultimediaPrivate::StringResolver<QMediaFormat::VideoCodec,
741 DescriptionRole>::toQString(codec)
742 .value_or(QStringLiteral("Unknown Video Codec"));
743}
744
745/*!
746 \fn bool QMediaFormat::operator!=(const QMediaFormat &other) const
747
748 Returns \c true if \a other is not equal to the current media format,
749 otherwise returns \c false.
750*/
751
752/*!
753 Returns \c true if \a other is equal to the current media format, otherwise
754 returns \c false.
755*/
756bool QMediaFormat::operator==(const QMediaFormat &other) const
757{
758 Q_ASSERT(!d);
759 return fmt == other.fmt &&
760 audio == other.audio &&
761 video == other.video;
762}
763
764/*!
765 \enum QMediaFormat::ResolveFlags
766
767 Describes the requirements for resolving a suitable format for
768 QMediaRecorder.
769
770 \value NoFlags
771 No requirements
772 \value RequiresVideo
773 A video codec is required
774
775 \sa resolveForEncoding()
776*/
777
778/*!
779 Resolves the format, based on \a flags, to a format that is supported by
780 QMediaRecorder.
781
782 This method tries to find the best possible match for unspecified settings.
783 Settings that are not supported by the recorder will be modified to the closest
784 match that is supported.
785
786 When resolving, priority is given in the following order:
787 \list 1
788 \li File format
789 \li Video codec
790 \li Audio codec
791 \endlist
792*/
793void QMediaFormat::resolveForEncoding(ResolveFlags flags)
794{
795 const bool requiresVideo = (flags & ResolveFlags::RequiresVideo) != 0;
796
797 if (!requiresVideo)
798 video = VideoCodec::Unspecified;
799
800 // need to adjust the format. Priority is given first to file format, then video codec, then audio codec
801
802 QMediaFormat nullFormat;
803 auto supportedFormats = nullFormat.supportedFileFormats(QMediaFormat::Encode);
804 auto supportedAudioCodecs = nullFormat.supportedAudioCodecs(QMediaFormat::Encode);
805 auto supportedVideoCodecs = nullFormat.supportedVideoCodecs(QMediaFormat::Encode);
806
807 auto bestSupportedFileFormat = [&](QMediaFormat::AudioCodec audio = QMediaFormat::AudioCodec::Unspecified,
808 QMediaFormat::VideoCodec video = QMediaFormat::VideoCodec::Unspecified)
809 {
810 QMediaFormat f;
811 f.setAudioCodec(audio);
812 f.setVideoCodec(video);
813 auto supportedFormats = f.supportedFileFormats(QMediaFormat::Encode);
814 auto *list = (flags == NoFlags) ? audioFormatPriorityList : videoFormatPriorityList;
815 while (*list != QMediaFormat::UnspecifiedFormat) {
816 if (supportedFormats.contains(*list))
817 break;
818 ++list;
819 }
820 return *list;
821 };
822
823 // reset format if it does not support video when video is required
824 if (requiresVideo && this->supportedVideoCodecs(QMediaFormat::Encode).isEmpty())
825 fmt = QMediaFormat::UnspecifiedFormat;
826
827 // reset non supported formats and codecs
828 if (!supportedFormats.contains(fmt))
829 fmt = QMediaFormat::UnspecifiedFormat;
830 if (!supportedAudioCodecs.contains(audio))
831 audio = QMediaFormat::AudioCodec::Unspecified;
832 if (!requiresVideo || !supportedVideoCodecs.contains(video))
833 video = QMediaFormat::VideoCodec::Unspecified;
834
835 if (requiresVideo) {
836 // try finding a file format that is supported
837 if (fmt == QMediaFormat::UnspecifiedFormat)
838 fmt = bestSupportedFileFormat(audio, video);
839 // try without the audio codec
840 if (fmt == QMediaFormat::UnspecifiedFormat)
841 fmt = bestSupportedFileFormat(QMediaFormat::AudioCodec::Unspecified, video);
842 }
843 // try without the video codec
844 if (fmt == QMediaFormat::UnspecifiedFormat)
845 fmt = bestSupportedFileFormat(audio);
846 // give me a format that's supported
847 if (fmt == QMediaFormat::UnspecifiedFormat)
848 fmt = bestSupportedFileFormat();
849 // still nothing? Give up
850 if (fmt == QMediaFormat::UnspecifiedFormat) {
851 *this = {};
852 return;
853 }
854
855 // find a working video codec
856 if (requiresVideo) {
857 // reset the audio codec, so that we won't throw away the video codec
858 // if it is supported (choosing the specified video codec has higher
859 // priority than the specified audio codec)
860 auto a = audio;
861 audio = QMediaFormat::AudioCodec::Unspecified;
862 auto videoCodecs = this->supportedVideoCodecs(QMediaFormat::Encode);
863 if (!videoCodecs.contains(video)) {
864 // not supported, try to find a replacement
865 auto *list = videoPriorityList;
866 while (*list != QMediaFormat::VideoCodec::Unspecified) {
867 if (videoCodecs.contains(*list))
868 break;
869 ++list;
870 }
871 video = *list;
872 }
873 audio = a;
874 } else {
875 video = QMediaFormat::VideoCodec::Unspecified;
876 }
877
878 // and a working audio codec
879 auto audioCodecs = this->supportedAudioCodecs(QMediaFormat::Encode);
880 if (!audioCodecs.contains(audio)) {
881 auto *list = audioPriorityList;
882 while (*list != QMediaFormat::AudioCodec::Unspecified) {
883 if (audioCodecs.contains(*list))
884 break;
885 ++list;
886 }
887 audio = *list;
888 }
889}
890
891/*!
892 \variable QMediaFormat::audio
893 \internal
894*/
895/*!
896 \variable QMediaFormat::d
897 \internal
898*/
899/*!
900 \variable QMediaFormat::video
901 \internal
902*/
903/*!
904 \variable QMediaFormat::fmt
905 \internal
906*/
907QT_END_NAMESPACE
908
909#include "moc_qmediaformat.cpp"
Combined button and popup list for selecting options.
QT_MM_MAKE_STRING_RESOLVER(QMediaFormat::FileFormat, DescriptionRole,(QMediaFormat::UnspecifiedFormat, "Unspecified File Format")(QMediaFormat::WMV, "Windows Media Video")(QMediaFormat::AVI, "Audio Video Interleave")(QMediaFormat::Matroska, "Matroska Multimedia Container")(QMediaFormat::MPEG4, "MPEG-4 Video Container")(QMediaFormat::Ogg, "Ogg")(QMediaFormat::QuickTime, "QuickTime Container")(QMediaFormat::WebM, "WebM")(QMediaFormat::Mpeg4Audio, "MPEG-4 Audio")(QMediaFormat::AAC, "AAC")(QMediaFormat::WMA, "Windows Media Audio")(QMediaFormat::MP3, "MP3")(QMediaFormat::FLAC, "Free Lossless Audio Codec (FLAC)")(QMediaFormat::Wave, "Wave File"))
QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QMediaFormatPrivate)
QT_MM_MAKE_STRING_RESOLVER(QMediaFormat::FileFormat, QtMultimediaPrivate::EnumName,(QMediaFormat::UnspecifiedFormat, "Unspecified")(QMediaFormat::WMV, "WMV")(QMediaFormat::AVI, "AVI")(QMediaFormat::Matroska, "Matroska")(QMediaFormat::MPEG4, "MPEG-4")(QMediaFormat::Ogg, "Ogg")(QMediaFormat::QuickTime, "QuickTime")(QMediaFormat::WebM, "WebM")(QMediaFormat::Mpeg4Audio, "MPEG-4 Audio")(QMediaFormat::AAC, "AAC")(QMediaFormat::WMA, "WMA")(QMediaFormat::MP3, "MP3")(QMediaFormat::FLAC, "FLAC")(QMediaFormat::Wave, "Wave"))
QT_MM_MAKE_STRING_RESOLVER(QMediaFormat::AudioCodec, DescriptionRole,(QMediaFormat::AudioCodec::Unspecified, "Unspecified Audio Codec")(QMediaFormat::AudioCodec::MP3, "MP3")(QMediaFormat::AudioCodec::AAC, "Advanced Audio Codec (AAC)")(QMediaFormat::AudioCodec::AC3, "Dolby Digital (AC3)")(QMediaFormat::AudioCodec::EAC3, "Dolby Digital Plus (E-AC3)")(QMediaFormat::AudioCodec::FLAC, "Free Lossless Audio Codec (FLAC)")(QMediaFormat::AudioCodec::DolbyTrueHD, "Dolby True HD")(QMediaFormat::AudioCodec::Opus, "Opus")(QMediaFormat::AudioCodec::Vorbis, "Vorbis")(QMediaFormat::AudioCodec::Wave, "Wave")(QMediaFormat::AudioCodec::WMA, "Windows Media Audio")(QMediaFormat::AudioCodec::ALAC, "Apple Lossless Audio Codec (ALAC)"))