c9d5da6f13eacd720be3eceb4f6a4e90265c2750
[vlc.git] / modules / codec / avcodec / fourcc.c
1 /*****************************************************************************
2  * fourcc.c: libavcodec <-> libvlc conversion routines
3  *****************************************************************************
4  * Copyright (C) 1999-2009 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *          Gildas Bazin <gbazin@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28
29 #include <vlc_common.h>
30 #include <vlc_codec.h>
31
32 #include <libavcodec/avcodec.h>
33 #include "avcodec.h"
34
35 /*****************************************************************************
36  * Codec fourcc -> libavcodec Codec_id mapping
37  * Sorted by AVCodecID enumeration order
38  *****************************************************************************/
39 struct vlc_avcodec_fourcc
40 {
41     vlc_fourcc_t i_fourcc;
42     unsigned i_codec;
43 };
44
45 /*
46  * Video Codecs
47  */
48 static const struct vlc_avcodec_fourcc video_codecs[] =
49 {
50     { VLC_CODEC_MP1V, AV_CODEC_ID_MPEG1VIDEO },
51     { VLC_CODEC_MP2V, AV_CODEC_ID_MPEG2VIDEO }, /* prefer MPEG2 over MPEG1 */
52     { VLC_CODEC_MPGV, AV_CODEC_ID_MPEG2VIDEO }, /* prefer MPEG2 over MPEG1 */
53     /* AV_CODEC_ID_MPEG2VIDEO_XVMC */
54     { VLC_CODEC_H261, AV_CODEC_ID_H261 },
55     { VLC_CODEC_H263, AV_CODEC_ID_H263 },
56     { VLC_CODEC_RV10, AV_CODEC_ID_RV10 },
57     { VLC_CODEC_RV13, AV_CODEC_ID_RV10 },
58     { VLC_CODEC_RV20, AV_CODEC_ID_RV20 },
59     { VLC_CODEC_MJPG, AV_CODEC_ID_MJPEG },
60     { VLC_CODEC_MJPGB, AV_CODEC_ID_MJPEGB },
61     { VLC_CODEC_LJPG, AV_CODEC_ID_LJPEG },
62     { VLC_CODEC_SP5X, AV_CODEC_ID_SP5X },
63     { VLC_CODEC_JPEGLS, AV_CODEC_ID_JPEGLS },
64     { VLC_CODEC_MP4V, AV_CODEC_ID_MPEG4 },
65     /* AV_CODEC_ID_RAWVIDEO */
66     { VLC_CODEC_DIV1, AV_CODEC_ID_MSMPEG4V1 },
67     { VLC_CODEC_DIV2, AV_CODEC_ID_MSMPEG4V2 },
68     { VLC_CODEC_DIV3, AV_CODEC_ID_MSMPEG4V3 },
69     { VLC_CODEC_WMV1, AV_CODEC_ID_WMV1 },
70     { VLC_CODEC_WMV2, AV_CODEC_ID_WMV2 },
71     { VLC_CODEC_H263P, AV_CODEC_ID_H263P },
72     { VLC_CODEC_H263I, AV_CODEC_ID_H263I },
73     { VLC_CODEC_FLV1, AV_CODEC_ID_FLV1 },
74     { VLC_CODEC_SVQ1, AV_CODEC_ID_SVQ1 },
75     { VLC_CODEC_SVQ3, AV_CODEC_ID_SVQ3 },
76     { VLC_CODEC_DV, AV_CODEC_ID_DVVIDEO },
77     { VLC_CODEC_HUFFYUV, AV_CODEC_ID_HUFFYUV },
78     { VLC_CODEC_CYUV, AV_CODEC_ID_CYUV },
79     { VLC_CODEC_H264, AV_CODEC_ID_H264 },
80     { VLC_CODEC_INDEO3, AV_CODEC_ID_INDEO3 },
81     { VLC_CODEC_VP3, AV_CODEC_ID_VP3 },
82     { VLC_CODEC_THEORA, AV_CODEC_ID_THEORA },
83 #if ( !defined( WORDS_BIGENDIAN ) )
84     /* Asus Video (Another thing that doesn't work on PPC) */
85     { VLC_CODEC_ASV1, AV_CODEC_ID_ASV1 },
86     { VLC_CODEC_ASV2, AV_CODEC_ID_ASV2 },
87 #endif
88     { VLC_CODEC_FFV1, AV_CODEC_ID_FFV1 },
89     { VLC_CODEC_4XM, AV_CODEC_ID_4XM },
90     { VLC_CODEC_VCR1, AV_CODEC_ID_VCR1 },
91     { VLC_CODEC_CLJR, AV_CODEC_ID_CLJR },
92     { VLC_CODEC_MDEC, AV_CODEC_ID_MDEC },
93     { VLC_CODEC_ROQ, AV_CODEC_ID_ROQ },
94     { VLC_CODEC_INTERPLAY, AV_CODEC_ID_INTERPLAY_VIDEO },
95     { VLC_CODEC_XAN_WC3, AV_CODEC_ID_XAN_WC3 },
96     { VLC_CODEC_XAN_WC4, AV_CODEC_ID_XAN_WC4 },
97     { VLC_CODEC_RPZA, AV_CODEC_ID_RPZA },
98     { VLC_CODEC_CINEPAK, AV_CODEC_ID_CINEPAK },
99     { VLC_CODEC_WS_VQA, AV_CODEC_ID_WS_VQA },
100     { VLC_CODEC_MSRLE, AV_CODEC_ID_MSRLE },
101     { VLC_CODEC_MSVIDEO1, AV_CODEC_ID_MSVIDEO1 },
102     { VLC_CODEC_IDCIN, AV_CODEC_ID_IDCIN },
103     { VLC_CODEC_8BPS, AV_CODEC_ID_8BPS },
104     { VLC_CODEC_SMC, AV_CODEC_ID_SMC },
105     { VLC_CODEC_FLIC, AV_CODEC_ID_FLIC },
106     { VLC_CODEC_TRUEMOTION1, AV_CODEC_ID_TRUEMOTION1 },
107     { VLC_CODEC_VMDVIDEO, AV_CODEC_ID_VMDVIDEO },
108     { VLC_CODEC_LCL_MSZH, AV_CODEC_ID_MSZH },
109     { VLC_CODEC_LCL_ZLIB, AV_CODEC_ID_ZLIB },
110     { VLC_CODEC_QTRLE, AV_CODEC_ID_QTRLE },
111     { VLC_CODEC_TSCC, AV_CODEC_ID_TSCC },
112     { VLC_CODEC_ULTI, AV_CODEC_ID_ULTI },
113     { VLC_CODEC_QDRAW, AV_CODEC_ID_QDRAW },
114     { VLC_CODEC_VIXL, AV_CODEC_ID_VIXL },
115     { VLC_CODEC_QPEG, AV_CODEC_ID_QPEG },
116     { VLC_CODEC_PNG, AV_CODEC_ID_PNG },
117     { VLC_CODEC_PPM, AV_CODEC_ID_PPM },
118     /* AV_CODEC_ID_PBM */
119     { VLC_CODEC_PGM, AV_CODEC_ID_PGM },
120     { VLC_CODEC_PGMYUV, AV_CODEC_ID_PGMYUV },
121     { VLC_CODEC_PAM, AV_CODEC_ID_PAM },
122     { VLC_CODEC_FFVHUFF, AV_CODEC_ID_FFVHUFF },
123     { VLC_CODEC_RV30, AV_CODEC_ID_RV30 },
124     { VLC_CODEC_RV40, AV_CODEC_ID_RV40 },
125     { VLC_CODEC_VC1,  AV_CODEC_ID_VC1 },
126     { VLC_CODEC_WMVA, AV_CODEC_ID_VC1 },
127     { VLC_CODEC_WMV3, AV_CODEC_ID_WMV3 },
128     { VLC_CODEC_WMVP, AV_CODEC_ID_WMV3 },
129     { VLC_CODEC_LOCO, AV_CODEC_ID_LOCO },
130     { VLC_CODEC_WNV1, AV_CODEC_ID_WNV1 },
131     { VLC_CODEC_AASC, AV_CODEC_ID_AASC },
132     { VLC_CODEC_INDEO2, AV_CODEC_ID_INDEO2 },
133     { VLC_CODEC_FRAPS, AV_CODEC_ID_FRAPS },
134     { VLC_CODEC_TRUEMOTION2, AV_CODEC_ID_TRUEMOTION2 },
135     { VLC_CODEC_BMP, AV_CODEC_ID_BMP },
136     { VLC_CODEC_CSCD, AV_CODEC_ID_CSCD },
137     { VLC_CODEC_MMVIDEO, AV_CODEC_ID_MMVIDEO },
138     { VLC_CODEC_ZMBV, AV_CODEC_ID_ZMBV },
139     { VLC_CODEC_AVS, AV_CODEC_ID_AVS },
140     { VLC_CODEC_SMACKVIDEO, AV_CODEC_ID_SMACKVIDEO },
141     { VLC_CODEC_NUV, AV_CODEC_ID_NUV },
142     { VLC_CODEC_KMVC, AV_CODEC_ID_KMVC },
143     { VLC_CODEC_FLASHSV, AV_CODEC_ID_FLASHSV },
144     { VLC_CODEC_CAVS, AV_CODEC_ID_CAVS },
145     { VLC_CODEC_JPEG2000, AV_CODEC_ID_JPEG2000 },
146     { VLC_CODEC_VMNC, AV_CODEC_ID_VMNC },
147     { VLC_CODEC_VP5, AV_CODEC_ID_VP5 },
148     { VLC_CODEC_VP6, AV_CODEC_ID_VP6 },
149     { VLC_CODEC_VP6F, AV_CODEC_ID_VP6F },
150     { VLC_CODEC_TARGA, AV_CODEC_ID_TARGA },
151     { VLC_CODEC_DSICINVIDEO, AV_CODEC_ID_DSICINVIDEO },
152     { VLC_CODEC_TIERTEXSEQVIDEO, AV_CODEC_ID_TIERTEXSEQVIDEO },
153     { VLC_CODEC_TIFF, AV_CODEC_ID_TIFF },
154     { VLC_CODEC_GIF, AV_CODEC_ID_GIF },
155     { VLC_CODEC_DXA, AV_CODEC_ID_DXA },
156     { VLC_CODEC_DNXHD, AV_CODEC_ID_DNXHD },
157     { VLC_CODEC_THP, AV_CODEC_ID_THP },
158     { VLC_CODEC_SGI, AV_CODEC_ID_SGI },
159     { VLC_CODEC_C93, AV_CODEC_ID_C93 },
160     { VLC_CODEC_BETHSOFTVID, AV_CODEC_ID_BETHSOFTVID },
161     /* AV_CODEC_ID_PTX */
162     { VLC_CODEC_TXD, AV_CODEC_ID_TXD },
163     { VLC_CODEC_VP6A, AV_CODEC_ID_VP6A },
164     { VLC_CODEC_AMV, AV_CODEC_ID_AMV },
165     { VLC_CODEC_VB, AV_CODEC_ID_VB },
166     { VLC_CODEC_PCX, AV_CODEC_ID_PCX },
167     /* AV_CODEC_ID_SUNRAST */
168     { VLC_CODEC_INDEO4, AV_CODEC_ID_INDEO4 },
169     { VLC_CODEC_INDEO5, AV_CODEC_ID_INDEO5 },
170     { VLC_CODEC_MIMIC, AV_CODEC_ID_MIMIC },
171     { VLC_CODEC_RL2, AV_CODEC_ID_RL2 },
172     { VLC_CODEC_ESCAPE124, AV_CODEC_ID_ESCAPE124 },
173     { VLC_CODEC_DIRAC, AV_CODEC_ID_DIRAC },
174     { VLC_CODEC_BFI, AV_CODEC_ID_BFI },
175     { VLC_CODEC_CMV, AV_CODEC_ID_CMV },
176     { VLC_CODEC_MOTIONPIXELS, AV_CODEC_ID_MOTIONPIXELS },
177     { VLC_CODEC_TGV, AV_CODEC_ID_TGV },
178     { VLC_CODEC_TGQ, AV_CODEC_ID_TGQ },
179     { VLC_CODEC_TQI, AV_CODEC_ID_TQI },
180     { VLC_CODEC_AURA, AV_CODEC_ID_AURA },
181     /* AV_CODEC_ID_AURA2 */
182     /* AV_CODEC_ID_V210X */
183     { VLC_CODEC_TMV, AV_CODEC_ID_TMV },
184     { VLC_CODEC_V210, AV_CODEC_ID_V210 },
185     { VLC_CODEC_VUYA, AV_CODEC_ID_AYUV },
186     /* AV_CODEC_ID_DPX */
187     { VLC_CODEC_MAD, AV_CODEC_ID_MAD },
188     { VLC_CODEC_FRWU, AV_CODEC_ID_FRWU },
189     { VLC_CODEC_FLASHSV2, AV_CODEC_ID_FLASHSV2 },
190     /* AV_CODEC_ID_CDGRAPHICS */
191     /* AV_CODEC_ID_R210 */
192     { VLC_CODEC_ANM, AV_CODEC_ID_ANM },
193     { VLC_CODEC_BINKVIDEO, AV_CODEC_ID_BINKVIDEO },
194     /* AV_CODEC_ID_IFF_ILBM */
195     /* AV_CODEC_ID_IFF_BYTERUN1 */
196     { VLC_CODEC_KGV1, AV_CODEC_ID_KGV1 },
197     { VLC_CODEC_YOP, AV_CODEC_ID_YOP },
198     { VLC_CODEC_VP8, AV_CODEC_ID_VP8 },
199     /* AV_CODEC_ID_PICTOR */
200     /* AV_CODEC_ID_ANSI */
201     /* AV_CODEC_ID_A64_MULTI */
202     /* AV_CODEC_ID_A64_MULTI5 */
203     /* AV_CODEC_ID_R10K */
204     { VLC_CODEC_MXPEG, AV_CODEC_ID_MXPEG },
205     { VLC_CODEC_LAGARITH, AV_CODEC_ID_LAGARITH },
206     { VLC_CODEC_PRORES, AV_CODEC_ID_PRORES },
207     { VLC_CODEC_JV, AV_CODEC_ID_JV },
208     { VLC_CODEC_DFA, AV_CODEC_ID_DFA },
209     { VLC_CODEC_WMVP, AV_CODEC_ID_WMV3IMAGE },
210     { VLC_CODEC_WMVP2, AV_CODEC_ID_VC1IMAGE },
211     { VLC_CODEC_UTVIDEO, AV_CODEC_ID_UTVIDEO },
212     { VLC_CODEC_BMVVIDEO, AV_CODEC_ID_BMV_VIDEO },
213     { VLC_CODEC_VBLE, AV_CODEC_ID_VBLE },
214     { VLC_CODEC_DXTORY, AV_CODEC_ID_DXTORY },
215     /* AV_CODEC_ID_V410 */
216     /* AV_CODEC_ID_XWD */
217     { VLC_CODEC_CDXL, AV_CODEC_ID_CDXL },
218     /* AV_CODEC_ID_XBM */
219     /* AV_CODEC_ID_ZEROCODEC */
220     { VLC_CODEC_MSS1, AV_CODEC_ID_MSS1 },
221     { VLC_CODEC_MSA1, AV_CODEC_ID_MSA1 },
222     { VLC_CODEC_TSC2, AV_CODEC_ID_TSCC2 },
223     { VLC_CODEC_MTS2, AV_CODEC_ID_MTS2 },
224     { VLC_CODEC_CLLC, AV_CODEC_ID_CLLC },
225     { VLC_CODEC_MSS2, AV_CODEC_ID_MSS2 },
226     { VLC_CODEC_VP9, AV_CODEC_ID_VP9 },
227 #if LIBAVCODEC_VERSION_CHECK( 57, 26, 0, 83, 101 )
228     { VLC_CODEC_AV1, AV_CODEC_ID_AV1 },
229 #endif
230     { VLC_CODEC_ICOD, AV_CODEC_ID_AIC },
231     /* AV_CODEC_ID_ESCAPE130 */
232     { VLC_CODEC_G2M4, AV_CODEC_ID_G2M },
233     { VLC_CODEC_G2M2, AV_CODEC_ID_G2M },
234     { VLC_CODEC_G2M3, AV_CODEC_ID_G2M },
235     /* AV_CODEC_ID_WEBP */
236     { VLC_CODEC_HNM4_VIDEO, AV_CODEC_ID_HNM4_VIDEO },
237     { VLC_CODEC_HEVC, AV_CODEC_ID_HEVC },
238
239     { VLC_CODEC_FIC , AV_CODEC_ID_FIC },
240     /* AV_CODEC_ID_ALIAS_PIX */
241     /* AV_CODEC_ID_BRENDER_PIX */
242     /* AV_CODEC_ID_PAF_VIDEO */
243     /* AV_CODEC_ID_EXR */
244
245     { VLC_CODEC_VP7 , AV_CODEC_ID_VP7 },
246     /* AV_CODEC_ID_SANM */
247     /* AV_CODEC_ID_SGIRLE */
248     /* AV_CODEC_ID_MVC1 */
249     /* AV_CODEC_ID_MVC2 */
250     { VLC_CODEC_HQX, AV_CODEC_ID_HQX },
251
252     { VLC_CODEC_TDSC, AV_CODEC_ID_TDSC },
253
254     { VLC_CODEC_HQ_HQA, AV_CODEC_ID_HQ_HQA },
255
256     { VLC_CODEC_HAP, AV_CODEC_ID_HAP },
257     /* AV_CODEC_ID_DDS */
258
259     { VLC_CODEC_DXV, AV_CODEC_ID_DXV },
260
261     /* ffmpeg only: AV_CODEC_ID_BRENDER_PIX */
262     /* ffmpeg only: AV_CODEC_ID_Y41P */
263     /* ffmpeg only: AV_CODEC_ID_EXR */
264     /* ffmpeg only: AV_CODEC_ID_AVRP */
265     /* ffmpeg only: AV_CODEC_ID_012V */
266     /* ffmpeg only: AV_CODEC_ID_AVUI */
267     /* ffmpeg only: AV_CODEC_ID_TARGA_Y216 */
268     /* ffmpeg only: AV_CODEC_ID_V308 */
269     /* ffmpeg only: AV_CODEC_ID_V408 */
270     /* ffmpeg only: AV_CODEC_ID_YUV4 */
271     /* ffmpeg only: AV_CODEC_ID_SANM */
272     /* ffmpeg only: AV_CODEC_ID_PAF_VIDEO */
273     /* ffmpeg only: AV_CODEC_ID_AVRN */
274     /* ffmpeg only: AV_CODEC_ID_CPIA */
275     /* ffmpeg only: AV_CODEC_ID_XFACE */
276     /* ffmpeg only: AV_CODEC_ID_SGIRLE */
277     /* ffmpeg only: AV_CODEC_ID_MVC1 */
278     /* ffmpeg only: AV_CODEC_ID_MVC2 */
279     /* ffmpeg only: AV_CODEC_ID_SNOW */
280     /* ffmpeg only: AV_CODEC_ID_SMVJPEG */
281
282 #if LIBAVCODEC_VERSION_CHECK( 57, 999, 999, 24, 102 )
283     { VLC_CODEC_CINEFORM, AV_CODEC_ID_CFHD },
284 #endif
285
286 #if LIBAVCODEC_VERSION_CHECK( 57, 999, 999, 70, 100 )
287     { VLC_CODEC_PIXLET, AV_CODEC_ID_PIXLET },
288 #endif
289
290 #if LIBAVCODEC_VERSION_CHECK( 57, 999, 999, 71, 101 )
291     { VLC_CODEC_SPEEDHQ, AV_CODEC_ID_SPEEDHQ },
292 #endif
293
294 #if LIBAVCODEC_VERSION_CHECK( 57, 999, 999, 79, 100 )
295     { VLC_CODEC_FMVC, AV_CODEC_ID_FMVC },
296 #endif
297 };
298
299 /*
300  *  Audio Codecs
301  */
302 static const struct vlc_avcodec_fourcc audio_codecs[] =
303 {
304     /* PCM */
305     { VLC_CODEC_S16L, AV_CODEC_ID_PCM_S16LE },
306     { VLC_CODEC_S16B, AV_CODEC_ID_PCM_S16BE },
307     { VLC_CODEC_U16L, AV_CODEC_ID_PCM_U16LE },
308     { VLC_CODEC_U16B, AV_CODEC_ID_PCM_U16BE },
309     { VLC_CODEC_S8, AV_CODEC_ID_PCM_S8 },
310     { VLC_CODEC_U8, AV_CODEC_ID_PCM_U8 },
311     { VLC_CODEC_MULAW, AV_CODEC_ID_PCM_MULAW },
312     { VLC_CODEC_ALAW, AV_CODEC_ID_PCM_ALAW },
313     { VLC_CODEC_S32L, AV_CODEC_ID_PCM_S32LE },
314     { VLC_CODEC_S32B, AV_CODEC_ID_PCM_S32BE },
315     { VLC_CODEC_U32L, AV_CODEC_ID_PCM_U32LE },
316     { VLC_CODEC_U32B, AV_CODEC_ID_PCM_U32BE },
317     { VLC_CODEC_S24L, AV_CODEC_ID_PCM_S24LE },
318     { VLC_CODEC_S24B, AV_CODEC_ID_PCM_S24BE },
319     { VLC_CODEC_U24L, AV_CODEC_ID_PCM_U24LE },
320     { VLC_CODEC_U24B, AV_CODEC_ID_PCM_U24BE },
321     { VLC_CODEC_S24DAUD, AV_CODEC_ID_PCM_S24DAUD },
322     /* AV_CODEC_ID_PCM_ZORK */
323     { VLC_CODEC_S16L_PLANAR, AV_CODEC_ID_PCM_S16LE_PLANAR },
324     /* AV_CODEC_ID_PCM_DVD */
325     { VLC_CODEC_F32B, AV_CODEC_ID_PCM_F32BE },
326     { VLC_CODEC_F32L, AV_CODEC_ID_PCM_F32LE },
327     { VLC_CODEC_F64B, AV_CODEC_ID_PCM_F64BE },
328     { VLC_CODEC_F64L, AV_CODEC_ID_PCM_F64LE },
329     { VLC_CODEC_BD_LPCM, AV_CODEC_ID_PCM_BLURAY },
330     /* AV_CODEC_ID_PCM_LXF */
331     /* AV_CODEC_ID_S302M */
332     /* AV_CODEC_ID_PCM_S8_PLANAR */
333     /* AV_CODEC_ID_PCM_S24LE_PLANAR */
334     /* AV_CODEC_ID_PCM_S32LE_PLANAR */
335     /* ffmpeg only: AV_CODEC_ID_PCM_S16BE_PLANAR */
336
337     /* ADPCM */
338     { VLC_CODEC_ADPCM_IMA_QT, AV_CODEC_ID_ADPCM_IMA_QT },
339     { VLC_CODEC_ADPCM_IMA_WAV, AV_CODEC_ID_ADPCM_IMA_WAV },
340     /* AV_CODEC_ID_ADPCM_IMA_DK3 */
341     /* AV_CODEC_ID_ADPCM_IMA_DK4 */
342     { VLC_CODEC_ADPCM_IMA_WS, AV_CODEC_ID_ADPCM_IMA_WS },
343     /* AV_CODEC_ID_ADPCM_IMA_SMJPEG */
344     { VLC_CODEC_ADPCM_MS, AV_CODEC_ID_ADPCM_MS },
345     { VLC_CODEC_ADPCM_4XM, AV_CODEC_ID_ADPCM_4XM },
346     { VLC_CODEC_ADPCM_XA, AV_CODEC_ID_ADPCM_XA },
347     { VLC_CODEC_ADPCM_ADX, AV_CODEC_ID_ADPCM_ADX },
348     { VLC_CODEC_ADPCM_EA, AV_CODEC_ID_ADPCM_EA },
349     { VLC_CODEC_ADPCM_G726, AV_CODEC_ID_ADPCM_G726 },
350     { VLC_CODEC_ADPCM_CREATIVE, AV_CODEC_ID_ADPCM_CT },
351     { VLC_CODEC_ADPCM_SWF, AV_CODEC_ID_ADPCM_SWF },
352     { VLC_CODEC_ADPCM_YAMAHA, AV_CODEC_ID_ADPCM_YAMAHA },
353     { VLC_CODEC_ADPCM_SBPRO_4, AV_CODEC_ID_ADPCM_SBPRO_4 },
354     { VLC_CODEC_ADPCM_SBPRO_3, AV_CODEC_ID_ADPCM_SBPRO_3 },
355     { VLC_CODEC_ADPCM_SBPRO_2, AV_CODEC_ID_ADPCM_SBPRO_2 },
356     { VLC_CODEC_ADPCM_THP, AV_CODEC_ID_ADPCM_THP },
357     { VLC_CODEC_ADPCM_IMA_AMV, AV_CODEC_ID_ADPCM_IMA_AMV },
358     { VLC_CODEC_ADPCM_EA_R1, AV_CODEC_ID_ADPCM_EA_R1 },
359     /* AV_CODEC_ID_ADPCM_EA_R3 */
360     /* AV_CODEC_ID_ADPCM_EA_R2 */
361     { VLC_CODEC_ADPCM_IMA_EA_SEAD, AV_CODEC_ID_ADPCM_IMA_EA_SEAD },
362     /* AV_CODEC_ID_ADPCM_IMA_EA_EACS */
363     /* AV_CODEC_ID_ADPCM_EA_XAS */
364     /* AV_CODEC_ID_ADPCM_EA_MAXIS_XA */
365     /* AV_CODEC_ID_ADPCM_IMA_ISS */
366     { VLC_CODEC_ADPCM_G722, AV_CODEC_ID_ADPCM_G722 },
367     { VLC_CODEC_ADPCM_IMA_APC, AV_CODEC_ID_ADPCM_IMA_APC },
368     /* ffmpeg only: AV_CODEC_ID_VIMA */
369     /* ffmpeg only: AV_CODEC_ID_ADPCM_AFC */
370     /* ffmpeg only: AV_CODEC_ID_ADPCM_IMA_OKI */
371     /* ffmpeg only: AV_CODEC_ID_ADPCM_DTK */
372     /* ffmpeg only: AV_CODEC_ID_ADPCM_IMA_RAD */
373     /* ffmpeg only: AV_CODEC_ID_ADPCM_G726LE */
374
375     /* AMR */
376     { VLC_CODEC_AMR_NB, AV_CODEC_ID_AMR_NB },
377     { VLC_CODEC_AMR_WB, AV_CODEC_ID_AMR_WB },
378
379     /* RealAudio */
380     { VLC_CODEC_RA_144, AV_CODEC_ID_RA_144 },
381     { VLC_CODEC_RA_288, AV_CODEC_ID_RA_288 },
382
383     /* DPCM */
384     { VLC_CODEC_ROQ_DPCM, AV_CODEC_ID_ROQ_DPCM },
385     { VLC_CODEC_INTERPLAY_DPCM, AV_CODEC_ID_INTERPLAY_DPCM },
386     /* AV_CODEC_ID_XAN_DPCM */
387     /* AV_CODEC_ID_SOL_DPCM */
388
389     /* audio codecs */
390     { VLC_CODEC_MPGA, AV_CODEC_ID_MP2 },
391     { VLC_CODEC_MP2, AV_CODEC_ID_MP2 },
392     { VLC_CODEC_MP3, AV_CODEC_ID_MP3 },
393     { VLC_CODEC_MP4A, AV_CODEC_ID_AAC },
394     { VLC_CODEC_A52, AV_CODEC_ID_AC3 },
395     { VLC_CODEC_DTS, AV_CODEC_ID_DTS },
396     { VLC_CODEC_VORBIS, AV_CODEC_ID_VORBIS },
397     { VLC_CODEC_DVAUDIO, AV_CODEC_ID_DVAUDIO },
398     { VLC_CODEC_WMA1, AV_CODEC_ID_WMAV1 },
399     { VLC_CODEC_WMA2, AV_CODEC_ID_WMAV2 },
400     { VLC_CODEC_MACE3, AV_CODEC_ID_MACE3 },
401     { VLC_CODEC_MACE6, AV_CODEC_ID_MACE6 },
402     { VLC_CODEC_VMDAUDIO, AV_CODEC_ID_VMDAUDIO },
403     { VLC_CODEC_FLAC, AV_CODEC_ID_FLAC },
404     /* AV_CODEC_ID_MP3ADU */
405     /* AV_CODEC_ID_MP3ON4 */
406     { VLC_CODEC_SHORTEN, AV_CODEC_ID_SHORTEN },
407     { VLC_CODEC_ALAC, AV_CODEC_ID_ALAC },
408     /* AV_CODEC_ID_WESTWOOD_SND1 */
409     { VLC_CODEC_GSM, AV_CODEC_ID_GSM },
410     { VLC_CODEC_QDM2, AV_CODEC_ID_QDM2 },
411 #if LIBAVCODEC_VERSION_CHECK( 57, 999, 999, 71, 100 )
412     { VLC_CODEC_QDMC, AV_CODEC_ID_QDMC },
413 #endif
414     { VLC_CODEC_COOK, AV_CODEC_ID_COOK },
415     { VLC_CODEC_TRUESPEECH, AV_CODEC_ID_TRUESPEECH },
416     { VLC_CODEC_TTA, AV_CODEC_ID_TTA },
417     { VLC_CODEC_SMACKAUDIO, AV_CODEC_ID_SMACKAUDIO },
418     { VLC_CODEC_QCELP, AV_CODEC_ID_QCELP },
419     { VLC_CODEC_WAVPACK, AV_CODEC_ID_WAVPACK },
420     { VLC_CODEC_DSICINAUDIO, AV_CODEC_ID_DSICINAUDIO },
421     { VLC_CODEC_IMC, AV_CODEC_ID_IMC },
422     { VLC_CODEC_MUSEPACK7, AV_CODEC_ID_MUSEPACK7 },
423     { VLC_CODEC_MLP, AV_CODEC_ID_MLP },
424     { VLC_CODEC_GSM_MS, AV_CODEC_ID_GSM_MS },
425     { VLC_CODEC_ATRAC3, AV_CODEC_ID_ATRAC3 },
426     { VLC_CODEC_APE, AV_CODEC_ID_APE },
427     { VLC_CODEC_NELLYMOSER, AV_CODEC_ID_NELLYMOSER },
428     { VLC_CODEC_MUSEPACK8, AV_CODEC_ID_MUSEPACK8 },
429     { VLC_CODEC_SPEEX, AV_CODEC_ID_SPEEX },
430     { VLC_CODEC_WMAS, AV_CODEC_ID_WMAVOICE },
431     { VLC_CODEC_WMAP, AV_CODEC_ID_WMAPRO },
432     { VLC_CODEC_WMAL, AV_CODEC_ID_WMALOSSLESS },
433     { VLC_CODEC_ATRAC3P, AV_CODEC_ID_ATRAC3P },
434     { VLC_CODEC_EAC3, AV_CODEC_ID_EAC3 },
435     { VLC_CODEC_SIPR, AV_CODEC_ID_SIPR },
436     /* AV_CODEC_ID_MP1 */
437     { VLC_CODEC_TWINVQ, AV_CODEC_ID_TWINVQ },
438     { VLC_CODEC_TRUEHD, AV_CODEC_ID_TRUEHD },
439     { VLC_CODEC_ALS, AV_CODEC_ID_MP4ALS },
440     { VLC_CODEC_ATRAC1, AV_CODEC_ID_ATRAC1 },
441     { VLC_CODEC_BINKAUDIO_RDFT, AV_CODEC_ID_BINKAUDIO_RDFT },
442     { VLC_CODEC_BINKAUDIO_DCT, AV_CODEC_ID_BINKAUDIO_DCT },
443     { VLC_CODEC_MP4A, AV_CODEC_ID_AAC_LATM },
444     /* AV_CODEC_ID_QDMC */
445     /* AV_CODEC_ID_CELT */
446     { VLC_CODEC_G723_1, AV_CODEC_ID_G723_1 },
447     /* AV_CODEC_ID_G729 */
448     /* AV_CODEC_ID_8SVX_EXP */
449     /* AV_CODEC_ID_8SVX_FIB */
450     { VLC_CODEC_BMVAUDIO, AV_CODEC_ID_BMV_AUDIO },
451     { VLC_CODEC_RALF, AV_CODEC_ID_RALF },
452     { VLC_CODEC_INDEO_AUDIO, AV_CODEC_ID_IAC },
453     /* AV_CODEC_ID_ILBC */
454     { VLC_CODEC_OPUS, AV_CODEC_ID_OPUS },
455     /* AV_CODEC_ID_COMFORT_NOISE */
456     { VLC_CODEC_TAK, AV_CODEC_ID_TAK },
457     { VLC_CODEC_METASOUND, AV_CODEC_ID_METASOUND },
458     /* AV_CODEC_ID_PAF_AUDIO */
459     { VLC_CODEC_ON2AVC, AV_CODEC_ID_ON2AVC },
460
461     /* ffmpeg only: AV_CODEC_ID_FFWAVESYNTH */
462     /* ffmpeg only: AV_CODEC_ID_SONIC */
463     /* ffmpeg only: AV_CODEC_ID_SONIC_LS */
464     /* ffmpeg only: AV_CODEC_ID_PAF_AUDIO */
465     /* ffmpeg only: AV_CODEC_ID_EVRC */
466     /* ffmpeg only: AV_CODEC_ID_SMV */
467 };
468
469 /* Subtitle streams */
470 static const struct vlc_avcodec_fourcc spu_codecs[] =
471 {
472     { VLC_CODEC_SPU, AV_CODEC_ID_DVD_SUBTITLE },
473     { VLC_CODEC_DVBS, AV_CODEC_ID_DVB_SUBTITLE },
474     { VLC_CODEC_SUBT, AV_CODEC_ID_TEXT },
475     { VLC_CODEC_XSUB, AV_CODEC_ID_XSUB },
476     { VLC_CODEC_SSA, AV_CODEC_ID_SSA },
477     { VLC_CODEC_TX3G, AV_CODEC_ID_MOV_TEXT },
478     { VLC_CODEC_BD_PG, AV_CODEC_ID_HDMV_PGS_SUBTITLE },
479 #if LIBAVCODEC_VERSION_CHECK( 57, 999, 999, 71, 100 )
480     { VLC_CODEC_BD_TEXT, AV_CODEC_ID_HDMV_TEXT_SUBTITLE },
481 #endif
482     { VLC_CODEC_TELETEXT, AV_CODEC_ID_DVB_TELETEXT },
483     /* AV_CODEC_ID_SRT */
484     /* ffmpeg only: AV_CODEC_ID_MICRODVD */
485     /* ffmpeg only: AV_CODEC_ID_EIA_608 */
486     /* ffmpeg only: AV_CODEC_ID_JACOSUB */
487     /* ffmpeg only: AV_CODEC_ID_SAMI */
488     /* ffmpeg only: AV_CODEC_ID_REALTEXT */
489     /* ffmpeg only: AV_CODEC_ID_SUBVIEWER1 */
490     /* ffmpeg only: AV_CODEC_ID_SUBVIEWER */
491     /* ffmpeg only: AV_CODEC_ID_SUBRIP */
492     /* ffmpeg only: AV_CODEC_ID_WEBVTT */
493     /* ffmpeg only: AV_CODEC_ID_MPL2 */
494     /* ffmpeg only: AV_CODEC_ID_VPLAYER */
495     /* ffmpeg only: AV_CODEC_ID_PJS */
496     /* ffmpeg only: AV_CODEC_ID_ASS */
497 };
498
499 bool GetFfmpegCodec( enum es_format_category_e cat, vlc_fourcc_t i_fourcc,
500                      unsigned *pi_ffmpeg_codec, const char **ppsz_name )
501 {
502     const struct vlc_avcodec_fourcc *base;
503     size_t count;
504
505     switch( cat )
506     {
507         case VIDEO_ES:
508             base = video_codecs;
509             count = ARRAY_SIZE(video_codecs);
510             break;
511         case AUDIO_ES:
512             base = audio_codecs;
513             count = ARRAY_SIZE(audio_codecs);
514             break;
515         case SPU_ES:
516             base = spu_codecs;
517             count = ARRAY_SIZE(spu_codecs);
518             break;
519         default:
520             base = NULL;
521             count = 0;
522     }
523
524     i_fourcc = vlc_fourcc_GetCodec( cat, i_fourcc );
525
526     for( size_t i = 0; i < count; i++ )
527     {
528         if( base[i].i_fourcc == i_fourcc )
529         {
530             if( pi_ffmpeg_codec != NULL )
531                 *pi_ffmpeg_codec = base[i].i_codec;
532             if( ppsz_name )
533                 *ppsz_name = vlc_fourcc_GetDescription( cat, i_fourcc );
534             return true;
535         }
536     }
537     return false;
538 }
539
540 vlc_fourcc_t GetVlcFourcc( unsigned i_ffmpeg_codec )
541 {
542     for( size_t i = 0; i < ARRAY_SIZE(video_codecs); i++ )
543     {
544         if( video_codecs[i].i_codec == i_ffmpeg_codec )
545             return video_codecs[i].i_fourcc;
546     }
547     for( size_t i = 0; i < ARRAY_SIZE(audio_codecs); i++ )
548     {
549         if( audio_codecs[i].i_codec == i_ffmpeg_codec )
550             return audio_codecs[i].i_fourcc;
551     }
552     for( size_t i = 0; i < ARRAY_SIZE(spu_codecs); i++ )
553     {
554         if( spu_codecs[i].i_codec == i_ffmpeg_codec )
555             return spu_codecs[i].i_fourcc;
556     }
557     return VLC_CODEC_UNKNOWN;
558 }