esds box中主要是存放Element Stream Descriptors(ESDs),该box的前四个字节为version&flag,一般为0x 00 00 00 00;
从偏移第四个字节开始,为ESDs。
ESDs中可以分为三层,每层为包含关系,分别为MP4ESDescr,MP4DecConfigDescr,MP4DecSpecificDescr,每层的结构都类似如下:
typedef esdsStruct{
uint8_t tag;
<不定长,最长4字节> size;
uint8_t[size] data;
}esdsStruct;
各层的起始标签如下:
- #define MP4ESDescrTag 0x03
- #define MP4DecConfigDescrTag 0x04
- #define MP4DecSpecificDescrTag 0x05
起始标签后,为data size(不包含tag和size字节数),指示该层data的字节数。
其中,MP4DecConfigDescr层的data[0] 为objectTypeIndication<http://www.mp4ra.org/object.html>(一般来说,为esds box的data[11]),用于指示codec类型,定义如下:
- /* http://www.mp4ra.org */
- /* ordered by muxing preference */
- const AVCodecTag ff_mp4_obj_type[] = {
- { CODEC_ID_MOV_TEXT , 0x08 },
- { CODEC_ID_MPEG4 , 0x20 },
- { CODEC_ID_H264 , 0x21 },
- { CODEC_ID_AAC , 0x40 },
- { CODEC_ID_MP4ALS , 0x40 }, /* 14496-3 ALS */
- { CODEC_ID_MPEG2VIDEO, 0x61 }, /* MPEG2 Main */
- { CODEC_ID_MPEG2VIDEO, 0x60 }, /* MPEG2 Simple */
- { CODEC_ID_MPEG2VIDEO, 0x62 }, /* MPEG2 SNR */
- { CODEC_ID_MPEG2VIDEO, 0x63 }, /* MPEG2 Spatial */
- { CODEC_ID_MPEG2VIDEO, 0x64 }, /* MPEG2 High */
- { CODEC_ID_MPEG2VIDEO, 0x65 }, /* MPEG2 422 */
- { CODEC_ID_AAC , 0x66 }, /* MPEG2 AAC Main */
- { CODEC_ID_AAC , 0x67 }, /* MPEG2 AAC Low */
- { CODEC_ID_AAC , 0x68 }, /* MPEG2 AAC SSR */
- { CODEC_ID_MP3 , 0x69 }, /* 13818-3 */
- { CODEC_ID_MP2 , 0x69 }, /* 11172-3 */
- { CODEC_ID_MPEG1VIDEO, 0x6A }, /* 11172-2 */
- { CODEC_ID_MP3 , 0x6B }, /* 11172-3 */
- { CODEC_ID_MJPEG , 0x6C }, /* 10918-1 */
- { CODEC_ID_PNG , 0x6D },
- { CODEC_ID_JPEG2000 , 0x6E }, /* 15444-1 */
- { CODEC_ID_VC1 , 0xA3 },
- { CODEC_ID_DIRAC , 0xA4 },
- { CODEC_ID_AC3 , 0xA5 },
- { CODEC_ID_DTS , 0xA9 }, /* mp4ra.org */
- { CODEC_ID_VORBIS , 0xDD }, /* non standard, gpac uses it */
- { CODEC_ID_DVD_SUBTITLE, 0xE0 }, /* non standard, see unsupported-embedded-subs-2.mp4 */
- { CODEC_ID_QCELP , 0xE1 },
- { CODEC_ID_MPEG4SYSTEMS, 0x01 },
- { CODEC_ID_MPEG4SYSTEMS, 0x02 },
- { CODEC_ID_NONE , 0 },
- };
当objectTypeIndication为0x40时,为MPEG-4 Audio(MPEG-4 Audio generally is thought of as AAC but there is a whole framework of audio codecs that can go in MPEG-4 Audio including AAC, BSAC, ALS, CELP, and something called MP3On4),如果想更细分format为aac还是mp3,可以读取MP4DecSpecificDescr层data[0]的前五位,详细可以参考另一篇文章:
[mp4]The audio codec for mp4 atom
MP4DecSpecificDescr层(一般来说,该层在esds box中的偏移为objectTypeIndication+13,即esds box的data[24])的data为初始化解码器的私有数据,如aac音频的头信息,mpeg4视频的vos,vo等头信息。