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 file is part of FFmpeg.
8 *
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
31
32 /* http://www.mp4ra.org */
33 /* ordered by muxing preference */
72 };
73
79 };
80
84 };
85
86 /* map numeric codes from mdhd atom to ISO 639 */
87 /* cf. QTFileFormat.pdf p253, qtff.pdf p205 */
88 /* http://developer.apple.com/documentation/mac/Text/Text-368.html */
89 /* deprecated by putting the code as 3*5 bits ASCII */
91 "eng", /* 0 English */
92 "fra", /* 1 French */
93 "ger", /* 2 German */
94 "ita", /* 3 Italian */
95 "dut", /* 4 Dutch */
96 "sve", /* 5 Swedish */
97 "spa", /* 6 Spanish */
98 "dan", /* 7 Danish */
99 "por", /* 8 Portuguese */
100 "nor", /* 9 Norwegian */
101 "heb", /* 10 Hebrew */
102 "jpn", /* 11 Japanese */
103 "ara", /* 12 Arabic */
104 "fin", /* 13 Finnish */
105 "gre", /* 14 Greek */
106 "ice", /* 15 Icelandic */
107 "mlt", /* 16 Maltese */
108 "tur", /* 17 Turkish */
109 "hr ", /* 18 Croatian */
110 "chi", /* 19 Traditional Chinese */
111 "urd", /* 20 Urdu */
112 "hin", /* 21 Hindi */
113 "tha", /* 22 Thai */
114 "kor", /* 23 Korean */
115 "lit", /* 24 Lithuanian */
116 "pol", /* 25 Polish */
117 "hun", /* 26 Hungarian */
118 "est", /* 27 Estonian */
119 "lav", /* 28 Latvian */
120 "smi", /* 29 Sami */
121 "fo ", /* 30 Faroese */
122 "per", /* 31 Farsi */
123 "rus", /* 32 Russian */
124 "chi", /* 33 Simplified Chinese */
125 "", /* 34 Flemish */
126 "iri", /* 35 Irish */
127 "alb", /* 36 Albanian */
128 "ron", /* 37 Romanian */
129 "ces", /* 38 Czech */
130 "slk", /* 39 Slovak */
131 "slv", /* 40 Slovenian */
132 "yid", /* 41 Yiddish */
133 "sr ", /* 42 Serbian */
134 "mac", /* 43 Macedonian */
135 "bul", /* 44 Bulgarian */
136 "ukr", /* 45 Ukrainian */
137 "bel", /* 46 Belarusian */
138 "uzb", /* 47 Uzbek */
139 "kaz", /* 48 Kazakh */
140 "aze", /* 49 Azerbaijani */
141 "aze", /* 50 AzerbaijanAr */
142 "arm", /* 51 Armenian */
143 "geo", /* 52 Georgian */
144 "mol", /* 53 Moldavian */
145 "kir", /* 54 Kirghiz */
146 "tgk", /* 55 Tajiki */
147 "tuk", /* 56 Turkmen */
148 "mon", /* 57 Mongolian */
149 "", /* 58 MongolianCyr */
150 "pus", /* 59 Pashto */
151 "kur", /* 60 Kurdish */
152 "kas", /* 61 Kashmiri */
153 "snd", /* 62 Sindhi */
154 "tib", /* 63 Tibetan */
155 "nep", /* 64 Nepali */
156 "san", /* 65 Sanskrit */
157 "mar", /* 66 Marathi */
158 "ben", /* 67 Bengali */
159 "asm", /* 68 Assamese */
160 "guj", /* 69 Gujarati */
161 "pa ", /* 70 Punjabi */
162 "ori", /* 71 Oriya */
163 "mal", /* 72 Malayalam */
164 "kan", /* 73 Kannada */
165 "tam", /* 74 Tamil */
166 "tel", /* 75 Telugu */
167 "sin", /* 76 Sinhala */
168 "bur", /* 77 Burmese */
169 "khm", /* 78 Khmer */
170 "lao", /* 79 Lao */
171 "vie", /* 80 Vietnamese */
172 "ind", /* 81 Indonesian */
173 "tgl", /* 82 Tagalog */
174 "may", /* 83 MalayRoman */
175 "may", /* 84 MalayArabic */
176 "amh", /* 85 Amharic */
177 "tir", /* 86 Galla */
178 "orm", /* 87 Oromo */
179 "som", /* 88 Somali */
180 "swa", /* 89 Swahili */
181 "kin", /* 90 Kinyarwanda */
182 "run", /* 91 Rundi */
183 "nya", /* 92 Nyanja */
184 "mlg", /* 93 Malagasy */
185 "epo", /* 94 Esperanto */
186 "", /* 95 */
187 "", /* 96 */
188 "", /* 97 */
189 "", /* 98 */
190 "", /* 99 */
191 "", /* 100 */
192 "", /* 101 */
193 "", /* 102 */
194 "", /* 103 */
195 "", /* 104 */
196 "", /* 105 */
197 "", /* 106 */
198 "", /* 107 */
199 "", /* 108 */
200 "", /* 109 */
201 "", /* 110 */
202 "", /* 111 */
203 "", /* 112 */
204 "", /* 113 */
205 "", /* 114 */
206 "", /* 115 */
207 "", /* 116 */
208 "", /* 117 */
209 "", /* 118 */
210 "", /* 119 */
211 "", /* 120 */
212 "", /* 121 */
213 "", /* 122 */
214 "", /* 123 */
215 "", /* 124 */
216 "", /* 125 */
217 "", /* 126 */
218 "", /* 127 */
219 "wel", /* 128 Welsh */
220 "baq", /* 129 Basque */
221 "cat", /* 130 Catalan */
222 "lat", /* 131 Latin */
223 "que", /* 132 Quechua */
224 "grn", /* 133 Guarani */
225 "aym", /* 134 Aymara */
226 "tat", /* 135 Tatar */
227 "uig", /* 136 Uighur */
228 "dzo", /* 137 Dzongkha */
229 "jav", /* 138 JavaneseRom */
230 };
231
233 {
235
236 /* old way, only for QT? */
240 }
241 /* XXX:can we do that in mov too? */
242 if (!mp4)
243 return -1;
244 /* handle undefined as such */
245 if (lang[0] == '0円')
246 lang = "und";
247 /* 5 bits ASCII */
248 for (
i = 0;
i < 3;
i++) {
252 return -1;
255 }
257 }
258
260 {
263 /* is it the mangled iso code? */
264 /* see http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt */
265 if (
code >= 0x400 &&
code != 0x7fff) {
266 for (
i = 2;
i >= 0;
i--) {
269 }
270 return 1;
271 }
272 /* old fashion apple lang code */
274 return 0;
276 return 0;
278 return 1;
279 }
280
282 {
284 int count = 4;
285 while (count--) {
289 break;
290 }
292 }
293
295 {
301 }
302
304 {
309 if (
flags & 0x80)
//streamDependenceFlag
311 if (
flags & 0x40) {
//URL_Flag
314 }
315 if (
flags & 0x20)
//OCRstreamFlag
317 }
318
326 };
327
329 {
333 int object_type_id =
avio_r8(pb);
337
339
347 /* As per 14496-3:2009 9.D.2.2, No decSpecificInfo is defined
348 for MPEG-1 Audio or MPEG-2 Audio; MPEG-2 AAC excluded. */
349 if (object_type_id == 0x69 || object_type_id == 0x6b)
350 return 0;
351 if (!
len || (uint64_t)
len > (1<<30))
367 else
370 "sample rate %d ext sample rate %d\n", cfg.
channels,
376 }
377 }
378 return 0;
379 }
380
385
409 { 0, 0},
410 };
411
413 {
415 uint32_t layout_tag = 0;
416
418 if (channel_layout ==
layouts->channel_layout) {
419 layout_tag =
layouts->layout_tag;
420 break;
421 }
422
423 if (layout_tag) {
424 avio_wb32(pb, layout_tag);
// mChannelLayoutTag
426 } else {
427 avio_wb32(pb, 0x10000);
// kCAFChannelLayoutTag_UseChannelBitmap
429 }
430 avio_wb32(pb, 0);
// mNumberChannelDescriptions
431 }
432
435 "caption" },
437 "commentary" },
439 "description" },
441 "dub" },
443 "forced-subtitle" },
445 };
446
450 };