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
54QVideoFrameFormat::ColorRange QWindowsMultimediaUtils::colorRangeFromNominalRange(UINT32 nominalRange)
55{
56 switch (nominalRange) {
57 case MFNominalRange_0_255:
58 return QVideoFrameFormat::ColorRange_Full;
59 case MFNominalRange_16_235:
60 return QVideoFrameFormat::ColorRange_Video;
61 default:
62 return QVideoFrameFormat::ColorRange_Unknown;
63 }
64}
65
66QVideoFrameFormat::ColorSpace QWindowsMultimediaUtils::colorSpaceFromMatrix(UINT32 yuvMatrix)
67{
68 switch (yuvMatrix) {
69 case MFVideoTransferMatrix_BT709:
70 return QVideoFrameFormat::ColorSpace_BT709;
71 case MFVideoTransferMatrix_BT601:
72 return QVideoFrameFormat::ColorSpace_BT601;
73 case MFVideoTransferMatrix_BT2020_10:
74 case MFVideoTransferMatrix_BT2020_12:
75 return QVideoFrameFormat::ColorSpace_BT2020;
76 default:
77 return QVideoFrameFormat::ColorSpace_Undefined;
78 }
79}
80
81GUID QWindowsMultimediaUtils::videoFormatForCodec(QMediaFormat::VideoCodec codec)
82{
83 switch (codec) {
84 case QMediaFormat::VideoCodec::MPEG1:
85 return MFVideoFormat_MPG1;
86 case QMediaFormat::VideoCodec::MPEG2:
87 return MFVideoFormat_MPEG2;
88 case QMediaFormat::VideoCodec::MPEG4:
89 return MFVideoFormat_MP4V;
90 case QMediaFormat::VideoCodec::H264:
91 return MFVideoFormat_H264;
92 case QMediaFormat::VideoCodec::H265:
93 return MFVideoFormat_H265;
94 case QMediaFormat::VideoCodec::VP8:
95 return MFVideoFormat_VP80;
96 case QMediaFormat::VideoCodec::VP9:
97 return MFVideoFormat_VP90;
98 case QMediaFormat::VideoCodec::AV1:
99 return MFVideoFormat_AV1;
100 case QMediaFormat::VideoCodec::WMV:
101 return MFVideoFormat_WMV3;
102 case QMediaFormat::VideoCodec::MotionJPEG:
103 return MFVideoFormat_MJPG;
104 default:
105 return MFVideoFormat_H264;
106 }
107}
108
109QMediaFormat::VideoCodec QWindowsMultimediaUtils::codecForVideoFormat(GUID format)
110{
111 if (format == MFVideoFormat_MPG1)
112 return QMediaFormat::VideoCodec::MPEG1;
113 if (format == MFVideoFormat_MPEG2)
114 return QMediaFormat::VideoCodec::MPEG2;
115 if (format == MFVideoFormat_MP4V
116 || format == MFVideoFormat_M4S2
117 || format == MFVideoFormat_MP4S
118 || format == MFVideoFormat_MP43)
119 return QMediaFormat::VideoCodec::MPEG4;
120 if (format == MFVideoFormat_H264)
121 return QMediaFormat::VideoCodec::H264;
122 if (format == MFVideoFormat_H265)
123 return QMediaFormat::VideoCodec::H265;
124 if (format == MFVideoFormat_VP80)
125 return QMediaFormat::VideoCodec::VP8;
126 if (format == MFVideoFormat_VP90)
127 return QMediaFormat::VideoCodec::VP9;
128 if (format == MFVideoFormat_AV1)
129 return QMediaFormat::VideoCodec::AV1;
130 if (format == MFVideoFormat_WMV1
131 || format == MFVideoFormat_WMV2
132 || format == MFVideoFormat_WMV3)
133 return QMediaFormat::VideoCodec::WMV;
134 if (format == MFVideoFormat_MJPG)
135 return QMediaFormat::VideoCodec::MotionJPEG;
136 return QMediaFormat::VideoCodec::Unspecified;
137}
138
139GUID QWindowsMultimediaUtils::audioFormatForCodec(QMediaFormat::AudioCodec codec)
140{
141 switch (codec) {
142 case QMediaFormat::AudioCodec::MP3:
143 return MFAudioFormat_MP3;
144 case QMediaFormat::AudioCodec::AAC:
145 return MFAudioFormat_AAC;
146 case QMediaFormat::AudioCodec::ALAC:
147 return MFAudioFormat_ALAC;
148 case QMediaFormat::AudioCodec::FLAC:
149 return MFAudioFormat_FLAC;
150 case QMediaFormat::AudioCodec::Vorbis:
151 return MFAudioFormat_Vorbis;
152 case QMediaFormat::AudioCodec::Wave:
153 return MFAudioFormat_PCM;
154 case QMediaFormat::AudioCodec::Opus:
155 return MFAudioFormat_Opus;
156 case QMediaFormat::AudioCodec::AC3:
157 return MFAudioFormat_Dolby_AC3;
158 case QMediaFormat::AudioCodec::EAC3:
159 return MFAudioFormat_Dolby_DDPlus;
160 case QMediaFormat::AudioCodec::WMA:
161 return MFAudioFormat_WMAudioV9;
162 default:
163 return MFAudioFormat_AAC;
164 }
165}
166
167QMediaFormat::AudioCodec QWindowsMultimediaUtils::codecForAudioFormat(GUID format)
168{
169 if (format == MFAudioFormat_MP3)
170 return QMediaFormat::AudioCodec::MP3;
171 if (format == MFAudioFormat_AAC)
172 return QMediaFormat::AudioCodec::AAC;
173 if (format == MFAudioFormat_ALAC)
174 return QMediaFormat::AudioCodec::ALAC;
175 if (format == MFAudioFormat_FLAC)
176 return QMediaFormat::AudioCodec::FLAC;
177 if (format == MFAudioFormat_Vorbis)
178 return QMediaFormat::AudioCodec::Vorbis;
179 if (format == MFAudioFormat_PCM)
180 return QMediaFormat::AudioCodec::Wave;
181 if (format == MFAudioFormat_Opus)
182 return QMediaFormat::AudioCodec::Opus;
183 if (format == MFAudioFormat_Dolby_AC3)
184 return QMediaFormat::AudioCodec::AC3;
185 if (format == MFAudioFormat_Dolby_DDPlus)
186 return QMediaFormat::AudioCodec::EAC3;
187 if (format == MFAudioFormat_WMAudioV8
188 || format == MFAudioFormat_WMAudioV9
189 || format == MFAudioFormat_WMAudio_Lossless)
190 return QMediaFormat::AudioCodec::WMA;
191 return QMediaFormat::AudioCodec::Unspecified;
192}
193
194GUID QWindowsMultimediaUtils::containerForVideoFileFormat(QMediaFormat::FileFormat format)
195{
196 switch (format) {
197 case QMediaFormat::FileFormat::MPEG4:
198 return MFTranscodeContainerType_MPEG4;
199 case QMediaFormat::FileFormat::WMV:
200 return MFTranscodeContainerType_ASF;
201 case QMediaFormat::FileFormat::AVI:
202 return MFTranscodeContainerType_AVI;
203 default:
204 return MFTranscodeContainerType_MPEG4;
205 }
206}
207
208GUID QWindowsMultimediaUtils::containerForAudioFileFormat(QMediaFormat::FileFormat format)
209{
210 switch (format) {
211 case QMediaFormat::FileFormat::MP3:
212 return MFTranscodeContainerType_MP3;
213 case QMediaFormat::FileFormat::AAC:
214 return MFTranscodeContainerType_ADTS;
215 case QMediaFormat::FileFormat::Mpeg4Audio:
216 return MFTranscodeContainerType_MPEG4;
217 case QMediaFormat::FileFormat::WMA:
218 return MFTranscodeContainerType_ASF;
219 case QMediaFormat::FileFormat::FLAC:
220 return MFTranscodeContainerType_FLAC;
221 case QMediaFormat::FileFormat::Wave:
222 return MFTranscodeContainerType_WAVE;
223 default:
224 return MFTranscodeContainerType_MPEG4;
225 }
226}
227
228QT_END_NAMESPACE
Combined button and popup list for selecting options.