mp4格式

下面的软件下载地址:http://download.csdn.net/source/2607382

MP4格式缩率图

ftyp :

  这是一个筐,可以装 mdat 等其他 Box 

例: 00 00 00 14 66 74 79 70 69 73 6F 6D 00 00 02 00 6D 70 34 31
  语义为: ftyp: Major brand: isom
  Minor version: 512
  Compatible brand: mp41
free|skip
 
空白 Box. 装在 ftyp 等筐里
 
例: 00 00 00 08 66 72 65
 
语意为: free: (null)

moov :

  这是一个筐,里面很丰富
 
例: 00 00 07 63 6D 6F 6F 76
 
本身属性没有。但后面全是它的内容

moov: mvhd :

  这是 moovheader.
 
例:  00 00 00 6C 6D 76 68 64 00 00 00 00 7C 25 B0 80
  7C 25 B0 80 00 00 03 E8 00 00 06 14 00 01 00 00
  01 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00
  00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00
  00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  00 00 00 00 00 00 00 00 00 00 00 03   
        

  语义:
 creation_time:2082844800       modification_time:2082844800   
 timescale:1000 //
一秒分多少份,这里 1000 表示时间单位为 1 毫秒 , 这个设置很重要
 duration:1556 rate:10000
表示 1.0 volume:100 表示最大声
 reserved:0  reserved[0]:0   reserved[1]:0   
 Matric[0]:10000  Matric[1]:0  Matric[2]:0  Matric[3]:0  Matric[4]:10000 
 Matric[5]:0
  Matric[6]:0  Matric[7]:0  Matric[8]:40000000
 Predefined[0]:0  Predefined[1]:0  Predefined[2]:0  Predefined[3]:0
 Predefined[4]:0  Predefined[5]:0  next_track_ID:3

 

moov:trak: tkhd :

  这是 track header
 
1 00 00 00 5C 74 6B 68 64 00 00 00 0F 7C 25 B0 80
  7C 25 B0 80 00 00 00 01 00 00 00 00 00 00 06 08
  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  40 00 00 00 02 40 00 00 01 E0 00 00     
        
 
语义:
 creation_time:2082844800     modification_time:2082844800   
 track_ID:1
 第一轨 index, 这个值很重要 , 直接决定了视频和音频是否能同时出现 , 如果音频和视频的 track_ID 都是 1, 则会导致播放器无法播放 .
 reserved_1:0  
 duration:1544 //
这个值对播放器很重要 , 具体时间还和 mvhdtimescale 相关 , 用来指定了时长 ,1544 个时间单位,如果是毫秒为单位,则为 1544 毫秒 ,
 volume:0
  // 这是视频轨,无音响 reserved_2[0]:0     reserved_2[1]:0        
 layer:0 //
由于我们的视频只有一层 , 所以这里总是 0
 alternate_group:0 reserved_3:0   
 Matric[0]:10000    Matric[1]:0    Matric[2]:0    Matric[3]:0  Matric[4]:10000   
 Matric[5]:0    Matric[6]:0    Matric[7]:0    Matric[8]:40000000
 width:2400000 height:1e00000 //
这两个单位都要右移 16 位才靠谱

 2 语义:
 creation_time:2082844800     modification_time:2082844800   
 track_ID:2 reserved_1:0 duration:1556 //
这个值对播放器很重要 , 用来指定了时长 , 具体时间还和 mvhdtimescale 相关
 volume:100 //
这是音频轨,最大声  reserved_2[0]:0   reserved_2[1]:0        
 layer:0 //
只对视频有意义  alternate_group:0 // 总是 0
 reserved_3:0    Matric[0]:10000    Matric[1]:0    Matric[2]:0    Matric[3]:0
 Matric[4]:10000    Matric[5]:0    Matric[6]:0    Matric[7]:0    Matric[8]:40000000
 width:0 height:0

moov:trak: mdia :

  这个 Box 没有属性,是一个筐,装在 trak

moov:trak: mdia: mdhd

 1: 视频
 creation_time:2082844800   modification_time:2082844800   
 timescale:24000 //
这个位决定了播放的速度,不过他与 duration 的相乘后还是可以对应上面的 mvhd 设置
 duration:37037
 pad:0
 Language[0]:21      Language[1]:14      Language[2]:4
 pre_defined:0
 
 
2: 声频
 creation_time:2082844800   modification_time:2082844800   
 timescale:44100 
 duration:68608
 pad:0 //
这个位无意义,是为了将后面 language 凑够 16 位之用
 Language[0]:21      Language[1]:14      Language[2]:4
 pre_defined:0

hdlr: handler
 
1: 视频
 pre_defined:0 handler_type:vide //
似乎除了 handler_type 以外,其余的属性无意义
 reserved0      reserved:0      reserved:0

 2: 声频
 pre_defined:0 handler_type:soun
 reserved:0      reserved:0      reserved:0

moov:trak: mdia: minf : vmhd

 Video media header
例:  
 graphicsmode:0 //Video
轨的合成模式,未知语义
 opcolor:0        opcolor:0        opcolor:0 //
同样未知

 

moov:trak: mdia: minf : dinf : dref

 Data referrence
 
例:
 entry_count:1 //
只有一条 Entry
 url:  //
即使有也是没内容,测试文件无论音视都没有内容

 

moov:trak: mdia: minf : stbl : stsd

stsd: Sample Description box
 
这是一个 table, 里面放有很多 entry
 
例: entry_count:1 // 视频,有一条 entry

VisualSampleEntry: stsd 里装的一条一条的视频 entry,
 
例:
 data_reference_index:1
 pre_defined[0]:0
 pre_defined[1]:0 pre_defined[2]:0
 width:576 height:480
 horizresolution:480000 vertresolution:480000 //
常数,即 72dpi
 reserved:0 frame_count:1   compressorname://

 depth:24 //
颜色深度
 pre_defined:-1

AudioSampleEntry: stsd 里装的一条一条音频 entry
 
例: reserved[0]:0            reserved[1]:0
 channelcount:2 samplesize:16
  pre_defined:0 reserved_2:0
 samplerate:ac440000 //
显然要右移 16 位才有意义

 

moov:trak: mdia: minf : stbl : stsd : mp4a

mp4a: aac box 这个 box 实际就是继承了 audio sample entry box
 reserved[0]:0            reserved[1]:0
 channelcount:2 samplesize:16
 pre_defined:0 reserved_2:0 samplerate:56220000

 

moov:trak: mdia: minf : stbl : stsd : esds

esds: 包含在 mp4a,
 length:3
 ES_ID:6400
 streamDependenceFlag:0
 URL_Flag=0  reserved=0
 streamPriority:1 streamDependenceFlag:0
 dependsOn_ES_ID:52685
 m_iData_Size:23 //data
的长度 , 算出来的
 Data[23] //
这里面有很一堆不知所云的数据 , 一直到 stts, 但这堆数据极度重要 , 直接决定了解码器能否解码 ,14496-1 里有定义
   //
实践证明 : 这组数据与采样率有关 ,44100 一组 , 22050 一组 , 48000 又是一组 , 44100 可以与 48000 共用一组

 

moov:trak: mdia: minf : stbl : stts

stts: Time to sample
 
1: 视频
 entry_count:1
 sample_count:37 //
上面已经有 duration 时间了, duration 指整个 mdatvideo 的时长,这里 37 却为 chunks 数目
 sample_delta:1001 //1001 * 37=37037 sample_delta*sample_count=duration

 2: 音频
 sentry_count:1
 sample_count:67 //
音频分了 67chunks
 sample_delta:1024 //
同上

 

moov:trak: mdia: minf : stbl : stss

stss: syn Sample box
 
1: 视频
 entry_count:1
 sample_number:1

  但音频里没有这个 box,
 
这个 Box 非常重要 , 决定了整个 mp4 文件是否可以拖拉 , 如果这个 box 只有一个 entry, 则拖拉时将 cpu 达到 100%, 如果这个 box 不存在 , 可以拖拉 , 也不会达到 100%, 但是会略等一会 , 通常做法可以搞 100.

 

moov:trak: mdia: minf : stbl : stsc

stsc: Sample To Chunk Box 这个 box 非常重要 , 指示了在某一个 chunk 开始后面的 chunks 里每 chunk 有多少个 sample, 一个 sample 就是一帧
 
1: 视频  
 entry_count:1
 first chunk: 1, sample per chunk: 1, sample description index 1

 2: 音频
 entry_count:1
 first chunk: 1, sample per chunk: 1, sample description index 1

 

moov:trak: mdia: minf : stbl : stsz

stsz: Sample Size Box, 这个 box 乃重中之重 , 指示了每个 sample 的大小
 
1: 视频
 sample size: 0         sample count: 37
 5127    855     830     2327    2742    2373    2716    2365    3061
 2170    1888    2427    2578    2218    2084    2138    2319    2586   
 2728    2322    3505    2624    1551    2725    2502    2072    1720   
 1382    2653    2177    1323    1492    1801    1765    1985    5028   
 3467
 
2: 音频
 sample size: 0         sample count: 65
 219     205     207     182     213     194     195     194     212
 188     159     179     186     189     184     184     190     188
 190     186     195     196     182     197     182     186     182
 182     185     182     193     186     184     187     175     173
 170     185     171     181     178     178     185     192     188
 187     175     167     177     182     167     173     177     175
 176     174     170     168     169     180     164     167     176    
 170
 mdat Box
中被划分为很多个 chunk, 这里指出了每个 chunk 的大小 .

 

moov:trak: mdia: minf : stbl : stco

stco: Chunk Offset Box, 这也是最重要的 box, 指示了每个 chunk 的开始位置
 
