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 */
64 {
AV_CODEC_ID_FLAC , 0xC1 },
/* nonstandard, update when there is a standard value */
73 };
74
76 /* { AV_CODEC_ID_, MKTAG('I', 'V', '5', '0') }, *//* Indeo 5.0 */
77
82
100
115
118 {
AV_CODEC_ID_AVRN ,
MKTAG(
'A',
'V',
'D',
'J') },
/* MJPEG with alpha-channel (AVID JFIF meridien compressed) */
119 /* { AV_CODEC_ID_MJPEG, MKTAG('A', 'V', 'R', 'n') }, *//* MJPEG with alpha-channel (AVID ABVB/Truevision NuVista) */
122
127
129 {
AV_CODEC_ID_MPEG4,
MKTAG(
'D',
'I',
'V',
'X') },
/* OpenDiVX *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */
132
135
151
161
163
164 {
AV_CODEC_ID_HEVC,
MKTAG(
'h',
'e',
'v',
'1') },
/* HEVC/H.265 which indicates parameter sets may be in ES */
165 {
AV_CODEC_ID_HEVC,
MKTAG(
'h',
'v',
'c',
'1') },
/* HEVC/H.265 which indicates parameter sets shall not be in ES */
166
188
191
242
244
247 {
AV_CODEC_ID_GIF,
MKTAG(
'g',
'i',
'f',
' ') },
/* embedded gif files as frames (usually one "click to play movie" frame) */
250
253
264
272
274
280
283
297
306
308
310 };
311
325 {
AV_CODEC_ID_EAC3,
MKTAG(
'e',
'c',
'-',
'3') },
/* ETSI TS 102 366 Annex F (only valid in ISOBMFF) */
367 };
368
374 };
375
376 /* map numeric codes from mdhd atom to ISO 639 */
377 /* cf. QTFileFormat.pdf p253, qtff.pdf p205 */
378 /* http://developer.apple.com/documentation/mac/Text/Text-368.html */
379 /* deprecated by putting the code as 3*5 bits ASCII */
381 /* 0-9 */
382 "eng", "fra", "ger", "ita", "dut", "sve", "spa", "dan", "por", "nor",
383 "heb", "jpn", "ara", "fin", "gre", "ice", "mlt", "tur", "hr "/*scr*/, "chi"/*ace?*/,
384 "urd", "hin", "tha", "kor", "lit", "pol", "hun", "est", "lav", "",
385 "fo ", "", "rus", "chi", "", "iri", "alb", "ron", "ces", "slk",
386 "slv", "yid", "sr ", "mac", "bul", "ukr", "bel", "uzb", "kaz", "aze",
387 /*?*/
388 "aze", "arm", "geo", "mol", "kir", "tgk", "tuk", "mon", "", "pus",
389 "kur", "kas", "snd", "tib", "nep", "san", "mar", "ben", "asm", "guj",
390 "pa ", "ori", "mal", "kan", "tam", "tel", "", "bur", "khm", "lao",
391 /* roman? arabic? */
392 "vie", "ind", "tgl", "may", "may", "amh", "tir", "orm", "som", "swa",
393 /*==rundi?*/
394 "", "run", "", "mlg", "epo", "", "", "", "", "",
395 /* 100 */
396 "", "", "", "", "", "", "", "", "", "",
397 "", "", "", "", "", "", "", "", "", "",
398 "", "", "", "", "", "", "", "", "wel", "baq",
399 "cat", "lat", "que", "grn", "aym", "tat", "uig", "dzo", "jav"
400 };
401
403 {
404 int i, code = 0;
405
406 /* old way, only for QT? */
409 return i;
410 }
411 /* XXX:can we do that in mov too? */
412 if (!mp4)
413 return -1;
414 /* handle undefined as such */
415 if (lang[0] == '0円')
416 lang = "und";
417 /* 5 bits ASCII */
418 for (i = 0; i < 3; i++) {
420 c -= 0x60;
421 if (c > 0x1f)
422 return -1;
423 code <<= 5;
425 }
426 return code;
427 }
428
430 {
431 int i;
432 memset(to, 0, 4);
433 /* is it the mangled iso code? */
434 /* see http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt */
435 if (code >= 0x400 && code != 0x7fff) {
436 for (i = 2; i >= 0; i--) {
437 to[i] = 0x60 + (code & 0x1f);
438 code >>= 5;
439 }
440 return 1;
441 }
442 /* old fashion apple lang code */
444 return 0;
446 return 0;
448 return 1;
449 }
450
452 {
455 while (count--) {
457 len = (len << 7) | (c & 0x7f);
458 if (!(c & 0x80))
459 break;
460 }
462 }
463
465 {
471 }
472
474 {
479 if (flags & 0x80) //streamDependenceFlag
481 if (flags & 0x40) { //URL_Flag
484 }
485 if (flags & 0x20) //OCRstreamFlag
487 }
488
496 };
497
499 {
501 unsigned v;
503 int ret;
504 int object_type_id =
avio_r8(pb);
507
509
510 // TODO: fix this with codecpar
511 #if FF_API_LAVF_AVCTX
513 if (v < INT32_MAX)
514 st->codec->rc_max_rate = v;
516 #endif
517
519
521 if (codec_id)
527 if (!len || (uint64_t)len > (1<<30))
530 return ret;
535 if (ret < 0)
536 return ret;
542 else
551 }
552 }
553 return 0;
554 }
555
560
584 { 0, 0},
585 };
586 #if 0
588 {
590 uint32_t layout_tag;
593
594 if (size < 12)
596
598 size -= 4;
599 if (layout_tag == 0) { // kCAFChannelLayoutTag_UseChannelDescriptions
600 // Channel descriptions not implemented
601 av_log_ask_for_sample(s, "Unimplemented container channel layout.\n");
603 return 0;
604 }
605 if (layout_tag == 0x10000) { // kCAFChannelLayoutTag_UseChannelBitmap
607 size -= 4;
609 return 0;
610 }
614 break;
615 }
616 layouts++;
617 }
621
622 return 0;
623 }
624 #endif
625
627 {
629 uint32_t layout_tag = 0;
630
631 for (layouts = mov_channel_layout; layouts->
channel_layout; layouts++)
634 break;
635 }
636
637 if (layout_tag) {
638 avio_wb32(pb, layout_tag);
// mChannelLayoutTag
640 } else {
641 avio_wb32(pb, 0x10000);
// kCAFChannelLayoutTag_UseChannelBitmap
643 }
644 avio_wb32(pb, 0);
// mNumberChannelDescriptions
645 }
646
648 {
650 }
651
653 {
655 }
int ff_mov_iso639_to_lang(const char lang[4], int mp4)
static const AVCodecTag mp4_audio_types[]
#define AV_CH_LAYOUT_7POINT1
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id)
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_CH_LAYOUT_SURROUND
static const MovChannelLayout mov_channel_layout[]
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
#define AV_CH_LAYOUT_4POINT0
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
#define AV_CH_LAYOUT_STEREO
unsigned int avio_rb16(AVIOContext *s)
#define AV_CH_LAYOUT_5POINT0
mpeg audio layer common tables.
static const char mov_mdhd_language_map[][4]
const struct AVCodecTag * avformat_get_mov_audio_tags(void)
const AVCodecTag ff_codec_movvideo_tags[]
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
unsigned int avio_rb32(AVIOContext *s)
const uint16_t avpriv_mpa_freq_tab[3]
#define AV_CH_LOW_FREQUENCY
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
const struct AVCodecTag * avformat_get_mov_video_tags(void)
#define AV_CH_LAYOUT_5POINT1
int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb)
AVCodecID
Identify the syntax and semantics of the bitstream.
int ff_mp4_read_descr_len(AVIOContext *pb)
#define MP4DecSpecificDescrTag
preferred ID for decoding MPEG audio layer 1, 2 or 3
#define AV_CH_LAYOUT_QUAD
const AVCodecTag ff_mp4_obj_type[]
const AVCodecTag ff_codec_movsubtitle_tags[]
uint64_t channel_layout
Audio channel layout.
int extradata_size
Size of the extradata content in bytes.
int avio_r8(AVIOContext *s)
static const uint16_t fc[]
unsigned int avio_rb24(AVIOContext *s)
#define AV_CH_LAYOUT_STEREO_DOWNMIX
#define AV_CH_LAYOUT_5POINT1_BACK
preferred ID for MPEG-1/2 video decoding
int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st, int64_t size)
Read 'chan' tag from the input stream.
#define FF_ARRAY_ELEMS(a)
int ff_mov_lang_to_iso639(unsigned code, char to[4])
FAKE codec to indicate a MPEG-4 Systems stream (only used by libavformat)
const AVCodecTag ff_codec_movaudio_tags[]
AVIOContext * pb
I/O context.
main external API structure.
#define AV_CH_LAYOUT_5POINT0_BACK
enum MovChannelLayoutTag * layouts
#define AV_CH_LAYOUT_7POINT1_WIDE
int sample_rate
Audio only.
void ff_mov_write_chan(AVIOContext *pb, int64_t channel_layout)
int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag)
#define FF_DISABLE_DEPRECATION_WARNINGS
int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int bit_size, int sync_extension)
Parse MPEG-4 systems extradata from a raw buffer to retrieve audio configuration. ...
#define FF_ENABLE_DEPRECATION_WARNINGS
as in Berlin toast format
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
void avio_wb32(AVIOContext *s, unsigned int val)
AVCodecParameters * codecpar
Codec parameters associated with this stream.
#define AV_CH_LAYOUT_MONO
#define MKTAG(a, b, c, d)