MP4
https://www.mpeg.org/standards/MPEG-4/14/
MPEG-4 Part 14 MP4 File Format
MP4 标准定义的是一个多媒体容器格式 (Container Format)。你可以把它想象成一个数字包装盒,它的标准规定了如何将不同类型的媒体数据有序地打包在一起,以便于存储、传输和播放。
MP4 格式的核心是一种被称为 Box(盒子) 的数据结构。MP4 文件本质上就是由无数个嵌套的 Box 组成的。以下是几个至关重要的基础概念:
- Box 的基础结构
每个 Box 均由两部分组成:Header(头部) 和 Data(数据体)。
- Header(头部): 记录了当前 Box 的基本属性,主要包含两个字段:
- Size(大小): 标明整个 Box 的长度。
- 特殊情况 1: 当
size = 0时,表示这是该文件中的最后一个 Box。 - 特殊情况 2: 当
size = 1时,表示 Box 的长度超出了常规 32 位数值的表示范围,此时会在后面紧跟一个 64 位的largesize字段来记录真实长度。
- 特殊情况 1: 当
- Type(类型): 标明该 Box 的功能或分类(通常由 4 个字符组成,如
moov,mdat)。- 特殊情况: 当
type = uuid时,说明该 Box 包含的是用户自定义的扩展数据类型。
- 特殊情况: 当
- Size(大小): 标明整个 Box 的长度。
- Data(数据体): Box 中承载的实际内容。它的形式非常灵活:
- 可以是纯粹的媒体流或二进制数据。
- 也可以包含更多的子 Box。
- Container Box (容器盒子)
当一个 Box 的 Data 部分不是纯数据,而是由一系列嵌套的子 Box 组成时,这种特殊的 Box 就被称为 Container Box(容器盒子)。这正是 MP4 能够形成复杂树状结构的基础。
- FullBox (扩展盒子)
FullBox 是标准 Box 的升级版。它在基础的 Header 结构中,额外增加了两个控制字段,通常用于需要版本控制或特殊标记的 Box 中:
- Version(版本): 占 8 位大小,用于标记 Box 版本的迭代。
- Flags(标志): 占 24 位大小,用于记录某些特定的状态或配置标志。
jax@MacbookPro FFmpeg % mp4dump ./big-buck-bunny-1080p-30sec.mp4
[ftyp] size=8+24
major_brand = isom
minor_version = 200
compatible_brand = isom
compatible_brand = iso2
compatible_brand = avc1
compatible_brand = mp41
[free] size=8+0
[mdat] size=8+22698704
[moov] size=8+19749
[mvhd] size=12+96
timescale = 1000
duration = 30022
duration(ms) = 30022
[trak] size=8+9723
[tkhd] size=12+80, flags=3
enabled = 1
id = 1
duration = 30000
width = 1920.000000
height = 1080.000000
[edts] size=8+28
[elst] size=12+16
entry_count = 1
entry/segment duration = 30000
entry/media time = 1024
entry/media rate = 1
[mdia] size=8+9587
[mdhd] size=12+20
timescale = 12288
duration = 368640
duration(ms) = 30000
language = und
[hdlr] size=12+33
handler_type = vide
handler_name = VideoHandler
[minf] size=8+9502
[vmhd] size=12+8, flags=1
graphics_mode = 0
op_color = 0000,0000,0000
[dinf] size=8+28
[dref] size=12+16
[url ] size=12+0, flags=1
location = [local to file]
[stbl] size=8+9438
[stsd] size=12+142
entry_count = 1
[avc1] size=8+130
data_reference_index = 1
width = 1920
height = 1080
compressor =
[avcC] size=8+44
Configuration Version = 1
Profile = High
Profile Compatibility = 0
Level = 40
NALU Length Size = 4
Sequence Parameter = [67 64 00 28 ac d9 40 78 02 27 e5 c0 44 00 00 03 00 04 00 00 03 00 c0 3c 60 c6 58]
Picture Parameter = [68 eb e3 cb 22 c0]
[stts] size=12+12
entry_count = 1
[stss] size=12+24
entry_count = 5
[ctts] size=12+3380
entry_count = 422
[stsc] size=12+28
entry_count = 2
[stsz] size=12+2888
sample_size = 0
sample_count = 720
[stco] size=12+2880
entry_count = 719
[trak] size=8+9804
[tkhd] size=12+80, flags=3
enabled = 1
id = 2
duration = 30022
width = 0.000000
height = 0.000000
[edts] size=8+28
[elst] size=12+16
entry_count = 1
entry/segment duration = 30000
entry/media time = 1024
entry/media rate = 1
[mdia] size=8+9668
[mdhd] size=12+20
timescale = 48000
duration = 1441024
duration(ms) = 30021
language = und
[hdlr] size=12+33
handler_type = soun
handler_name = SoundHandler
[minf] size=8+9583
[smhd] size=12+4
balance = 0
[dinf] size=8+28
[dref] size=12+16
[url ] size=12+0, flags=1
location = [local to file]
[stbl] size=8+9523
[stsd] size=12+91
entry_count = 1
[mp4a] size=8+79
data_reference_index = 1
channel_count = 2
sample_size = 16
sample_rate = 48000
[esds] size=12+39
[ESDescriptor] size=5+34
es_id = 2
stream_priority = 0
[DecoderConfig] size=5+20
stream_type = 5
object_type = 64
up_stream = 0
buffer_size = 0
max_bitrate = 192580
avg_bitrate = 192580
DecoderSpecificInfo = 11 b0
[Descriptor:06] size=5+1
[stts] size=12+20
entry_count = 2
[stsc] size=12+832
entry_count = 69
[stsz] size=12+5640
sample_size = 0
sample_count = 1408
[stco] size=12+2880
entry_count = 719
[udta] size=8+90
[meta] size=12+78
[hdlr] size=12+21
handler_type = mdir
handler_name =
[ilst] size=8+37
[.too] size=8+29
[data] size=8+21
type = 1
lang = 0
value = Lavf56.25.101