mp4-esds box分析

esds box中主要是存放Element Stream Descriptors(ESDs),该box的前四个字节为version&flag,一般为0x 00 00 00 00;
从偏移第四个字节开始,为ESDs。
ESDs中可以分为三层,每层为包含关系,分别为MP4ESDescr(0x03开始,一般7个字节),MP4DecConfigDescr(0x04开始,一般13个字节),MP4DecSpecificDescr,每层的结构都类似如下:
typedef esdsStruct{
uint8_t tag;
<不定长,最长4字节> size;
uint8_t[size] data;
}esdsStruct;

起始标签后,为data size(不包含tag和size字节数),指示该层data的字节数。
其中,MP4DecConfigDescr层的data[0] 为objectTypeIndication<http://www.mp4ra.org/object.html>(一般来说,为esds box的data[11]),用于指示codec类型,
定义如下:
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 },  
};  
MP4DecSpecificDescr层(一般来说,该层在esds box中的偏移为objectTypeIndication+13,即esds box的data[24])的data为初始化解码器的私有数据,如aac音频的头信息,mpeg4视频的vos,vo等头信息。
当objectTypeIndication为0x40时,为MPEG-4 Audio。如果想更细分format为aac还是mp3,可以读取MP4DecSpecificDescr层data[0]的前五位。

esds box分析例子:

这是一段ESDS数据
00001e7: 0000 0027 6573 6473 0000 0000 0319 0000  ...'esds........
00001f7: 0004 1140 1500 01f8 0001 2728 0000 f3e8  ...@......'(....
0000207: 0502 1388 0601 02                        .......

分析如下:
0000 0027:   :esds box长度, 长度是39
6373 6473:   :esds box type: esds
00           :Version为0
  00 0000:   :Flags为0
03           :ES_DescrTag 见14496-1 Table 1
  19         :Length Field:25
     0000:   :ES_ID: 是0
00           :00(hex) =
             :0000 0000(bits)
             :0              :steamDependenceFlag,如果为1,则有16bits的dependsOn_ES_IS
             : 0             :URL_Flag,如果为1,后边则有8bits URLlength, 和相应的URLstring(URLlength)
             :  0            :OCRstreamFlag, 如果为1,有16bits OCR_ES_id;
             :   0 0000      :streamPriority
  04         :DecoderConfigDescriptor TAG
     11      :Length Field:17
       40:   :objectTypeIndication 14496-1 Table8, 0x40是Audio ISO/IEC 14496-3
15           :15(hex) =
             :0001 0101
             :0001 01        :streamType  5是Audio Stream, 14496-1 Table9
             :       0       :upStream
             :        1      :reserved
  00 01f8:   :bufferSizeDB   504
0001 2728:   :maxBitrate  75560          // 可以获取最大码率
0000 f3e8:   :avgBitrate  62440            // 可以获取平均码率
05           :DecSpecificInfotag
  02         :Length Field:2
     1388    :14496-3 1.6
             :1388(hex)=
             :0001 0011 1000 1000(bit)
             :0001 0                     :audioObjectType 2 GASpecificConfig
             :      011 1                :samplingFrequencyIndex
             :           000 1           :channelConfiguration 1
             :                00         :cpConfig
             :                  0        :directMapping
06           :SLConfigDescrTag
  01         :Length Field:1
     02      :predefined 0x02 Reserved for use in MP4 files
一些描述如下:
ISO/IEC 14496-1 ES_Descriptor is defined as follow:
8.6.5.1 Syntax
class ES_Descriptor extends BaseDescriptor : bit(8) tag=ES_DescrTag {
bit(16) ES_ID;
bit(1) streamDependenceFlag;
bit(1) URL_Flag;
bit(1) OCRstreamFlag;
bit(5) streamPriority;
if (streamDependenceFlag)
bit(16) dependsOn_ES_ID;
if (URL_Flag) {
bit(8) URLlength;
bit(8) URLstring[URLlength];
}
if (OCRstreamFlag)
bit(16) OCR_ES_Id;
DecoderConfigDescriptor decConfigDescr;
SLConfigDescriptor slConfigDescr;
IPI_DescrPointer ipiPtr[0 .. 1];
IP_IdentificationDataSet ipIDS[0 .. 255];
IPMP_DescriptorPointer ipmpDescrPtr[0 .. 255];
LanguageDescriptor langDescr[0 .. 255];
QoS_Descriptor qosDescr[0 .. 1];
RegistrationDescriptor regDescr[0 .. 1];
ExtensionDescriptor extDescr[0 .. 255];
}
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值