【多媒体封装格式详解】---MP4【3】

来源:互联网 发布:2017美国加息影响知乎 编辑:程序博客网 时间:2024/06/07 02:58

2.2.2  Media Box

Box Type: ‘mdia’
mdia box 结构十分复杂。来个例子。

2.2.2.1 Media Header Box

Box Type: ‘mdhd’

[cpp] view plain copy
  1. aligned(8) class MediaHeaderBox extends FullBox(‘mdhd’, version, 0) {  
  2. if (version==1) {  
  3. unsigned int(64) creation_time;  
  4. unsigned int(64) modification_time;  
  5. unsigned int(32) timescale;  
  6. unsigned int(64) duration;  
  7. else { // version==0  
  8. unsigned int(32) creation_time;  
  9. unsigned int(32) modification_time;  
  10. unsigned int(32) timescale;  
  11. unsigned int(32) duration;  
  12. }  
  13. bit(1) pad = 0;  
  14. unsigned int(5)[3] language; // ISO-639-2/T language code  
  15. unsigned int(16) pre_defined = 0;  
  16. }  

Field

Type

Comment

box size

4

box大小

box type

4

box类型

version

1

box版本,0或1,一般为0。

creation time

4

创建时间(相对于UTC时间1904-01-01零点的秒数)

modification time

4

修改时间

time scale

4

文件媒体在1秒时间内的刻度值,可以理解为1秒长度的时间单元数

一般情况下视频的 都是90000

duration

4

该track的时间长度

language

2

媒体语言码

pre-defined

2


2.2.2.2 Handler Reference Box

Box Type: ‘hdlr’
hdlr 这个box里面,我们可以获得这个track的类型信息。
[cpp] view plain copy
  1. aligned(8) class HandlerBox extends FullBox(‘hdlr’, version = 0, 0) {  
  2. unsigned int(32) pre_defined = 0;  
  3. unsigned int(32) handler_type;  
  4. const unsigned int(32)[3] reserved = 0;  
  5. string name;  
  6. }  

Field

Type

Comment

box size

4

box大小

box type

4

box类型

version

1

box版本,0或1,一般为0。

flags

3

 

pre-defined

4

handler_type

4

‘vide’ Video track

‘soun’ Audio track

‘hint’ Hint track

reserved

12

0

name

string

字符串 track type name


例子 

 00 00 00 2168 64 6C 7200 00 00 00 00 00 00 00 ; ...!hdlr........

76 69 64 65 00 00 00 00 00 00 00 00 00 00 00 00 ; vide............

00
上面的例子 可知track 的类型是 ‘vide’ 这是个video track

2.2.2.3 Media Information Box

Box Type: ‘minf’

minf 里包含着一系列的box。里面是track有关的特征信息。
一般情况minf 包含:Media Information Header Boxes、Data Information Box(dinf)、Sample Table Box。
Media Information Header Boxes 根据类型分‘vmhd’, ‘smhd’, ’hmhd’, ‘nmhd’

2.2.2.3.1 Media Information Header Boxes

Box Types: ‘vmhd’, ‘smhd’, ’hmhd’, ‘nmhd’

Video Media Header Box(vmhd)
[cpp] view plain copy
  1. aligned(8) class VideoMediaHeaderBox  
  2. extends FullBox(‘vmhd’, version = 0, 1) {  
  3. template unsigned int(16) graphicsmode = 0; // copy, see below  
  4. template unsigned int(16)[3] opcolor = {0, 0, 0};  
  5. }  

Field

Type

Comment

box size

4

box大小

box type

4

box类型

version

1

box版本,0或1,一般为0。

flags

3

flags

graphicsmode

2

specifies a composition mode for this video track, from the following enumerated set,

which may be extended by derived specifications:

copy = 0 copy over the existing image

opcolor

2*3

is a set of 3 colour values (red, green, blue) available for use by graphics modes


例子:

00 00 00 14 76 6D 68 640000 00 01 00 00 00 00 ; ....vmhd........

00 00 00 00                                     ; ....



Sound Media Header Box(smhd)
[cpp] view plain copy
  1. aligned(8) class SoundMediaHeaderBox  
  2. extends FullBox(‘smhd’, version = 0, 0) {  
  3. template int(16) balance = 0;  
  4. const unsigned int(16) reserved = 0;  
  5. }  

Field

Type

Comment

box size

4

box大小

box type

4

box类型

version

1

box版本,0或1,一般为0。

flags

3

flags

balance

2

立体声平衡,[8.8]格式值,一般为0-1.0表示全部左声道,1.0表示全部右声道

reserved

2

0


例子:

 00 00 00 10 73 6D 68 64 00 00 00 0000 0000 00 ; ....smhd........


Hint Media Header Box(hmhd)
[cpp] view plain copy
  1. aligned(8) class HintMediaHeaderBox  
  2. extends FullBox(‘hmhd’, version = 0, 0) {  
  3. unsigned int(16) maxPDUsize;  
  4. unsigned int(16) avgPDUsize;  
  5. unsigned int(32) maxbitrate;  
  6. unsigned int(32) avgbitrate;  
  7. unsigned int(32) reserved = 0;  
  8. }  


2.2.2.3.2 Data Information Box

Box Type: ‘dinf’

dinf 里面包含的是Data Reference Box 可能的类型:‘url ‘, ‘urn ‘, ‘dref’
[cpp] view plain copy
  1. aligned(8) class DataEntryUrlBox (bit(24) flags)  
  2. extends FullBox(‘url ’, version = 0, flags) {  
  3. string location;  
  4. }  
  5. aligned(8) class DataEntryUrnBox (bit(24) flags)  
  6. extends FullBox(‘urn ’, version = 0, flags) {  
  7. string name;  
  8. string location;  
  9. }  
  10. aligned(8) class DataReferenceBox  
  11. extends FullBox(‘dref’, version = 0, 0) {  
  12. unsigned int(32) entry_count;  
  13. for (i=1; i • entry_count; i++) {  
  14. DataEntryBox(entry_version, entry_flags) data_entry;  
  15. }  
  16. }  


未完待续。。。。。
接下来要把里面的真实数据流搞出来。
原创粉丝点击