1: 视频
 entry_count:37
 0x24 0x15d3  0x1aaf  0x1f84  0x2a20  0x35aa  0x404a  0x4c53  0x5705
 0x6470  0x6da6  0x767c  0x8174  0x8d00  0x9725  0xa003  0xa9c9  0xb447 
 0xbfdc 0xcbf7  0xd5b8  0xe4c0  0xf064  0xf7da  0x103ea 0x10e70 0x117ff
 0x1200d 0x126da 0x1328b 0x13bbd 0x14247 0x14973 0x151cd 0x15a0a 0x16272
 0x17770
 
 
2: 音频
 entry_count:65
 0x142b 0x1506  0x192a  0x19f9  0x1ded  0x1ec2  0x289b  0x295e
 0x34d6  0x3eef  0x3fab  0x4ae6  0x4b99  0x5590  0x564d  0x62fa 
 0x63b2  0x6cea 0x7506  0x75be  0x7ff7  0x80b1  0x8b86  0x8c4a 
 0x95aa  0x966f  0x9f49  0xa85d 0xa913  0xb2d8  0xb391  0xbe61 
 0xbf22  0xca84  0xcb3c  0xd509  0xe369  0xe416 0xef00  0xefb9 
 0xf673  0xf728  0x1027f 0x10331 0x10db0 0x11688 0x11744 0x11eb7
 0x11f66 0x12573 0x12624 0x13137 0x131de 0x13b0c 0x140e8 0x14197
 0x1481b 0x148c9 0x1507c 0x15124 0x158b2 0x15966 0x161cb 0x17616
 0x176c6

 

moov:trak: mdia: minf : stbl : smhd

smhd: sound media header
 
:
 balance:0 reserved:0
 
暂时未知语义
 

avcC: AVC descriptor box

avcC: AVC descriptor box 非常重要 , SPS PPS 都放这 在 14496-15 定义
 
:
 configurationVersion:1  AVCProfileIndication:66
 profile_compatibility:192 AVCLevelIndication;31
 reserved_1:63  lengthSizeMinusOne:3
 reserved_2:7
 numOfSequenceParameterSets:1 numOfPictureParameterSets:1
 SPS length: 24 //
第一个 SPS 的长度 , 多个 SPS 可以继续往下
 PPS length: 4 //
第一个 PPS 的长度 , 多个 PPS 可以继续往下

 

 

aligned(8) class AVCDecoderConfigurationRecord { 

 unsigned int(8) configurationVersion = 1; 

 unsigned int(8) AVCProfileIndication; 

 unsigned int(8) profile_compatibility; 

 unsigned int(8) AVCLevelIndication;  

 bit(6) reserved = ‘111111’b;

 unsigned int(2) lengthSizeMinusOne;  

 bit(3) reserved = ‘111’b;

 unsigned int(5) numOfSequenceParameterSets; 

 for (i=0; i< numOfSequenceParameterSets;  i++) { 

  unsigned int(16) sequenceParameterSetLength ; 

  bit(8*sequenceParameterSetLength) sequenceParameterSetNALUnit; 

 } 

 unsigned int(8) numOfPictureParameterSets; 

 for (i=0; i< numOfPictureParameterSets;  i++) { 

  unsigned int(16) pictureParameterSetLength; 

  bit(8*pictureParameterSetLength) pictureParameterSetNALUnit; 

 } 

}

http://www.nhzjj.com/asp/admin/editor/newsfile/201011314552121.pdf

btrt: bit rate box

btrt: bit rate box
 bufferSizeDB:7858 //
告诉 decoder 开辟缓冲区大小 ?
 maxBitrate:413432 //
最大 Bit rate
 avgBitrate:371960 //
平均 Bit rate

 

 avc1

  class AVCSampleEntry() extends VisualSampleEntry (‘avc1’){

 AVCConfigurationBox config; 

 MPEG4BitRateBox ();      // optional 

 MPEG4ExtensionDescriptorsBox (); // optional 

}

 

 

class AVCConfigurationBox extends Box(‘avcC’) { 

 AVCDecoderConfigurationRecord() AVCConfig; 

}

 

 

class MPEG4BitRateBox extends Box(‘btrt’){

 unsigned int(32) bufferSizeDB; 

 unsigned int(32) maxBitrate; 

 unsigned int(32) avgBitrate; 

}

 

 

class MPEG4ExtensionDescriptorsBox extends Box(‘m4ds’) { 

 Descriptor Descr[0 .. 255]; 

}

 

 

 



Trouble shooting
1,
播放速度不正常 , 哪个参数可调 ?
 mdhd->timescale,
数字越大 , 则播放速度越快
 
2,
拖拉不正常 , 哪个 Box 可调 ?
 stss,
如果只有一条 entry, 则拖拉会产生 cpu 100% 的情况 . 如果没有 entry, 则拖拉会略有停顿
3,
音频 , 视频分别整合成 mp4 文件可以播放 , 但音频 , 视频都整合进 mp4 文件以后就无法播放 .
 trak->track_id,
两轨可能都用同一 ID, 则不成 . 视频为 1, 音频为 2, 则可以解决这个问题

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值