]> git.sesse.net Git - ffmpeg/blob - libavformat/isom.c
change codec id if sample size field is set to 24 in stsd, fix Sony-mx5p.mov
[ffmpeg] / libavformat / isom.c
1 /*
2  * ISO Media common code
3  * Copyright (c) 2001 Fabrice Bellard.
4  * Copyright (c) 2002 Francois Revol <revol@free.fr>
5  * Copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include "avformat.h"
23 #include "riff.h"
24 #include "isom.h"
25
26 /* http://gpac.sourceforge.net/tutorial/mediatypes.htm */
27 const CodecTag ff_mov_obj_type[] = {
28     { CODEC_ID_MPEG4     ,  32 },
29     { CODEC_ID_H264      ,  33 },
30     { CODEC_ID_AAC       ,  64 },
31     { CODEC_ID_MPEG2VIDEO,  96 }, /* MPEG2 Simple */
32     { CODEC_ID_MPEG2VIDEO,  97 }, /* MPEG2 Main */
33     { CODEC_ID_MPEG2VIDEO,  98 }, /* MPEG2 SNR */
34     { CODEC_ID_MPEG2VIDEO,  99 }, /* MPEG2 Spatial */
35     { CODEC_ID_MPEG2VIDEO, 100 }, /* MPEG2 High */
36     { CODEC_ID_MPEG2VIDEO, 101 }, /* MPEG2 422 */
37     { CODEC_ID_AAC       , 102 }, /* MPEG2 AAC Main */
38     { CODEC_ID_AAC       , 103 }, /* MPEG2 AAC Low */
39     { CODEC_ID_AAC       , 104 }, /* MPEG2 AAC SSR */
40     { CODEC_ID_MP3       , 105 },
41     { CODEC_ID_MPEG1VIDEO, 106 },
42     { CODEC_ID_MP2       , 107 },
43     { CODEC_ID_MJPEG     , 108 },
44     { CODEC_ID_PCM_S16LE , 224 },
45     { CODEC_ID_VORBIS    , 221 },
46     { CODEC_ID_QCELP     , 225 },
47     { CODEC_ID_AC3       , 226 },
48     { CODEC_ID_PCM_ALAW  , 227 },
49     { CODEC_ID_PCM_MULAW , 228 },
50     { CODEC_ID_PCM_S16BE , 230 },
51     { CODEC_ID_H263      , 242 },
52     { CODEC_ID_H261      , 243 },
53     { 0, 0 },
54 };
55
56 /* map numeric codes from mdhd atom to ISO 639 */
57 /* cf. QTFileFormat.pdf p253, qtff.pdf p205 */
58 /* http://developer.apple.com/documentation/mac/Text/Text-368.html */
59 /* deprecated by putting the code as 3*5bit ascii */
60 static const char *mov_mdhd_language_map[] = {
61     /* 0-9 */
62     "eng", "fra", "ger", "ita", "dut", "sve", "spa", "dan", "por", "nor",
63     "heb", "jpn", "ara", "fin", "gre", "ice", "mlt", "tur", "hr "/*scr*/, "chi"/*ace?*/,
64     "urd", "hin", "tha", "kor", "lit", "pol", "hun", "est", "lav",  NULL,
65     "fo ",  NULL, "rus", "chi",  NULL, "iri", "alb", "ron", "ces", "slk",
66     "slv", "yid", "sr ", "mac", "bul", "ukr", "bel", "uzb", "kaz", "aze",
67     /*?*/
68     "aze", "arm", "geo", "mol", "kir", "tgk", "tuk", "mon",  NULL, "pus",
69     "kur", "kas", "snd", "tib", "nep", "san", "mar", "ben", "asm", "guj",
70     "pa ", "ori", "mal", "kan", "tam", "tel",  NULL, "bur", "khm", "lao",
71     /*                   roman? arabic? */
72     "vie", "ind", "tgl", "may", "may", "amh", "tir", "orm", "som", "swa",
73     /*==rundi?*/
74     NULL, "run",  NULL, "mlg", "epo",  NULL,  NULL,  NULL,  NULL,  NULL,
75     /* 100 */
76     NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,
77     NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,
78     NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL,  NULL, "wel", "baq",
79     "cat", "lat", "que", "grn", "aym", "tat", "uig", "dzo", "jav"
80 };
81
82 int ff_mov_iso639_to_lang(const char *lang, int mp4)
83 {
84     int i, code = 0;
85
86     /* old way, only for QT? */
87     for (i = 0; !mp4 && (i < (sizeof(mov_mdhd_language_map)/sizeof(char *))); i++) {
88         if (mov_mdhd_language_map[i] && !strcmp(lang, mov_mdhd_language_map[i]))
89             return i;
90     }
91     /* XXX:can we do that in mov too? */
92     if (!mp4)
93         return 0;
94     /* handle undefined as such */
95     if (lang[0] == '\0')
96         lang = "und";
97     /* 5bit ascii */
98     for (i = 0; i < 3; i++) {
99         unsigned char c = (unsigned char)lang[i];
100         if (c < 0x60)
101             return 0;
102         if (c > 0x60 + 0x1f)
103             return 0;
104         code <<= 5;
105         code |= (c - 0x60);
106     }
107     return code;
108 }
109
110 int ff_mov_lang_to_iso639(int code, char *to)
111 {
112     int i;
113     /* is it the mangled iso code? */
114     /* see http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt */
115     if (code > 138) {
116         for (i = 2; i >= 0; i--) {
117             to[i] = 0x60 + (code & 0x1f);
118             code >>= 5;
119         }
120         return 1;
121     }
122     /* old fashion apple lang code */
123     if (code >= (sizeof(mov_mdhd_language_map)/sizeof(char *)))
124         return 0;
125     if (!mov_mdhd_language_map[code])
126         return 0;
127     strncpy(to, mov_mdhd_language_map[code], 4);
128     return 1;
129 }