22761cffa63315bbc0e8ad6f651a5dc9fd49b30d
[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     /* AV_CODEC_ID_DPX */
186     { VLC_CODEC_MAD, AV_CODEC_ID_MAD },
187     { VLC_CODEC_FRWU, AV_CODEC_ID_FRWU },
188     { VLC_CODEC_FLASHSV2, AV_CODEC_ID_FLASHSV2 },
189     /* AV_CODEC_ID_CDGRAPHICS */
190     /* AV_CODEC_ID_R210 */
191     { VLC_CODEC_ANM, AV_CODEC_ID_ANM },
192     { VLC_CODEC_BINKVIDEO, AV_CODEC_ID_BINKVIDEO },
193     /* AV_CODEC_ID_IFF_ILBM */
194     /* AV_CODEC_ID_IFF_BYTERUN1 */
195     { VLC_CODEC_KGV1, AV_CODEC_ID_KGV1 },
196     { VLC_CODEC_YOP, AV_CODEC_ID_YOP },
197     { VLC_CODEC_VP8, AV_CODEC_ID_VP8 },
198     /* AV_CODEC_ID_PICTOR */
199     /* AV_CODEC_ID_ANSI */
200     /* AV_CODEC_ID_A64_MULTI */
201     /* AV_CODEC_ID_A64_MULTI5 */
202     /* AV_CODEC_ID_R10K */
203     { VLC_CODEC_MXPEG, AV_CODEC_ID_MXPEG },
204     { VLC_CODEC_LAGARITH, AV_CODEC_ID_LAGARITH },
205     { VLC_CODEC_PRORES, AV_CODEC_ID_PRORES },
206     { VLC_CODEC_JV, AV_CODEC_ID_JV },
207     { VLC_CODEC_DFA, AV_CODEC_ID_DFA },
208     { VLC_CODEC_WMVP, AV_CODEC_ID_WMV3IMAGE },
209     { VLC_CODEC_WMVP2, AV_CODEC_ID_VC1IMAGE },
210     { VLC_CODEC_UTVIDEO, AV_CODEC_ID_UTVIDEO },
211     { VLC_CODEC_BMVVIDEO, AV_CODEC_ID_BMV_VIDEO },
212     { VLC_CODEC_VBLE, AV_CODEC_ID_VBLE },
213     { VLC_CODEC_DXTORY, AV_CODEC_ID_DXTORY },
214     /* AV_CODEC_ID_V410 */
215     /* AV_CODEC_ID_XWD */
216     { VLC_CODEC_CDXL, AV_CODEC_ID_CDXL },
217     /* AV_CODEC_ID_XBM */
218     /* AV_CODEC_ID_ZEROCODEC */
219     { VLC_CODEC_MSS1, AV_CODEC_ID_MSS1 },
220     { VLC_CODEC_MSA1, AV_CODEC_ID_MSA1 },
221     { VLC_CODEC_TSC2, AV_CODEC_ID_TSCC2 },
222     { VLC_CODEC_MTS2, AV_CODEC_ID_MTS2 },
223     { VLC_CODEC_CLLC, AV_CODEC_ID_CLLC },
224     { VLC_CODEC_MSS2, AV_CODEC_ID_MSS2 },
225     { VLC_CODEC_VP9, AV_CODEC_ID_VP9 },
226 #if LIBAVCODEC_VERSION_CHECK( 57, 26, 0, 83, 101 )
227     { VLC_CODEC_AV1, AV_CODEC_ID_AV1 },
228 #endif
229     { VLC_CODEC_ICOD, AV_CODEC_ID_AIC },
230     /* AV_CODEC_ID_ESCAPE130 */
231     { VLC_CODEC_G2M4, AV_CODEC_ID_G2M },
232     { VLC_CODEC_G2M2, AV_CODEC_ID_G2M },
233     { VLC_CODEC_G2M3, AV_CODEC_ID_G2M },
234     /* AV_CODEC_ID_WEBP */
235     { VLC_CODEC_HNM4_VIDEO, AV_CODEC_ID_HNM4_VIDEO },
236     { VLC_CODEC_HEVC, AV_CODEC_ID_HEVC },
237
238     { VLC_CODEC_FIC , AV_CODEC_ID_FIC },
239     /* AV_CODEC_ID_ALIAS_PIX */
240     /* AV_CODEC_ID_BRENDER_PIX */
241     /* AV_CODEC_ID_PAF_VIDEO */
242     /* AV_CODEC_ID_EXR */
243
244     { VLC_CODEC_VP7 , AV_CODEC_ID_VP7 },
245     /* AV_CODEC_ID_SANM */
246     /* AV_CODEC_ID_SGIRLE */
247     /* AV_CODEC_ID_MVC1 */
248     /* AV_CODEC_ID_MVC2 */
249     { VLC_CODEC_HQX, AV_CODEC_ID_HQX },
250
251     { VLC_CODEC_TDSC, AV_CODEC_ID_TDSC },
252
253     { VLC_CODEC_HQ_HQA, AV_CODEC_ID_HQ_HQA },
254
255     { VLC_CODEC_HAP, AV_CODEC_ID_HAP },
256     /* AV_CODEC_ID_DDS */
257
258     { VLC_CODEC_DXV, AV_CODEC_ID_DXV },
259
260     /* ffmpeg only: AV_CODEC_ID_BRENDER_PIX */
261     /* ffmpeg only: AV_CODEC_ID_Y41P */
262     /* ffmpeg only: AV_CODEC_ID_EXR */
263     /* ffmpeg only: AV_CODEC_ID_AVRP */
264     /* ffmpeg only: AV_CODEC_ID_012V */
265     /* ffmpeg only: AV_CODEC_ID_AVUI */
266     /* ffmpeg only: AV_CODEC_ID_AYUV */
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, 70, 100 )
283     { VLC_CODEC_PIXLET, AV_CODEC_ID_PIXLET },
284 #endif
285
286 #if LIBAVCODEC_VERSION_CHECK( 57, 999, 999, 71, 101 )
287     { VLC_CODEC_SPEEDHQ, AV_CODEC_ID_SPEEDHQ },
288 #endif
289
290 #if LIBAVCODEC_VERSION_CHECK( 57, 999, 999, 79, 100 )
291     { VLC_CODEC_FMVC, AV_CODEC_ID_FMVC },
292 #endif
293 };
294
295 /*
296  *  Audio Codecs
297  */
298 static const struct vlc_avcodec_fourcc audio_codecs[] =
299 {
300     /* PCM */
301     { VLC_CODEC_S16L, AV_CODEC_ID_PCM_S16LE },
302     { VLC_CODEC_S16B, AV_CODEC_ID_PCM_S16BE },
303     { VLC_CODEC_U16L, AV_CODEC_ID_PCM_U16LE },
304     { VLC_CODEC_U16B, AV_CODEC_ID_PCM_U16BE },
305     { VLC_CODEC_S8, AV_CODEC_ID_PCM_S8 },
306     { VLC_CODEC_U8, AV_CODEC_ID_PCM_U8 },
307     { VLC_CODEC_MULAW, AV_CODEC_ID_PCM_MULAW },
308     { VLC_CODEC_ALAW, AV_CODEC_ID_PCM_ALAW },
309     { VLC_CODEC_S32L, AV_CODEC_ID_PCM_S32LE },
310     { VLC_CODEC_S32B, AV_CODEC_ID_PCM_S32BE },
311     { VLC_CODEC_U32L, AV_CODEC_ID_PCM_U32LE },
312     { VLC_CODEC_U32B, AV_CODEC_ID_PCM_U32BE },
313     { VLC_CODEC_S24L, AV_CODEC_ID_PCM_S24LE },
314     { VLC_CODEC_S24B, AV_CODEC_ID_PCM_S24BE },
315     { VLC_CODEC_U24L, AV_CODEC_ID_PCM_U24LE },
316     { VLC_CODEC_U24B, AV_CODEC_ID_PCM_U24BE },
317     { VLC_CODEC_S24DAUD, AV_CODEC_ID_PCM_S24DAUD },
318     /* AV_CODEC_ID_PCM_ZORK */
319     { VLC_CODEC_S16L_PLANAR, AV_CODEC_ID_PCM_S16LE_PLANAR },
320     /* AV_CODEC_ID_PCM_DVD */
321     { VLC_CODEC_F32B, AV_CODEC_ID_PCM_F32BE },
322     { VLC_CODEC_F32L, AV_CODEC_ID_PCM_F32LE },
323     { VLC_CODEC_F64B, AV_CODEC_ID_PCM_F64BE },
324     { VLC_CODEC_F64L, AV_CODEC_ID_PCM_F64LE },
325     { VLC_CODEC_BD_LPCM, AV_CODEC_ID_PCM_BLURAY },
326     /* AV_CODEC_ID_PCM_LXF */
327     /* AV_CODEC_ID_S302M */
328     /* AV_CODEC_ID_PCM_S8_PLANAR */
329     /* AV_CODEC_ID_PCM_S24LE_PLANAR */
330     /* AV_CODEC_ID_PCM_S32LE_PLANAR */
331     /* ffmpeg only: AV_CODEC_ID_PCM_S16BE_PLANAR */
332
333     /* ADPCM */
334     { VLC_CODEC_ADPCM_IMA_QT, AV_CODEC_ID_ADPCM_IMA_QT },
335     { VLC_CODEC_ADPCM_IMA_WAV, AV_CODEC_ID_ADPCM_IMA_WAV },
336     /* AV_CODEC_ID_ADPCM_IMA_DK3 */
337     /* AV_CODEC_ID_ADPCM_IMA_DK4 */
338     { VLC_CODEC_ADPCM_IMA_WS, AV_CODEC_ID_ADPCM_IMA_WS },
339     /* AV_CODEC_ID_ADPCM_IMA_SMJPEG */
340     { VLC_CODEC_ADPCM_MS, AV_CODEC_ID_ADPCM_MS },
341     { VLC_CODEC_ADPCM_4XM, AV_CODEC_ID_ADPCM_4XM },
342     { VLC_CODEC_ADPCM_XA, AV_CODEC_ID_ADPCM_XA },
343     { VLC_CODEC_ADPCM_ADX, AV_CODEC_ID_ADPCM_ADX },
344     { VLC_CODEC_ADPCM_EA, AV_CODEC_ID_ADPCM_EA },
345     { VLC_CODEC_ADPCM_G726, AV_CODEC_ID_ADPCM_G726 },
346     { VLC_CODEC_ADPCM_CREATIVE, AV_CODEC_ID_ADPCM_CT },
347     { VLC_CODEC_ADPCM_SWF, AV_CODEC_ID_ADPCM_SWF },
348     { VLC_CODEC_ADPCM_YAMAHA, AV_CODEC_ID_ADPCM_YAMAHA },
349     { VLC_CODEC_ADPCM_SBPRO_4, AV_CODEC_ID_ADPCM_SBPRO_4 },
350     { VLC_CODEC_ADPCM_SBPRO_3, AV_CODEC_ID_ADPCM_SBPRO_3 },
351     { VLC_CODEC_ADPCM_SBPRO_2, AV_CODEC_ID_ADPCM_SBPRO_2 },
352     { VLC_CODEC_ADPCM_THP, AV_CODEC_ID_ADPCM_THP },
353     { VLC_CODEC_ADPCM_IMA_AMV, AV_CODEC_ID_ADPCM_IMA_AMV },
354     { VLC_CODEC_ADPCM_EA_R1, AV_CODEC_ID_ADPCM_EA_R1 },
355     /* AV_CODEC_ID_ADPCM_EA_R3 */
356     /* AV_CODEC_ID_ADPCM_EA_R2 */
357     { VLC_CODEC_ADPCM_IMA_EA_SEAD, AV_CODEC_ID_ADPCM_IMA_EA_SEAD },
358     /* AV_CODEC_ID_ADPCM_IMA_EA_EACS */
359     /* AV_CODEC_ID_ADPCM_EA_XAS */
360     /* AV_CODEC_ID_ADPCM_EA_MAXIS_XA */
361     /* AV_CODEC_ID_ADPCM_IMA_ISS */
362     { VLC_CODEC_ADPCM_G722, AV_CODEC_ID_ADPCM_G722 },
363     { VLC_CODEC_ADPCM_IMA_APC, AV_CODEC_ID_ADPCM_IMA_APC },
364     /* ffmpeg only: AV_CODEC_ID_VIMA */
365     /* ffmpeg only: AV_CODEC_ID_ADPCM_AFC */
366     /* ffmpeg only: AV_CODEC_ID_ADPCM_IMA_OKI */
367     /* ffmpeg only: AV_CODEC_ID_ADPCM_DTK */
368     /* ffmpeg only: AV_CODEC_ID_ADPCM_IMA_RAD */
369     /* ffmpeg only: AV_CODEC_ID_ADPCM_G726LE */
370
371     /* AMR */
372     { VLC_CODEC_AMR_NB, AV_CODEC_ID_AMR_NB },
373     { VLC_CODEC_AMR_WB, AV_CODEC_ID_AMR_WB },
374
375     /* RealAudio */
376     { VLC_CODEC_RA_144, AV_CODEC_ID_RA_144 },
377     { VLC_CODEC_RA_288, AV_CODEC_ID_RA_288 },
378
379     /* DPCM */
380     { VLC_CODEC_ROQ_DPCM, AV_CODEC_ID_ROQ_DPCM },
381     { VLC_CODEC_INTERPLAY_DPCM, AV_CODEC_ID_INTERPLAY_DPCM },
382     /* AV_CODEC_ID_XAN_DPCM */
383     /* AV_CODEC_ID_SOL_DPCM */
384
385     /* audio codecs */
386     { VLC_CODEC_MPGA, AV_CODEC_ID_MP2 },
387     { VLC_CODEC_MP2, AV_CODEC_ID_MP2 },
388     { VLC_CODEC_MP3, AV_CODEC_ID_MP3 },
389     { VLC_CODEC_MP4A, AV_CODEC_ID_AAC },
390     { VLC_CODEC_A52, AV_CODEC_ID_AC3 },
391     { VLC_CODEC_DTS, AV_CODEC_ID_DTS },
392     { VLC_CODEC_VORBIS, AV_CODEC_ID_VORBIS },
393     { VLC_CODEC_DVAUDIO, AV_CODEC_ID_DVAUDIO },
394     { VLC_CODEC_WMA1, AV_CODEC_ID_WMAV1 },
395     { VLC_CODEC_WMA2, AV_CODEC_ID_WMAV2 },
396     { VLC_CODEC_MACE3, AV_CODEC_ID_MACE3 },
397     { VLC_CODEC_MACE6, AV_CODEC_ID_MACE6 },
398     { VLC_CODEC_VMDAUDIO, AV_CODEC_ID_VMDAUDIO },
399     { VLC_CODEC_FLAC, AV_CODEC_ID_FLAC },
400     /* AV_CODEC_ID_MP3ADU */
401     /* AV_CODEC_ID_MP3ON4 */
402     { VLC_CODEC_SHORTEN, AV_CODEC_ID_SHORTEN },
403     { VLC_CODEC_ALAC, AV_CODEC_ID_ALAC },
404     /* AV_CODEC_ID_WESTWOOD_SND1 */
405     { VLC_CODEC_GSM, AV_CODEC_ID_GSM },
406     { VLC_CODEC_QDM2, AV_CODEC_ID_QDM2 },
407 #if LIBAVCODEC_VERSION_CHECK( 57, 999, 999, 71, 100 )
408     { VLC_CODEC_QDMC, AV_CODEC_ID_QDMC },
409 #endif
410     { VLC_CODEC_COOK, AV_CODEC_ID_COOK },
411     { VLC_CODEC_TRUESPEECH, AV_CODEC_ID_TRUESPEECH },
412     { VLC_CODEC_TTA, AV_CODEC_ID_TTA },
413     { VLC_CODEC_SMACKAUDIO, AV_CODEC_ID_SMACKAUDIO },
414     { VLC_CODEC_QCELP, AV_CODEC_ID_QCELP },
415     { VLC_CODEC_WAVPACK, AV_CODEC_ID_WAVPACK },
416     { VLC_CODEC_DSICINAUDIO, AV_CODEC_ID_DSICINAUDIO },
417     { VLC_CODEC_IMC, AV_CODEC_ID_IMC },
418     { VLC_CODEC_MUSEPACK7, AV_CODEC_ID_MUSEPACK7 },
419     { VLC_CODEC_MLP, AV_CODEC_ID_MLP },
420     { VLC_CODEC_GSM_MS, AV_CODEC_ID_GSM_MS },
421     { VLC_CODEC_ATRAC3, AV_CODEC_ID_ATRAC3 },
422     { VLC_CODEC_APE, AV_CODEC_ID_APE },
423     { VLC_CODEC_NELLYMOSER, AV_CODEC_ID_NELLYMOSER },
424     { VLC_CODEC_MUSEPACK8, AV_CODEC_ID_MUSEPACK8 },
425     { VLC_CODEC_SPEEX, AV_CODEC_ID_SPEEX },
426     { VLC_CODEC_WMAS, AV_CODEC_ID_WMAVOICE },
427     { VLC_CODEC_WMAP, AV_CODEC_ID_WMAPRO },
428     { VLC_CODEC_WMAL, AV_CODEC_ID_WMALOSSLESS },
429     { VLC_CODEC_ATRAC3P, AV_CODEC_ID_ATRAC3P },
430     { VLC_CODEC_EAC3, AV_CODEC_ID_EAC3 },
431     { VLC_CODEC_SIPR, AV_CODEC_ID_SIPR },
432     /* AV_CODEC_ID_MP1 */
433     { VLC_CODEC_TWINVQ, AV_CODEC_ID_TWINVQ },
434     { VLC_CODEC_TRUEHD, AV_CODEC_ID_TRUEHD },
435     { VLC_CODEC_ALS, AV_CODEC_ID_MP4ALS },
436     { VLC_CODEC_ATRAC1, AV_CODEC_ID_ATRAC1 },
437     { VLC_CODEC_BINKAUDIO_RDFT, AV_CODEC_ID_BINKAUDIO_RDFT },
438     { VLC_CODEC_BINKAUDIO_DCT, AV_CODEC_ID_BINKAUDIO_DCT },
439     { VLC_CODEC_MP4A, AV_CODEC_ID_AAC_LATM },
440     /* AV_CODEC_ID_QDMC */
441     /* AV_CODEC_ID_CELT */
442     { VLC_CODEC_G723_1, AV_CODEC_ID_G723_1 },
443     /* AV_CODEC_ID_G729 */
444     /* AV_CODEC_ID_8SVX_EXP */
445     /* AV_CODEC_ID_8SVX_FIB */
446     { VLC_CODEC_BMVAUDIO, AV_CODEC_ID_BMV_AUDIO },
447     { VLC_CODEC_RALF, AV_CODEC_ID_RALF },
448     { VLC_CODEC_INDEO_AUDIO, AV_CODEC_ID_IAC },
449     /* AV_CODEC_ID_ILBC */
450     { VLC_CODEC_OPUS, AV_CODEC_ID_OPUS },
451     /* AV_CODEC_ID_COMFORT_NOISE */
452     { VLC_CODEC_TAK, AV_CODEC_ID_TAK },
453     { VLC_CODEC_METASOUND, AV_CODEC_ID_METASOUND },
454     /* AV_CODEC_ID_PAF_AUDIO */
455     { VLC_CODEC_ON2AVC, AV_CODEC_ID_ON2AVC },
456
457     /* ffmpeg only: AV_CODEC_ID_FFWAVESYNTH */
458     /* ffmpeg only: AV_CODEC_ID_SONIC */
459     /* ffmpeg only: AV_CODEC_ID_SONIC_LS */
460     /* ffmpeg only: AV_CODEC_ID_PAF_AUDIO */
461     /* ffmpeg only: AV_CODEC_ID_EVRC */
462     /* ffmpeg only: AV_CODEC_ID_SMV */
463 };
464
465 /* Subtitle streams */
466 static const struct vlc_avcodec_fourcc spu_codecs[] =
467 {
468     { VLC_CODEC_SPU, AV_CODEC_ID_DVD_SUBTITLE },
469     { VLC_CODEC_DVBS, AV_CODEC_ID_DVB_SUBTITLE },
470     { VLC_CODEC_SUBT, AV_CODEC_ID_TEXT },
471     { VLC_CODEC_XSUB, AV_CODEC_ID_XSUB },
472     { VLC_CODEC_SSA, AV_CODEC_ID_SSA },
473     /* AV_CODEC_ID_MOV_TEXT */
474     { VLC_CODEC_BD_PG, AV_CODEC_ID_HDMV_PGS_SUBTITLE },
475 #if LIBAVCODEC_VERSION_CHECK( 57, 999, 999, 71, 100 )
476     { VLC_CODEC_BD_TEXT, AV_CODEC_ID_HDMV_TEXT_SUBTITLE },
477 #endif
478     { VLC_CODEC_TELETEXT, AV_CODEC_ID_DVB_TELETEXT },
479     /* AV_CODEC_ID_SRT */
480     /* ffmpeg only: AV_CODEC_ID_MICRODVD */
481     /* ffmpeg only: AV_CODEC_ID_EIA_608 */
482     /* ffmpeg only: AV_CODEC_ID_JACOSUB */
483     /* ffmpeg only: AV_CODEC_ID_SAMI */
484     /* ffmpeg only: AV_CODEC_ID_REALTEXT */
485     /* ffmpeg only: AV_CODEC_ID_SUBVIEWER1 */
486     /* ffmpeg only: AV_CODEC_ID_SUBVIEWER */
487     /* ffmpeg only: AV_CODEC_ID_SUBRIP */
488     /* ffmpeg only: AV_CODEC_ID_WEBVTT */
489     /* ffmpeg only: AV_CODEC_ID_MPL2 */
490     /* ffmpeg only: AV_CODEC_ID_VPLAYER */
491     /* ffmpeg only: AV_CODEC_ID_PJS */
492     /* ffmpeg only: AV_CODEC_ID_ASS */
493 };
494
495 bool GetFfmpegCodec( enum es_format_category_e cat, vlc_fourcc_t i_fourcc,
496                      unsigned *pi_ffmpeg_codec, const char **ppsz_name )
497 {
498     const struct vlc_avcodec_fourcc *base;
499     size_t count;
500
501     switch( cat )
502     {
503         case VIDEO_ES:
504             base = video_codecs;
505             count = ARRAY_SIZE(video_codecs);
506             break;
507         case AUDIO_ES:
508             base = audio_codecs;
509             count = ARRAY_SIZE(audio_codecs);
510             break;
511         case SPU_ES:
512             base = spu_codecs;
513             count = ARRAY_SIZE(spu_codecs);
514             break;
515         default:
516             base = NULL;
517             count = 0;
518     }
519
520     i_fourcc = vlc_fourcc_GetCodec( cat, i_fourcc );
521
522     for( size_t i = 0; i < count; i++ )
523     {
524         if( base[i].i_fourcc == i_fourcc )
525         {
526             if( pi_ffmpeg_codec != NULL )
527                 *pi_ffmpeg_codec = base[i].i_codec;
528             if( ppsz_name )
529                 *ppsz_name = vlc_fourcc_GetDescription( cat, i_fourcc );
530             return true;
531         }
532     }
533     return false;
534 }
535
536 vlc_fourcc_t GetVlcFourcc( unsigned i_ffmpeg_codec )
537 {
538     for( size_t i = 0; i < ARRAY_SIZE(video_codecs); i++ )
539     {
540         if( video_codecs[i].i_codec == i_ffmpeg_codec )
541             return video_codecs[i].i_fourcc;
542     }
543     for( size_t i = 0; i < ARRAY_SIZE(audio_codecs); i++ )
544     {
545         if( audio_codecs[i].i_codec == i_ffmpeg_codec )
546             return audio_codecs[i].i_fourcc;
547     }
548     for( size_t i = 0; i < ARRAY_SIZE(spu_codecs); i++ )
549     {
550         if( spu_codecs[i].i_codec == i_ffmpeg_codec )
551             return spu_codecs[i].i_fourcc;
552     }
553     return VLC_CODEC_UNKNOWN;
554 }