Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qdarwinformatsinfo.mm
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
5#include <AVFoundation/AVFoundation.h>
6#include <qdebug.h>
7
9
10static struct {
11 const char *name;
14 { "video/x-ms-asf", QMediaFormat::WMV },
15 { "video/avi", QMediaFormat::AVI },
16 { "video/x-matroska", QMediaFormat::Matroska },
17 { "video/mp4", QMediaFormat::MPEG4 },
18 { "video/quicktime", QMediaFormat::QuickTime },
19 { "video/ogg", QMediaFormat::Ogg },
20 { "audio/mp3", QMediaFormat::MP3 },
21 { "audio/flac", QMediaFormat::FLAC },
23};
24
25static struct {
26 const char *name;
28} videoCodecMap[] = {
29 // See CMVideoCodecType for the four character code names of codecs
30 { "; codecs=\"mp1v\"", QMediaFormat::VideoCodec::MPEG1 },
31 { "; codecs=\"mp2v\"", QMediaFormat::VideoCodec::MPEG2 },
32 { "; codecs=\"mp4v\"", QMediaFormat::VideoCodec::MPEG4 },
33 { "; codecs=\"avc1\"", QMediaFormat::VideoCodec::H264 },
34 { "; codecs=\"hvc1\"", QMediaFormat::VideoCodec::H265 },
35 { "; codecs=\"vp09\"", QMediaFormat::VideoCodec::VP9 },
36 { "; codecs=\"av01\"", QMediaFormat::VideoCodec::AV1 }, // ### ????
37 { "; codecs=\"jpeg\"", QMediaFormat::VideoCodec::MotionJPEG },
39};
40
41static struct {
42 const char *name;
44} audioCodecMap[] = {
45 // AudioFile.h
46 // ### The next two entries do not work, probably because they contain non a space and period and AVFoundation doesn't like that
47 // We know they are supported on all Apple platforms, so we'll add them manually below
48// { "; codecs=\".mp3\"", QMediaFormat::AudioCodec::MP3 },
49// { "; codecs=\"aac \"", QMediaFormat::AudioCodec::AAC },
50 { "; codecs=\"ac-3\"", QMediaFormat::AudioCodec::AC3 },
51 { "; codecs=\"ec-3\"", QMediaFormat::AudioCodec::EAC3 },
52 { "; codecs=\"flac\"", QMediaFormat::AudioCodec::FLAC },
53 { "; codecs=\"alac\"", QMediaFormat::AudioCodec::ALAC },
54 { "; codecs=\"opus\"", QMediaFormat::AudioCodec::Opus },
56};
57
59{
60 auto avtypes = [AVURLAsset audiovisualMIMETypes];
61 for (AVFileType filetype in avtypes) {
62 auto *m = mediaContainerMap;
63 while (m->name) {
64 if (strcmp(filetype.UTF8String, m->name)) {
65 ++m;
66 continue;
67 }
68
69 QList<QMediaFormat::VideoCodec> video;
70 QList<QMediaFormat::AudioCodec> audio;
71
72 auto *v = videoCodecMap;
73 while (v->name) {
74 QByteArray extendedMimetype = m->name;
75 extendedMimetype += v->name;
76 if ([AVURLAsset isPlayableExtendedMIMEType:[NSString stringWithUTF8String:extendedMimetype.constData()]])
77 video << v->value;
78 ++v;
79 }
80
81 auto *a = audioCodecMap;
82 while (a->name) {
83 QByteArray extendedMimetype = m->name;
84 extendedMimetype += a->name;
85 if ([AVURLAsset isPlayableExtendedMIMEType:[NSString stringWithUTF8String:extendedMimetype.constData()]])
86 audio << a->value;
87 ++a;
88 }
89 // Added manually, see comment in the list above
90 if (m->value <= QMediaFormat::AAC)
92 if (m->value < QMediaFormat::AAC || m->value == QMediaFormat::MP3)
94
95 decoders << CodecMap{ m->value, audio, video };
96 ++m;
97 }
98 }
99
100 // seems AVFoundation only supports those for encoding
101 encoders = {
110 {} },
113 {} },
114 };
115
116 // ###
118}
119
123
125{
126 int codecId = kAudioFormatMPEG4AAC;
127 switch (codec) {
132 // Unsupported, shouldn't happen. Fall back to AAC
134 codecId = kAudioFormatMPEG4AAC;
135 break;
137 codecId = kAudioFormatMPEGLayer3;
138 break;
140 codecId = kAudioFormatAC3;
141 break;
143 codecId = kAudioFormatEnhancedAC3;
144 break;
146 codecId = kAudioFormatFLAC;
147 break;
149 codecId = kAudioFormatAppleLossless;
150 break;
152 codecId = kAudioFormatOpus;
153 break;
155 codecId = kAudioFormatLinearPCM;
156 }
157 return codecId;
158}
159
161{
162 const char *c = "hvc1"; // fallback is H265
163 switch (codec) {
170 break;
171
173 c = "mp1v";
174 break;
176 c = "mp2v";
177 break;
179 c = "mp4v";
180 break;
182 c = "avc1";
183 break;
185 c = "vp09";
186 break;
188 c = "jpeg";
189 }
190 return [NSString stringWithUTF8String:c];
191}
192
194{
195 switch (container) {
197 return AVFileTypeMPEG4;
199 return AVFileTypeQuickTimeMovie;
201 return AVFileTypeMPEGLayer3;
203 return AVFileTypeAppleM4A;
205 return AVFileTypeWAVE;
206 default:
207 return AVFileTypeQuickTimeMovie;
208 }
209}
210
\inmodule QtCore
Definition qbytearray.h:57
static int audioFormatForCodec(QMediaFormat::AudioCodec codec)
static NSString * videoFormatForCodec(QMediaFormat::VideoCodec codec)
static NSString * avFileTypeForContainerFormat(QMediaFormat::FileFormat fileType)
AudioCodec
\qmlproperty enumeration QtMultimedia::mediaFormat::fileFormat
FileFormat
Describes the container format used in a multimedia file or stream.
VideoCodec
\qmlproperty enumeration QtMultimedia::mediaFormat::audioCodec
QList< QImageCapture::FileFormat > imageFormats
Combined button and popup list for selecting options.
QMediaFormat::FileFormat value
const char * name
static struct @727 videoCodecMap[]
static struct @728 audioCodecMap[]
static QT_BEGIN_NAMESPACE struct @726 mediaContainerMap[]
QMediaFormat::AudioCodec codec
static AVCodecID codecId(QMediaFormat::VideoCodec codec)
GLsizei const GLfloat * v
[13]
const GLfloat * m
GLboolean GLboolean GLboolean GLboolean a
[7]
const GLubyte * c
GLuint in