2006-08-01 17:58:15 +03:00
|
|
|
/*
|
|
|
|
* ISO Media common code
|
2009-01-19 17:46:40 +02:00
|
|
|
* Copyright (c) 2001 Fabrice Bellard
|
2006-08-01 17:58:15 +03:00
|
|
|
* Copyright (c) 2002 Francois Revol <revol@free.fr>
|
|
|
|
* Copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
|
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2006-08-01 17:58:15 +03:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 18:30:46 +03:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2006-08-01 17:58:15 +03:00
|
|
|
*
|
2006-10-07 18:30:46 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2006-08-01 17:58:15 +03:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 18:30:46 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-08-01 17:58:15 +03:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "avformat.h"
|
2022-05-06 21:28:57 +02:00
|
|
|
#include "demux.h"
|
2010-05-22 19:01:32 +03:00
|
|
|
#include "internal.h"
|
2006-08-01 17:58:15 +03:00
|
|
|
#include "isom.h"
|
2010-11-23 02:51:12 +02:00
|
|
|
#include "libavcodec/mpeg4audio.h"
|
|
|
|
#include "libavcodec/mpegaudiodata.h"
|
2021-06-12 01:10:58 +02:00
|
|
|
#include "libavutil/channel_layout.h"
|
2006-08-01 17:58:15 +03:00
|
|
|
|
2007-03-24 17:10:12 +02:00
|
|
|
/* http://www.mp4ra.org */
|
2008-01-28 15:19:49 +02:00
|
|
|
/* ordered by muxing preference */
|
2007-03-24 17:24:36 +02:00
|
|
|
const AVCodecTag ff_mp4_obj_type[] = {
|
2012-08-05 12:11:04 +03:00
|
|
|
{ AV_CODEC_ID_MOV_TEXT , 0x08 },
|
|
|
|
{ AV_CODEC_ID_MPEG4 , 0x20 },
|
|
|
|
{ AV_CODEC_ID_H264 , 0x21 },
|
2014-03-03 17:53:43 +03:00
|
|
|
{ AV_CODEC_ID_HEVC , 0x23 },
|
2012-08-05 12:11:04 +03:00
|
|
|
{ AV_CODEC_ID_AAC , 0x40 },
|
|
|
|
{ AV_CODEC_ID_MP4ALS , 0x40 }, /* 14496-3 ALS */
|
2016-04-27 19:45:23 +02:00
|
|
|
{ AV_CODEC_ID_MPEG2VIDEO , 0x61 }, /* MPEG-2 Main */
|
|
|
|
{ AV_CODEC_ID_MPEG2VIDEO , 0x60 }, /* MPEG-2 Simple */
|
|
|
|
{ AV_CODEC_ID_MPEG2VIDEO , 0x62 }, /* MPEG-2 SNR */
|
|
|
|
{ AV_CODEC_ID_MPEG2VIDEO , 0x63 }, /* MPEG-2 Spatial */
|
|
|
|
{ AV_CODEC_ID_MPEG2VIDEO , 0x64 }, /* MPEG-2 High */
|
|
|
|
{ AV_CODEC_ID_MPEG2VIDEO , 0x65 }, /* MPEG-2 422 */
|
|
|
|
{ AV_CODEC_ID_AAC , 0x66 }, /* MPEG-2 AAC Main */
|
|
|
|
{ AV_CODEC_ID_AAC , 0x67 }, /* MPEG-2 AAC Low */
|
|
|
|
{ AV_CODEC_ID_AAC , 0x68 }, /* MPEG-2 AAC SSR */
|
2012-08-05 12:11:04 +03:00
|
|
|
{ AV_CODEC_ID_MP3 , 0x69 }, /* 13818-3 */
|
|
|
|
{ AV_CODEC_ID_MP2 , 0x69 }, /* 11172-3 */
|
|
|
|
{ AV_CODEC_ID_MPEG1VIDEO , 0x6A }, /* 11172-2 */
|
|
|
|
{ AV_CODEC_ID_MP3 , 0x6B }, /* 11172-3 */
|
|
|
|
{ AV_CODEC_ID_MJPEG , 0x6C }, /* 10918-1 */
|
|
|
|
{ AV_CODEC_ID_PNG , 0x6D },
|
|
|
|
{ AV_CODEC_ID_JPEG2000 , 0x6E }, /* 15444-1 */
|
|
|
|
{ AV_CODEC_ID_VC1 , 0xA3 },
|
|
|
|
{ AV_CODEC_ID_DIRAC , 0xA4 },
|
|
|
|
{ AV_CODEC_ID_AC3 , 0xA5 },
|
2014-10-07 15:57:19 +03:00
|
|
|
{ AV_CODEC_ID_EAC3 , 0xA6 },
|
2012-08-05 12:11:04 +03:00
|
|
|
{ AV_CODEC_ID_DTS , 0xA9 }, /* mp4ra.org */
|
2017-03-16 03:17:12 +02:00
|
|
|
{ AV_CODEC_ID_OPUS , 0xAD }, /* mp4ra.org */
|
2017-06-28 23:47:34 +02:00
|
|
|
{ AV_CODEC_ID_VP9 , 0xB1 }, /* mp4ra.org */
|
2016-10-20 06:28:11 +02:00
|
|
|
{ AV_CODEC_ID_FLAC , 0xC1 }, /* nonstandard, update when there is a standard value */
|
2016-04-27 19:45:23 +02:00
|
|
|
{ AV_CODEC_ID_TSCC2 , 0xD0 }, /* nonstandard, camtasia uses it */
|
2016-12-12 12:37:06 +02:00
|
|
|
{ AV_CODEC_ID_EVRC , 0xD1 }, /* nonstandard, pvAuthor uses it */
|
2016-04-27 19:45:23 +02:00
|
|
|
{ AV_CODEC_ID_VORBIS , 0xDD }, /* nonstandard, gpac uses it */
|
|
|
|
{ AV_CODEC_ID_DVD_SUBTITLE, 0xE0 }, /* nonstandard, see unsupported-embedded-subs-2.mp4 */
|
2012-08-05 12:11:04 +03:00
|
|
|
{ AV_CODEC_ID_QCELP , 0xE1 },
|
|
|
|
{ AV_CODEC_ID_MPEG4SYSTEMS, 0x01 },
|
|
|
|
{ AV_CODEC_ID_MPEG4SYSTEMS, 0x02 },
|
|
|
|
{ AV_CODEC_ID_NONE , 0 },
|
2006-08-01 17:58:15 +03:00
|
|
|
};
|
|
|
|
|
2008-01-26 22:30:03 +02:00
|
|
|
const AVCodecTag ff_codec_movsubtitle_tags[] = {
|
2012-08-05 12:11:04 +03:00
|
|
|
{ AV_CODEC_ID_MOV_TEXT, MKTAG('t', 'e', 'x', 't') },
|
|
|
|
{ AV_CODEC_ID_MOV_TEXT, MKTAG('t', 'x', '3', 'g') },
|
2012-08-07 23:45:46 +03:00
|
|
|
{ AV_CODEC_ID_EIA_608, MKTAG('c', '6', '0', '8') },
|
2012-08-05 12:11:04 +03:00
|
|
|
{ AV_CODEC_ID_NONE, 0 },
|
2008-01-26 22:30:03 +02:00
|
|
|
};
|
|
|
|
|
2018-08-27 21:57:07 +02:00
|
|
|
const AVCodecTag ff_codec_movdata_tags[] = {
|
|
|
|
{ AV_CODEC_ID_BIN_DATA, MKTAG('g', 'p', 'm', 'd') },
|
|
|
|
{ AV_CODEC_ID_NONE, 0 },
|
|
|
|
};
|
|
|
|
|
2006-08-01 17:58:15 +03:00
|
|
|
/* map numeric codes from mdhd atom to ISO 639 */
|
|
|
|
/* cf. QTFileFormat.pdf p253, qtff.pdf p205 */
|
|
|
|
/* http://developer.apple.com/documentation/mac/Text/Text-368.html */
|
2016-04-27 19:45:23 +02:00
|
|
|
/* deprecated by putting the code as 3*5 bits ASCII */
|
2010-01-31 00:05:26 +02:00
|
|
|
static const char mov_mdhd_language_map[][4] = {
|
2020-06-27 16:26:43 +02:00
|
|
|
"eng", /* 0 English */
|
|
|
|
"fra", /* 1 French */
|
|
|
|
"ger", /* 2 German */
|
|
|
|
"ita", /* 3 Italian */
|
|
|
|
"dut", /* 4 Dutch */
|
|
|
|
"sve", /* 5 Swedish */
|
|
|
|
"spa", /* 6 Spanish */
|
|
|
|
"dan", /* 7 Danish */
|
|
|
|
"por", /* 8 Portuguese */
|
|
|
|
"nor", /* 9 Norwegian */
|
|
|
|
"heb", /* 10 Hebrew */
|
|
|
|
"jpn", /* 11 Japanese */
|
|
|
|
"ara", /* 12 Arabic */
|
|
|
|
"fin", /* 13 Finnish */
|
|
|
|
"gre", /* 14 Greek */
|
|
|
|
"ice", /* 15 Icelandic */
|
|
|
|
"mlt", /* 16 Maltese */
|
|
|
|
"tur", /* 17 Turkish */
|
|
|
|
"hr ", /* 18 Croatian */
|
|
|
|
"chi", /* 19 Traditional Chinese */
|
|
|
|
"urd", /* 20 Urdu */
|
|
|
|
"hin", /* 21 Hindi */
|
|
|
|
"tha", /* 22 Thai */
|
|
|
|
"kor", /* 23 Korean */
|
|
|
|
"lit", /* 24 Lithuanian */
|
|
|
|
"pol", /* 25 Polish */
|
|
|
|
"hun", /* 26 Hungarian */
|
|
|
|
"est", /* 27 Estonian */
|
|
|
|
"lav", /* 28 Latvian */
|
|
|
|
"", /* 29 Sami */
|
|
|
|
"fo ", /* 30 Faroese */
|
|
|
|
"", /* 31 Farsi */
|
|
|
|
"rus", /* 32 Russian */
|
|
|
|
"chi", /* 33 Simplified Chinese */
|
|
|
|
"", /* 34 Flemish */
|
|
|
|
"iri", /* 35 Irish */
|
|
|
|
"alb", /* 36 Albanian */
|
|
|
|
"ron", /* 37 Romanian */
|
|
|
|
"ces", /* 38 Czech */
|
|
|
|
"slk", /* 39 Slovak */
|
|
|
|
"slv", /* 40 Slovenian */
|
|
|
|
"yid", /* 41 Yiddish */
|
|
|
|
"sr ", /* 42 Serbian */
|
|
|
|
"mac", /* 43 Macedonian */
|
|
|
|
"bul", /* 44 Bulgarian */
|
|
|
|
"ukr", /* 45 Ukrainian */
|
|
|
|
"bel", /* 46 Belarusian */
|
|
|
|
"uzb", /* 47 Uzbek */
|
|
|
|
"kaz", /* 48 Kazakh */
|
|
|
|
"aze", /* 49 Azerbaijani */
|
|
|
|
"aze", /* 50 AzerbaijanAr */
|
|
|
|
"arm", /* 51 Armenian */
|
|
|
|
"geo", /* 52 Georgian */
|
|
|
|
"mol", /* 53 Moldavian */
|
|
|
|
"kir", /* 54 Kirghiz */
|
|
|
|
"tgk", /* 55 Tajiki */
|
|
|
|
"tuk", /* 56 Turkmen */
|
|
|
|
"mon", /* 57 Mongolian */
|
|
|
|
"", /* 58 MongolianCyr */
|
|
|
|
"pus", /* 59 Pashto */
|
|
|
|
"kur", /* 60 Kurdish */
|
|
|
|
"kas", /* 61 Kashmiri */
|
|
|
|
"snd", /* 62 Sindhi */
|
|
|
|
"tib", /* 63 Tibetan */
|
|
|
|
"nep", /* 64 Nepali */
|
|
|
|
"san", /* 65 Sanskrit */
|
|
|
|
"mar", /* 66 Marathi */
|
|
|
|
"ben", /* 67 Bengali */
|
|
|
|
"asm", /* 68 Assamese */
|
|
|
|
"guj", /* 69 Gujarati */
|
|
|
|
"pa ", /* 70 Punjabi */
|
|
|
|
"ori", /* 71 Oriya */
|
|
|
|
"mal", /* 72 Malayalam */
|
|
|
|
"kan", /* 73 Kannada */
|
|
|
|
"tam", /* 74 Tamil */
|
|
|
|
"tel", /* 75 Telugu */
|
|
|
|
"", /* 76 Sinhala */
|
|
|
|
"bur", /* 77 Burmese */
|
|
|
|
"khm", /* 78 Khmer */
|
|
|
|
"lao", /* 79 Lao */
|
|
|
|
"vie", /* 80 Vietnamese */
|
|
|
|
"ind", /* 81 Indonesian */
|
|
|
|
"tgl", /* 82 Tagalog */
|
|
|
|
"may", /* 83 MalayRoman */
|
|
|
|
"may", /* 84 MalayArabic */
|
|
|
|
"amh", /* 85 Amharic */
|
|
|
|
"tir", /* 86 Galla */
|
|
|
|
"orm", /* 87 Oromo */
|
|
|
|
"som", /* 88 Somali */
|
|
|
|
"swa", /* 89 Swahili */
|
|
|
|
"", /* 90 Kinyarwanda */
|
|
|
|
"run", /* 91 Rundi */
|
|
|
|
"", /* 92 Nyanja */
|
|
|
|
"mlg", /* 93 Malagasy */
|
|
|
|
"epo", /* 94 Esperanto */
|
|
|
|
"", /* 95 */
|
|
|
|
"", /* 96 */
|
|
|
|
"", /* 97 */
|
|
|
|
"", /* 98 */
|
|
|
|
"", /* 99 */
|
|
|
|
"", /* 100 */
|
|
|
|
"", /* 101 */
|
|
|
|
"", /* 102 */
|
|
|
|
"", /* 103 */
|
|
|
|
"", /* 104 */
|
|
|
|
"", /* 105 */
|
|
|
|
"", /* 106 */
|
|
|
|
"", /* 107 */
|
|
|
|
"", /* 108 */
|
|
|
|
"", /* 109 */
|
|
|
|
"", /* 110 */
|
|
|
|
"", /* 111 */
|
|
|
|
"", /* 112 */
|
|
|
|
"", /* 113 */
|
|
|
|
"", /* 114 */
|
|
|
|
"", /* 115 */
|
|
|
|
"", /* 116 */
|
|
|
|
"", /* 117 */
|
|
|
|
"", /* 118 */
|
|
|
|
"", /* 119 */
|
|
|
|
"", /* 120 */
|
|
|
|
"", /* 121 */
|
|
|
|
"", /* 122 */
|
|
|
|
"", /* 123 */
|
|
|
|
"", /* 124 */
|
|
|
|
"", /* 125 */
|
|
|
|
"", /* 126 */
|
|
|
|
"", /* 127 */
|
|
|
|
"wel", /* 128 Welsh */
|
|
|
|
"baq", /* 129 Basque */
|
|
|
|
"cat", /* 130 Catalan */
|
|
|
|
"lat", /* 131 Latin */
|
|
|
|
"que", /* 132 Quechua */
|
|
|
|
"grn", /* 133 Guarani */
|
|
|
|
"aym", /* 134 Aymara */
|
|
|
|
"tat", /* 135 Tatar */
|
|
|
|
"uig", /* 136 Uighur */
|
|
|
|
"dzo", /* 137 Dzongkha */
|
|
|
|
"jav", /* 138 JavaneseRom */
|
2006-08-01 17:58:15 +03:00
|
|
|
};
|
|
|
|
|
2010-01-30 23:54:06 +02:00
|
|
|
int ff_mov_iso639_to_lang(const char lang[4], int mp4)
|
2006-08-01 17:58:15 +03:00
|
|
|
{
|
|
|
|
int i, code = 0;
|
|
|
|
|
|
|
|
/* old way, only for QT? */
|
2010-01-31 00:05:26 +02:00
|
|
|
for (i = 0; lang[0] && !mp4 && i < FF_ARRAY_ELEMS(mov_mdhd_language_map); i++) {
|
|
|
|
if (!strcmp(lang, mov_mdhd_language_map[i]))
|
2006-08-01 17:58:15 +03:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
/* XXX:can we do that in mov too? */
|
|
|
|
if (!mp4)
|
2009-02-26 15:11:18 +02:00
|
|
|
return -1;
|
2006-08-01 17:58:15 +03:00
|
|
|
/* handle undefined as such */
|
|
|
|
if (lang[0] == '\0')
|
|
|
|
lang = "und";
|
2016-04-27 19:45:23 +02:00
|
|
|
/* 5 bits ASCII */
|
2006-08-01 17:58:15 +03:00
|
|
|
for (i = 0; i < 3; i++) {
|
2010-01-30 23:50:47 +02:00
|
|
|
uint8_t c = lang[i];
|
|
|
|
c -= 0x60;
|
|
|
|
if (c > 0x1f)
|
2009-02-26 15:11:18 +02:00
|
|
|
return -1;
|
2006-08-01 17:58:15 +03:00
|
|
|
code <<= 5;
|
2010-01-30 23:50:47 +02:00
|
|
|
code |= c;
|
2006-08-01 17:58:15 +03:00
|
|
|
}
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2010-01-30 23:54:06 +02:00
|
|
|
int ff_mov_lang_to_iso639(unsigned code, char to[4])
|
2006-08-01 17:58:15 +03:00
|
|
|
{
|
|
|
|
int i;
|
2010-01-30 23:54:06 +02:00
|
|
|
memset(to, 0, 4);
|
2006-08-01 17:58:15 +03:00
|
|
|
/* is it the mangled iso code? */
|
|
|
|
/* see http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt */
|
2012-03-22 00:18:16 +03:00
|
|
|
if (code >= 0x400 && code != 0x7fff) {
|
2006-08-01 17:58:15 +03:00
|
|
|
for (i = 2; i >= 0; i--) {
|
|
|
|
to[i] = 0x60 + (code & 0x1f);
|
|
|
|
code >>= 5;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* old fashion apple lang code */
|
2008-10-22 00:40:24 +03:00
|
|
|
if (code >= FF_ARRAY_ELEMS(mov_mdhd_language_map))
|
2006-08-01 17:58:15 +03:00
|
|
|
return 0;
|
2010-01-31 00:05:26 +02:00
|
|
|
if (!mov_mdhd_language_map[code][0])
|
2006-08-01 17:58:15 +03:00
|
|
|
return 0;
|
2010-01-31 00:05:26 +02:00
|
|
|
memcpy(to, mov_mdhd_language_map[code], 4);
|
2006-08-01 17:58:15 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2010-11-23 02:51:12 +02:00
|
|
|
|
2011-02-20 12:04:12 +02:00
|
|
|
int ff_mp4_read_descr_len(AVIOContext *pb)
|
2010-11-23 02:51:12 +02:00
|
|
|
{
|
|
|
|
int len = 0;
|
|
|
|
int count = 4;
|
|
|
|
while (count--) {
|
2011-02-21 17:43:01 +02:00
|
|
|
int c = avio_r8(pb);
|
2010-11-23 02:51:12 +02:00
|
|
|
len = (len << 7) | (c & 0x7f);
|
|
|
|
if (!(c & 0x80))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2011-02-20 12:04:12 +02:00
|
|
|
int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag)
|
2010-11-23 02:51:12 +02:00
|
|
|
{
|
|
|
|
int len;
|
2011-02-21 17:43:01 +02:00
|
|
|
*tag = avio_r8(pb);
|
2010-11-23 02:51:12 +02:00
|
|
|
len = ff_mp4_read_descr_len(pb);
|
2016-04-27 19:45:23 +02:00
|
|
|
av_log(fc, AV_LOG_TRACE, "MPEG-4 description: tag=0x%02x len=%d\n", *tag, len);
|
2010-11-23 02:51:12 +02:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2011-08-25 02:59:30 +03:00
|
|
|
void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id)
|
|
|
|
{
|
|
|
|
int flags;
|
|
|
|
if (es_id) *es_id = avio_rb16(pb);
|
|
|
|
else avio_rb16(pb);
|
|
|
|
flags = avio_r8(pb);
|
|
|
|
if (flags & 0x80) //streamDependenceFlag
|
|
|
|
avio_rb16(pb);
|
|
|
|
if (flags & 0x40) { //URL_Flag
|
|
|
|
int len = avio_r8(pb);
|
|
|
|
avio_skip(pb, len);
|
|
|
|
}
|
|
|
|
if (flags & 0x20) //OCRstreamFlag
|
|
|
|
avio_rb16(pb);
|
|
|
|
}
|
|
|
|
|
2010-11-23 02:51:12 +02:00
|
|
|
static const AVCodecTag mp4_audio_types[] = {
|
2012-08-05 12:11:04 +03:00
|
|
|
{ AV_CODEC_ID_MP3ON4, AOT_PS }, /* old mp3on4 draft */
|
|
|
|
{ AV_CODEC_ID_MP3ON4, AOT_L1 }, /* layer 1 */
|
|
|
|
{ AV_CODEC_ID_MP3ON4, AOT_L2 }, /* layer 2 */
|
|
|
|
{ AV_CODEC_ID_MP3ON4, AOT_L3 }, /* layer 3 */
|
|
|
|
{ AV_CODEC_ID_MP4ALS, AOT_ALS }, /* MPEG-4 ALS */
|
|
|
|
{ AV_CODEC_ID_NONE, AOT_NULL },
|
2010-11-23 02:51:12 +02:00
|
|
|
};
|
|
|
|
|
2011-02-20 12:04:12 +02:00
|
|
|
int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb)
|
2010-11-23 02:51:12 +02:00
|
|
|
{
|
2014-05-21 23:48:11 +03:00
|
|
|
enum AVCodecID codec_id;
|
2010-11-23 02:51:12 +02:00
|
|
|
int len, tag;
|
2013-12-21 14:52:23 +03:00
|
|
|
int ret;
|
2011-02-21 17:43:01 +02:00
|
|
|
int object_type_id = avio_r8(pb);
|
|
|
|
avio_r8(pb); /* stream type */
|
|
|
|
avio_rb24(pb); /* buffer size db */
|
2021-04-18 15:59:35 +02:00
|
|
|
avio_rb32(pb); /* rc_max_rate */
|
2015-07-12 16:33:37 +02:00
|
|
|
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->bit_rate = avio_rb32(pb); /* avg bitrate */
|
2015-07-12 16:33:37 +02:00
|
|
|
|
2014-05-21 23:48:11 +03:00
|
|
|
codec_id= ff_codec_get_id(ff_mp4_obj_type, object_type_id);
|
|
|
|
if (codec_id)
|
2016-04-10 21:58:15 +02:00
|
|
|
st->codecpar->codec_id = codec_id;
|
2015-03-16 10:57:35 +02:00
|
|
|
av_log(fc, AV_LOG_TRACE, "esds object type id 0x%02x\n", object_type_id);
|
2010-11-23 02:51:12 +02:00
|
|
|
len = ff_mp4_read_descr(fc, pb, &tag);
|
|
|
|
if (tag == MP4DecSpecificDescrTag) {
|
2016-04-27 19:45:23 +02:00
|
|
|
av_log(fc, AV_LOG_TRACE, "Specific MPEG-4 header len=%d\n", len);
|
2019-03-28 19:29:30 +02:00
|
|
|
/* As per 14496-3:2009 9.D.2.2, No decSpecificInfo is defined
|
|
|
|
for MPEG-1 Audio or MPEG-2 Audio; MPEG-2 AAC excluded. */
|
|
|
|
if (object_type_id == 0x69 || object_type_id == 0x6b)
|
|
|
|
return 0;
|
2011-09-22 01:26:35 +03:00
|
|
|
if (!len || (uint64_t)len > (1<<30))
|
2017-11-24 22:55:05 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2016-04-14 18:21:08 +02:00
|
|
|
if ((ret = ff_get_extradata(fc, st->codecpar, pb, len)) < 0)
|
2013-12-25 18:37:42 +03:00
|
|
|
return ret;
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
if (st->codecpar->codec_id == AV_CODEC_ID_AAC) {
|
2013-12-18 21:39:05 +03:00
|
|
|
MPEG4AudioConfig cfg = {0};
|
2019-09-22 01:06:48 +02:00
|
|
|
ret = avpriv_mpeg4audio_get_config2(&cfg, st->codecpar->extradata,
|
|
|
|
st->codecpar->extradata_size, 1, fc);
|
2016-10-23 17:03:04 +02:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2017-03-31 17:14:42 +02:00
|
|
|
st->codecpar->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
|
|
|
|
st->codecpar->ch_layout.nb_channels = cfg.channels;
|
2010-11-23 02:51:12 +02:00
|
|
|
if (cfg.object_type == 29 && cfg.sampling_index < 3) // old mp3on4
|
2021-03-09 13:15:35 +02:00
|
|
|
st->codecpar->sample_rate = ff_mpa_freq_tab[cfg.sampling_index];
|
2010-11-23 02:51:12 +02:00
|
|
|
else if (cfg.ext_sample_rate)
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
st->codecpar->sample_rate = cfg.ext_sample_rate;
|
2010-11-23 02:51:12 +02:00
|
|
|
else
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
st->codecpar->sample_rate = cfg.sample_rate;
|
2015-03-16 10:57:35 +02:00
|
|
|
av_log(fc, AV_LOG_TRACE, "mp4a config channels %d obj %d ext obj %d "
|
2017-03-31 17:14:42 +02:00
|
|
|
"sample rate %d ext sample rate %d\n", cfg.channels,
|
2010-11-23 02:51:12 +02:00
|
|
|
cfg.object_type, cfg.ext_object_type,
|
|
|
|
cfg.sample_rate, cfg.ext_sample_rate);
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
if (!(st->codecpar->codec_id = ff_codec_get_id(mp4_audio_types,
|
2010-11-23 02:51:12 +02:00
|
|
|
cfg.object_type)))
|
lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.
In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.
There are multiple important problems with this approach:
- the fields in AVCodecContext are in general one of
* stream parameters
* codec options
* codec state
However, it's not clear which ones are which. It is consequently
unclear which fields are a demuxer allowed to set or a muxer allowed to
read. This leads to erratic behaviour depending on whether decoding or
encoding is being performed or not (and whether it uses the AVStream
embedded codec context).
- various synchronization issues arising from the fact that the same
context is used by several different APIs (muxers/demuxers,
parsers, bitstream filters and encoders/decoders) simultaneously, with
there being no clear rules for who can modify what and the different
processes being typically delayed with respect to each other.
- avformat_find_stream_info() making it necessary to support opening
and closing a single codec context multiple times, thus
complicating the semantics of freeing various allocated objects in the
codec context.
Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2014-06-18 21:42:52 +03:00
|
|
|
st->codecpar->codec_id = AV_CODEC_ID_AAC;
|
2010-11-23 02:51:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2011-04-28 11:45:32 +03:00
|
|
|
|
|
|
|
typedef struct MovChannelLayout {
|
|
|
|
int64_t channel_layout;
|
|
|
|
uint32_t layout_tag;
|
|
|
|
} MovChannelLayout;
|
|
|
|
|
|
|
|
static const MovChannelLayout mov_channel_layout[] = {
|
2011-10-04 08:26:50 +03:00
|
|
|
{ AV_CH_LAYOUT_MONO, (100<<16) | 1}, // kCAFChannelLayoutTag_Mono
|
|
|
|
{ AV_CH_LAYOUT_STEREO, (101<<16) | 2}, // kCAFChannelLayoutTag_Stereo
|
|
|
|
{ AV_CH_LAYOUT_STEREO, (102<<16) | 2}, // kCAFChannelLayoutTag_StereoHeadphones
|
|
|
|
{ AV_CH_LAYOUT_2_1, (131<<16) | 3}, // kCAFChannelLayoutTag_ITU_2_1
|
|
|
|
{ AV_CH_LAYOUT_QUAD, (132<<16) | 4}, // kCAFChannelLayoutTag_ITU_2_2
|
|
|
|
{ AV_CH_LAYOUT_2_2, (132<<16) | 4}, // kCAFChannelLayoutTag_ITU_2_2
|
|
|
|
{ AV_CH_LAYOUT_QUAD, (108<<16) | 4}, // kCAFChannelLayoutTag_Quadraphonic
|
|
|
|
{ AV_CH_LAYOUT_SURROUND, (113<<16) | 3}, // kCAFChannelLayoutTag_MPEG_3_0_A
|
|
|
|
{ AV_CH_LAYOUT_4POINT0, (115<<16) | 4}, // kCAFChannelLayoutTag_MPEG_4_0_A
|
|
|
|
{ AV_CH_LAYOUT_5POINT0_BACK, (117<<16) | 5}, // kCAFChannelLayoutTag_MPEG_5_0_A
|
|
|
|
{ AV_CH_LAYOUT_5POINT0, (117<<16) | 5}, // kCAFChannelLayoutTag_MPEG_5_0_A
|
|
|
|
{ AV_CH_LAYOUT_5POINT1_BACK, (121<<16) | 6}, // kCAFChannelLayoutTag_MPEG_5_1_A
|
|
|
|
{ AV_CH_LAYOUT_5POINT1, (121<<16) | 6}, // kCAFChannelLayoutTag_MPEG_5_1_A
|
|
|
|
{ AV_CH_LAYOUT_7POINT1, (128<<16) | 8}, // kCAFChannelLayoutTag_MPEG_7_1_C
|
|
|
|
{ AV_CH_LAYOUT_7POINT1_WIDE, (126<<16) | 8}, // kCAFChannelLayoutTag_MPEG_7_1_A
|
|
|
|
{ AV_CH_LAYOUT_5POINT1_BACK|AV_CH_LAYOUT_STEREO_DOWNMIX, (130<<16) | 8}, // kCAFChannelLayoutTag_SMPTE_DTV
|
|
|
|
{ AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY, (133<<16) | 3}, // kCAFChannelLayoutTag_DVD_4
|
|
|
|
{ AV_CH_LAYOUT_2_1|AV_CH_LOW_FREQUENCY, (134<<16) | 4}, // kCAFChannelLayoutTag_DVD_5
|
|
|
|
{ AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY, (135<<16) | 4}, // kCAFChannelLayoutTag_DVD_6
|
|
|
|
{ AV_CH_LAYOUT_2_2|AV_CH_LOW_FREQUENCY, (135<<16) | 4}, // kCAFChannelLayoutTag_DVD_6
|
|
|
|
{ AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY, (136<<16) | 4}, // kCAFChannelLayoutTag_DVD_10
|
|
|
|
{ AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY, (137<<16) | 5}, // kCAFChannelLayoutTag_DVD_11
|
2011-04-28 11:45:32 +03:00
|
|
|
{ 0, 0},
|
|
|
|
};
|
|
|
|
|
2011-05-17 02:47:12 +03:00
|
|
|
void ff_mov_write_chan(AVIOContext *pb, int64_t channel_layout)
|
2011-05-15 04:25:27 +03:00
|
|
|
{
|
|
|
|
const MovChannelLayout *layouts;
|
|
|
|
uint32_t layout_tag = 0;
|
|
|
|
|
|
|
|
for (layouts = mov_channel_layout; layouts->channel_layout; layouts++)
|
|
|
|
if (channel_layout == layouts->channel_layout) {
|
|
|
|
layout_tag = layouts->layout_tag;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layout_tag) {
|
2011-10-04 08:26:50 +03:00
|
|
|
avio_wb32(pb, layout_tag); // mChannelLayoutTag
|
|
|
|
avio_wb32(pb, 0); // mChannelBitmap
|
2011-05-15 04:25:27 +03:00
|
|
|
} else {
|
2011-10-04 08:26:50 +03:00
|
|
|
avio_wb32(pb, 0x10000); // kCAFChannelLayoutTag_UseChannelBitmap
|
2011-05-15 04:25:27 +03:00
|
|
|
avio_wb32(pb, channel_layout);
|
|
|
|
}
|
2011-10-04 08:26:50 +03:00
|
|
|
avio_wb32(pb, 0); // mNumberChannelDescriptions
|
2011-05-15 04:25:27 +03:00
|
|
|
}
|
2021-07-15 08:57:48 +02:00
|
|
|
|
|
|
|
static const struct MP4TrackKindValueMapping dash_role_map[] = {
|
|
|
|
{ AV_DISPOSITION_HEARING_IMPAIRED|AV_DISPOSITION_CAPTIONS,
|
|
|
|
"caption" },
|
|
|
|
{ AV_DISPOSITION_COMMENT,
|
|
|
|
"commentary" },
|
|
|
|
{ AV_DISPOSITION_VISUAL_IMPAIRED|AV_DISPOSITION_DESCRIPTIONS,
|
|
|
|
"description" },
|
|
|
|
{ AV_DISPOSITION_DUB,
|
|
|
|
"dub" },
|
|
|
|
{ AV_DISPOSITION_FORCED,
|
|
|
|
"forced-subtitle" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
const struct MP4TrackKindMapping ff_mov_track_kind_table[] = {
|
|
|
|
{ "urn:mpeg:dash:role:2011", dash_role_map },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|