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
qwindowsmultimediautils.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 <QtCore/qt_windows.h>
5static_assert(WINVER >= _WIN32_WINNT_WIN10, "Win10 required for newer audio formats.");
6
8
9#include <mfapi.h>
10#include <mfidl.h>
11
13
14QVideoFrameFormat::PixelFormat QWindowsMultimediaUtils::pixelFormatFromMediaSubtype(const GUID &subtype)
15{
16 if (subtype == MFVideoFormat_ARGB32)
17#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
18 return QVideoFrameFormat::Format_BGRA8888;
19#else
20 return QVideoFrameFormat::Format_ARGB8888;
21#endif
22 if (subtype == MFVideoFormat_RGB32)
23#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
24 return QVideoFrameFormat::Format_BGRX8888;
25#else
26 return QVideoFrameFormat::Format_XRGB8888;
27#endif
28 if (subtype == MFVideoFormat_AYUV)
29 return QVideoFrameFormat::Format_AYUV;
30 if (subtype == MFVideoFormat_I420)
31 return QVideoFrameFormat::Format_YUV420P;
32 if (subtype == MFVideoFormat_UYVY)
33 return QVideoFrameFormat::Format_UYVY;
34 if (subtype == MFVideoFormat_YV12)
35 return QVideoFrameFormat::Format_YV12;
36 if (subtype == MFVideoFormat_NV12)
37 return QVideoFrameFormat::Format_NV12;
38 if (subtype == MFVideoFormat_YUY2)
39 return QVideoFrameFormat::Format_YUYV;
40 if (subtype == MFVideoFormat_P010)
41 return QVideoFrameFormat::Format_P010;
42 if (subtype == MFVideoFormat_P016)
43 return QVideoFrameFormat::Format_P016;
44 if (subtype == MFVideoFormat_L8)
45 return QVideoFrameFormat::Format_Y8;
46 if (subtype == MFVideoFormat_L16)
47 return QVideoFrameFormat::Format_Y16;
48 if (subtype == MFVideoFormat_MJPG)
49 return QVideoFrameFormat::Format_Jpeg;
50
51 return QVideoFrameFormat::Format_Invalid;
52}
53
54GUID QWindowsMultimediaUtils::videoFormatForCodec(QMediaFormat::VideoCodec codec)
55{
56 switch (codec) {
57 case QMediaFormat::VideoCodec::MPEG1:
58 return MFVideoFormat_MPG1;
59 case QMediaFormat::VideoCodec::MPEG2:
60 return MFVideoFormat_MPEG2;
61 case QMediaFormat::VideoCodec::MPEG4:
62 return MFVideoFormat_MP4V;
63 case QMediaFormat::VideoCodec::H264:
64 return MFVideoFormat_H264;
65 case QMediaFormat::VideoCodec::H265:
66 return MFVideoFormat_H265;
67 case QMediaFormat::VideoCodec::VP8:
68 return MFVideoFormat_VP80;
69 case QMediaFormat::VideoCodec::VP9:
70 return MFVideoFormat_VP90;
71 case QMediaFormat::VideoCodec::AV1:
72 return MFVideoFormat_AV1;
73 case QMediaFormat::VideoCodec::WMV:
74 return MFVideoFormat_WMV3;
75 case QMediaFormat::VideoCodec::MotionJPEG:
76 return MFVideoFormat_MJPG;
77 default:
78 return MFVideoFormat_H264;
79 }
80}
81
82QMediaFormat::VideoCodec QWindowsMultimediaUtils::codecForVideoFormat(GUID format)
83{
84 if (format == MFVideoFormat_MPG1)
85 return QMediaFormat::VideoCodec::MPEG1;
86 if (format == MFVideoFormat_MPEG2)
87 return QMediaFormat::VideoCodec::MPEG2;
88 if (format == MFVideoFormat_MP4V
89 || format == MFVideoFormat_M4S2
90 || format == MFVideoFormat_MP4S
91 || format == MFVideoFormat_MP43)
92 return QMediaFormat::VideoCodec::MPEG4;
93 if (format == MFVideoFormat_H264)
94 return QMediaFormat::VideoCodec::H264;
95 if (format == MFVideoFormat_H265)
96 return QMediaFormat::VideoCodec::H265;
97 if (format == MFVideoFormat_VP80)
98 return QMediaFormat::VideoCodec::VP8;
99 if (format == MFVideoFormat_VP90)
100 return QMediaFormat::VideoCodec::VP9;
101 if (format == MFVideoFormat_AV1)
102 return QMediaFormat::VideoCodec::AV1;
103 if (format == MFVideoFormat_WMV1
104 || format == MFVideoFormat_WMV2
105 || format == MFVideoFormat_WMV3)
106 return QMediaFormat::VideoCodec::WMV;
107 if (format == MFVideoFormat_MJPG)
108 return QMediaFormat::VideoCodec::MotionJPEG;
109 return QMediaFormat::VideoCodec::Unspecified;
110}
111
112GUID QWindowsMultimediaUtils::audioFormatForCodec(QMediaFormat::AudioCodec codec)
113{
114 switch (codec) {
115 case QMediaFormat::AudioCodec::MP3:
116 return MFAudioFormat_MP3;
117 case QMediaFormat::AudioCodec::AAC:
118 return MFAudioFormat_AAC;
119 case QMediaFormat::AudioCodec::ALAC:
120 return MFAudioFormat_ALAC;
121 case QMediaFormat::AudioCodec::FLAC:
122 return MFAudioFormat_FLAC;
123 case QMediaFormat::AudioCodec::Vorbis:
124 return MFAudioFormat_Vorbis;
125 case QMediaFormat::AudioCodec::Wave:
126 return MFAudioFormat_PCM;
127 case QMediaFormat::AudioCodec::Opus:
128 return MFAudioFormat_Opus;
129 case QMediaFormat::AudioCodec::AC3:
130 return MFAudioFormat_Dolby_AC3;
131 case QMediaFormat::AudioCodec::EAC3:
132 return MFAudioFormat_Dolby_DDPlus;
133 case QMediaFormat::AudioCodec::WMA:
134 return MFAudioFormat_WMAudioV9;
135 default:
136 return MFAudioFormat_AAC;
137 }
138}
139
140QMediaFormat::AudioCodec QWindowsMultimediaUtils::codecForAudioFormat(GUID format)
141{
142 if (format == MFAudioFormat_MP3)
143 return QMediaFormat::AudioCodec::MP3;
144 if (format == MFAudioFormat_AAC)
145 return QMediaFormat::AudioCodec::AAC;
146 if (format == MFAudioFormat_ALAC)
147 return QMediaFormat::AudioCodec::ALAC;
148 if (format == MFAudioFormat_FLAC)
149 return QMediaFormat::AudioCodec::FLAC;
150 if (format == MFAudioFormat_Vorbis)
151 return QMediaFormat::AudioCodec::Vorbis;
152 if (format == MFAudioFormat_PCM)
153 return QMediaFormat::AudioCodec::Wave;
154 if (format == MFAudioFormat_Opus)
155 return QMediaFormat::AudioCodec::Opus;
156 if (format == MFAudioFormat_Dolby_AC3)
157 return QMediaFormat::AudioCodec::AC3;
158 if (format == MFAudioFormat_Dolby_DDPlus)
159 return QMediaFormat::AudioCodec::EAC3;
160 if (format == MFAudioFormat_WMAudioV8
161 || format == MFAudioFormat_WMAudioV9
162 || format == MFAudioFormat_WMAudio_Lossless)
163 return QMediaFormat::AudioCodec::WMA;
164 return QMediaFormat::AudioCodec::Unspecified;
165}
166
167GUID QWindowsMultimediaUtils::containerForVideoFileFormat(QMediaFormat::FileFormat format)
168{
169 switch (format) {
170 case QMediaFormat::FileFormat::MPEG4:
171 return MFTranscodeContainerType_MPEG4;
172 case QMediaFormat::FileFormat::WMV:
173 return MFTranscodeContainerType_ASF;
174 case QMediaFormat::FileFormat::AVI:
175 return MFTranscodeContainerType_AVI;
176 default:
177 return MFTranscodeContainerType_MPEG4;
178 }
179}
180
181GUID QWindowsMultimediaUtils::containerForAudioFileFormat(QMediaFormat::FileFormat format)
182{
183 switch (format) {
184 case QMediaFormat::FileFormat::MP3:
185 return MFTranscodeContainerType_MP3;
186 case QMediaFormat::FileFormat::AAC:
187 return MFTranscodeContainerType_ADTS;
188 case QMediaFormat::FileFormat::Mpeg4Audio:
189 return MFTranscodeContainerType_MPEG4;
190 case QMediaFormat::FileFormat::WMA:
191 return MFTranscodeContainerType_ASF;
192 case QMediaFormat::FileFormat::FLAC:
193 return MFTranscodeContainerType_FLAC;
194 case QMediaFormat::FileFormat::Wave:
195 return MFTranscodeContainerType_WAVE;
196 default:
197 return MFTranscodeContainerType_MPEG4;
198 }
199}
200
201QT_END_NAMESPACE