F4v是MP4的子集,由adobe定义。
网上资料大多关于mp4的box,对于整体结构,特别是chunk-sample(video/audio)的关系说得很模糊。
分几篇文章来说明mp4文件结构。
第一篇关于mp4的整体结构,mp4的box结构请参考其他文章。
mp4典型的结构如下图,由三个box组成:
Adobe的sample文件,sample1_1500kbps.f4v的结构解析分析,第一个box的数据如下:
box(F4vFtypBox,"ftyp",0x66747970):
header:
total_size:32(0x00000020)
box_type:1718909296(0x66747970)
payload:
major_brand:1714714144(0x66347620)
minor_version:0(0x00000000)
compatible_brands:16bytes 32 34 70 6D 32 6F 73 69 6D 6F 73 69 31 63 76 61
它第三个mdata的box数据如下:
box(F4vMediaDataBox,"mdat",0x6D646174):
header:
total_size:19645094(0x012BC2A6)
box_type:1835295092(0x6D646174)
payload:
payload:19645086bytes 00 00 00 00 00 00 00 00 00 00 00 02 09 10 00 00 ...
第二个box的数据很多,文件太大有1M多,下面只贴出一些关键点,省略了信息,可以在这里下载:http://download.csdn.net/download/winlinvip/4775226 ,如下:
box(F4vMoovBox,"moov",0x6D6F6F76):
header:
total_size:45362(0x0000B132)
box_type:1836019574(0x6D6F6F76)
payload:
movie_header_box:
box(F4vMovieHeaderBox,"mvhd",0x6D766864):
header:
total_size:108(0x0000006C)
box_type:1836476516(0x6D766864)
payload:
creation_time:
v_int32:-938482834(0xC80FE36E)
modification_time:
v_int32:-938482834(0xC80FE36E)
time_scale:30000(0x00007530)
duration:
v_int32:3438435(0x00347763)
rate:
a:1(0x0001)
b:0(0x0000)
volume:
a:1(0x01)
b:0(0x00)
reserved0:0(0x0000)
reserved1:0(0x0000000000000000)
matrix:36bytes 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 ...
reserved2:24bytes 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ...
next_track_id:3(0x00000003)
boxes:
boxes:
box(F4vTrackBox,"trak",0x7472616B):
header:
total_size:34412(0x0000866C)
box_type:1953653099(0x7472616B)
payload:
track_header:
box(F4vTrackHeaderBox,"tkhd",0x746B6864):
header:
total_size:92(0x0000005C)
box_type:1953196132(0x746B6864)
payload:
creation_time:
v_int32:-938482834(0xC80FE36E)
modification_time:
v_int32:-938482834(0xC80FE36E)
track_id:1(0x00000001)
reserved0:0(0x00000000)
duration:
v_int32:3438435(0x00347763)
reserved1:0(0x0000000000000000)
layer:0(0x0000)
alternate_group:0(0x0000)
volume:
a:0(0x00)
b:0(0x00)
reserved2:0(0x0000)
transform_matrix:36bytes 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 ...
width:
a:640(0x0280)
b:0(0x0000)
height:
a:352(0x0160)
b:0(0x0000)
boxes:
boxes:
box(F4vMediaBox,"mdia",0x6D646961):
header:
total_size:34312(0x00008608)
box_type:1835297121(0x6D646961)
payload:
media_header:
box(F4vMediaHeaderBox,"mdhd",0x6D646864):
header:
total_size:32(0x00000020)
box_type:1835296868(0x6D646864)
payload:
creation_time:
v_int32:-938482834(0xC80FE36E)
modification_time:
v_int32:-938482834(0xC80FE36E)
timescale:30000(0x00007530)
duration:
v_int32:3438435(0x00347763)
language:0(0x0000)
reserved0:0(0x0000)
handler_reference:
box(F4vHandlerReferenceBox,"hdlr",0x68646C72):
header:
total_size:52(0x00000034)
box_type:1751411826(0x68646C72)
payload:
version:0(0x00)
flags:0(0x000000)
predefined:0(0x00000000)
handler_type:1986618469(0x76696465)
reserved0:12bytes 00 00 00 00 00 00 00 00 00 00 00 00
name:Video Media Handler
media_information:
box(F4vMediaInformationBox,"minf",0x6D696E66):
header:
total_size:34220(0x000085AC)
box_type:1835626086(0x6D696E66)
payload:
media_info_header:
box(F4vVideoMediaHeaderBox,"vmhd",0x766D6864):
header:
total_size:20(0x00000014)
box_type:1986881636(0x766D6864)
payload:
version:0(0x00)
flags:1(0x000001)
graphics_mode:0(0x0000)
op_color:6bytes 00 00 00 00 00 00
data_information:
box(F4vDataInformationBox,"dinf",0x64696E66):
header:
total_size:36(0x00000024)
box_type:1684631142(0x64696E66)
payload:
reference_box:
box(F4vReferenceBox,"dref",0x64726566):
header:
total_size:28(0x0000001C)
box_type:1685218662(0x64726566)
payload:
version:0(0x00)
flags:0(0x000000)
entry_count:1(0x00000001)
data_entry:
box(F4vDataEntryUrlBox,"url ",0x75726C20):
header:
total_size:12(0x0000000C)
box_type:1970433056(0x75726C20)
payload:
version:0(0x00)
flags:1(0x000001)
location:NULL
sample_table:
box(F4vSampleTableBox,"stbl",0x7374626C):
header:
total_size:34156(0x0000856C)
box_type:1937007212(0x7374626C)
payload:
sample_description:
box(F4vSampleDescriptionBox,"stsd",0x73747364):
header:
total_size:180(0x000000B4)
box_type:1937011556(0x73747364)
payload:
version:0(0x00)
flags:0(0x000000)
count:1(0x00000001)
descriptions:
boxes:
box(F4vVideoAvc1,"avc1",0x61766331):
header:
total_size:164(0x000000A4)
box_type:1635148593(0x61766331)
payload:
reserved0:6bytes 00 00 00 00 00 00
data_reference_index:1(0x0001)
predefined0:0(0x0000)
reserved1:0(0x0000)
predefined1:12bytes 00 00 00 00 00 00 00 00 00 00 00 00
width:640(0x0280)
height:352(0x0160)
horiz_resolution:
a:72(0x0048)
b:0(0x0000)
vert_resolution:
a:70(0x0046)
b:26214(0x6666)
reserved2:0(0x00000000)
frame_count:1(0x0001)
compressor_name:32bytes 0A 41 56 43 20 43 6F 64 69 6E 67 00 00 00 00 00 ...
depth:24(0x0018)
predefined2:65535(0xFFFF)
boxes:
boxes:
box(F4vBox,"avcC",0x61766343):
header:
total_size:58(0x0000003A)
box_type:1635148611(0x61766343)
payload:
payload:50bytes 01 64 00 1E FF E1 00 21 27 64 00 1E AC 2C AC 0A ...
box(F4vBox,"btrt",0x62747274):
header:
total_size:20(0x00000014)
box_type:1651798644(0x62747274)
payload:
payload:12bytes 00 02 C1 00 00 16 08 00 00 15 E9 60
decoding_time_to_sample:
box(F4vDecodingTimeToSampleBox,"stts",0x73747473):
header:
total_size:24(0x00000018)
box_type:1937011827(0x73747473)
payload:
version:0(0x00)
flags:0(0x000000)
count:1(0x00000001)
sample_count:3435(0x00000D6B)
sample_delta:1001(0x000003E9)
composition_time_to_sample:
box(F4vCompositionTimeToSampleBox,"ctts",0x63747473):
header:
total_size:19728(0x00004D10)
box_type:1668576371(0x63747473)
payload:
version:0(0x00)
flags:0(0x000000)
count:2464(0x000009A0)
sample_count:1(0x00000001)
sample_offset:1001(0x000003E9)
sample_count:1(0x00000001)
sample_offset:3003(0x00000BBB)
sample_count:2(0x00000002)
sample_offset:0(0x00000000)
sample_count:1(0x00000001)
sample_offset:3003(0x00000BBB)
sample_count:2(0x00000002)
sample_offset:0(0x00000000)
sample_count:1(0x00000001)
sample_offset:3003(0x00000BBB)
...........................
...........................
sample_count:1(0x00000001)
sample_offset:0(0x00000000)
sample_to_chunk:
box(F4vSampleToChunkBox,"stsc",0x73747363):
header:
total_size:112(0x00000070)
box_type:1937011555(0x73747363)
payload:
version:0(0x00)
flags:0(0x000000)
count:8(0x00000008)
first_chunk:1(0x00000001)
samples_per_chunk:90(0x0000005A)
samples_desc_index:1(0x00000001)
first_chunk:12(0x0000000C)
samples_per_chunk:89(0x00000059)
samples_desc_index:1(0x00000001)
first_chunk:13(0x0000000D)
samples_per_chunk:90(0x0000005A)
samples_desc_index:1(0x00000001)
...........................
first_chunk:39(0x00000027)
samples_per_chunk:18(0x00000012)
samples_desc_index:1(0x00000001)
sample_size:
box(F4vSampleSizeBox,"stsz",0x7374737A):
header:
total_size:13760(0x000035C0)
box_type:1937011578(0x7374737A)
payload:
version:0(0x00)
flags:0(0x000000)
constant_size:0(0x00000000)
size_count:3435(0x00000D6B)
size_table:
sample_size:1593(0x00000639)
sample_size:229(0x000000E5)
sample_size:96(0x00000060)
sample_size:95(0x0000005F)
sample_size:718(0x000002CE)
sample_size:152(0x00000098)
sample_size:148(0x00000094)
sample_size:1402(0x0000057A)
sample_size:260(0x00000104)
sample_size:246(0x000000F6)
sample_size:649(0x00000289)
sample_size:95(0x0000005F)
sample_size:111(0x0000006F)
sample_size:2330(0x0000091A)
sample_size:370(0x00000172)
sample_size:696(0x000002B8)
sample_size:7100(0x00001BBC)
sample_size:1890(0x00000762)
sample_size:2101(0x00000835)
...........................
sample_size:2520(0x000009D8)
sample_size:2838(0x00000B16)
sample_size:1995(0x000007CB)
chunk_offset:
box(F4vChunkOffsetStcoBox,"stco",0x7374636F):
header:
total_size:172(0x000000AC)
box_type:1937007471(0x7374636F)
payload:
version:0(0x00)
flags:0(0x000000)
offset_count:39(0x00000027)
offsets:
chunk_offset:53932(0x0000D2AC)
chunk_offset:359182(0x00057B0E)
chunk_offset:931430(0x000E3666)
chunk_offset:1171186(0x0011DEF2)
chunk_offset:1236607(0x0012DE7F)
chunk_offset:1711188(0x001A1C54)
chunk_offset:2283310(0x0022D72E)
chunk_offset:2862003(0x002BABB3)
chunk_offset:3406733(0x0033FB8D)
...........................
chunk_offset:19566362(0x012A8F1A)
sync_sample:
box(F4vSyncSampleBox,"stss",0x73747373):
header:
total_size:172(0x000000AC)
box_type:1937011571(0x73747373)
payload:
version:0(0x00)
flags:0(0x000000)
sync_count:39(0x00000027)
sync_table:
sync_sample:1(0x00000001)
sync_sample:91(0x0000005B)
sync_sample:181(0x000000B5)
sync_sample:271(0x0000010F)
sync_sample:361(0x00000169)
sync_sample:451(0x000001C3)
sync_sample:541(0x0000021D)
sync_sample:631(0x00000277)
sync_sample:721(0x000002D1)
...........................
sync_sample:3331(0x00000D03)
sync_sample:3421(0x00000D5D)
boxes:
boxes:
box(F4vTrackBox,"trak",0x7472616B):
header:
total_size:10834(0x00002A52)
box_type:1953653099(0x7472616B)
payload:
track_header:
box(F4vTrackHeaderBox,"tkhd",0x746B6864):
header:
total_size:92(0x0000005C)
box_type:1953196132(0x746B6864)
payload:
creation_time:
v_int32:-938482834(0xC80FE36E)
modification_time:
v_int32:-938482834(0xC80FE36E)
track_id:2(0x00000002)
reserved0:0(0x00000000)
duration:
v_int32:3438435(0x00347763)
reserved1:0(0x0000000000000000)
layer:0(0x0000)
alternate_group:0(0x0000)
volume:
a:1(0x01)
b:0(0x00)
reserved2:0(0x0000)
transform_matrix:36bytes 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 ...
width:
a:0(0x0000)
b:0(0x0000)
height:
a:0(0x0000)
b:0(0x0000)
boxes:
boxes:
box(F4vMediaBox,"mdia",0x6D646961):
header:
total_size:10734(0x000029EE)
box_type:1835297121(0x6D646961)
payload:
media_header:
box(F4vMediaHeaderBox,"mdhd",0x6D646864):
header:
total_size:32(0x00000020)
box_type:1835296868(0x6D646864)
payload:
creation_time:
v_int32:-938482834(0xC80FE36E)
modification_time:
v_int32:-938482834(0xC80FE36E)
timescale:22050(0x00005622)
duration:
v_int32:2528256(0x00269400)
language:0(0x0000)
reserved0:0(0x0000)
handler_reference:
box(F4vHandlerReferenceBox,"hdlr",0x68646C72):
header:
total_size:52(0x00000034)
box_type:1751411826(0x68646C72)
payload:
version:0(0x00)
flags:0(0x000000)
predefined:0(0x00000000)
handler_type:1936684398(0x736F756E)
reserved0:12bytes 00 00 00 00 00 00 00 00 00 00 00 00
name:Sound Media Handler
media_information:
box(F4vMediaInformationBox,"minf",0x6D696E66):
header:
total_size:10642(0x00002992)
box_type:1835626086(0x6D696E66)
payload:
media_info_header:
box(F4vSoundMediaHeaderBox,"smhd",0x736D6864):
header:
total_size:16(0x00000010)
box_type:1936549988(0x736D6864)
payload:
version:0(0x00)
flags:0(0x000000)
graphics_mode:
a:0(0x00)
b:0(0x00)
reserved0:0(0x0000)
data_information:
box(F4vDataInformationBox,"dinf",0x64696E66):
header:
total_size:36(0x00000024)
box_type:1684631142(0x64696E66)
payload:
reference_box:
box(F4vReferenceBox,"dref",0x64726566):
header:
total_size:28(0x0000001C)
box_type:1685218662(0x64726566)
payload:
version:0(0x00)
flags:0(0x000000)
entry_count:1(0x00000001)
data_entry:
box(F4vDataEntryUrlBox,"url ",0x75726C20):
header:
total_size:12(0x0000000C)
box_type:1970433056(0x75726C20)
payload:
version:0(0x00)
flags:1(0x000001)
location:NULL
sample_table:
box(F4vSampleTableBox,"stbl",0x7374626C):
header:
total_size:10582(0x00002956)
box_type:1937007212(0x7374626C)
payload:
sample_description:
box(F4vSampleDescriptionBox,"stsd",0x73747364):
header:
total_size:94(0x0000005E)
box_type:1937011556(0x73747364)
payload:
version:0(0x00)
flags:0(0x000000)
count:1(0x00000001)
descriptions:
boxes:
box(F4vAudioAAC,"AAC",0x6D703461):
header:
total_size:78(0x0000004E)
box_type:1836069985(0x6D703461)
payload:
reserved0:6bytes 00 00 00 00 00 00
data_reference_index:1(0x0001)
reserved1:0(0x0000000000000000)
channel_count:2(0x0002)
sample_size:16(0x0010)
predefined2:0(0x0000)
reserved2:0(0x0000)
sample_rate:
a:22050(0x5622)
b:0(0x0000)
boxes:
boxes:
box(F4vBox,"esds",0x65736473):
header:
total_size:42(0x0000002A)
box_type:1702061171(0x65736473)
payload:
payload:34bytes 00 00 00 00 03 1C 00 00 00 04 14 40 15 00 1F 40 ...
decoding_time_to_sample:
box(F4vDecodingTimeToSampleBox,"stts",0x73747473):
header:
total_size:24(0x00000018)
box_type:1937011827(0x73747473)
payload:
version:0(0x00)
flags:0(0x000000)
count:1(0x00000001)
sample_count:2469(0x000009A5)
sample_delta:1024(0x00000400)
sample_to_chunk:
box(F4vSampleToChunkBox,"stsc",0x73747363):
header:
total_size:388(0x00000184)
box_type:1937011555(0x73747363)
payload:
version:0(0x00)
flags:0(0x000000)
count:31(0x0000001F)
first_chunk:1(0x00000001)
samples_per_chunk:65(0x00000041)
samples_desc_index:1(0x00000001)
first_chunk:3(0x00000003)
samples_per_chunk:64(0x00000040)
samples_desc_index:1(0x00000001)
first_chunk:4(0x00000004)
samples_per_chunk:65(0x00000041)
samples_desc_index:1(0x00000001)
first_chunk:5(0x00000005)
samples_per_chunk:64(0x00000040)
samples_desc_index:1(0x00000001)
first_chunk:6(0x00000006)
samples_per_chunk:65(0x00000041)
samples_desc_index:1(0x00000001)
first_chunk:8(0x00000008)
samples_per_chunk:64(0x00000040)
samples_desc_index:1(0x00000001)
first_chunk:9(0x00000009)
samples_per_chunk:65(0x00000041)
samples_desc_index:1(0x00000001)
first_chunk:10(0x0000000A)
samples_per_chunk:64(0x00000040)
samples_desc_index:1(0x00000001)
...........................
first_chunk:39(0x00000027)
samples_per_chunk:14(0x0000000E)
samples_desc_index:1(0x00000001)
sample_size:
box(F4vSampleSizeBox,"stsz",0x7374737A):
header:
total_size:9896(0x000026A8)
box_type:1937011578(0x7374737A)
payload:
version:0(0x00)
flags:0(0x000000)
constant_size:0(0x00000000)
size_count:2469(0x000009A5)
size_table:
sample_size:371(0x00000173)
sample_size:372(0x00000174)
sample_size:417(0x000001A1)
sample_size:497(0x000001F1)
sample_size:462(0x000001CE)
sample_size:493(0x000001ED)
sample_size:408(0x00000198)
sample_size:418(0x000001A2)
sample_size:366(0x0000016E)
sample_size:395(0x0000018B)
sample_size:371(0x00000173)
sample_size:358(0x00000166)
...........................
sample_size:383(0x0000017F)
sample_size:364(0x0000016C)
sample_size:386(0x00000182)
sample_size:405(0x00000195)
chunk_offset:
box(F4vChunkOffsetStcoBox,"stco",0x7374636F):
header:
total_size:172(0x000000AC)
box_type:1937007471(0x7374636F)
payload:
version:0(0x00)
flags:0(0x000000)
offset_count:39(0x00000027)
offsets:
chunk_offset:334724(0x00051B84)
chunk_offset:906122(0x000DD38A)
chunk_offset:1145912(0x00117C38)
chunk_offset:1211243(0x00127B6B)
chunk_offset:1686344(0x0019BB48)
chunk_offset:2257621(0x002272D5)
chunk_offset:2836800(0x002B4940)
chunk_offset:3381618(0x00339972)
chunk_offset:3938809(0x003C19F9)
chunk_offset:4524709(0x00450AA5)
chunk_offset:5085138(0x004D97D2)
...........................
chunk_offset:18975430(0x01218AC6)
chunk_offset:19541106(0x012A2C72)
chunk_offset:19693547(0x012C7FEB)
boxes:
boxes: