mp4⽂件格式⼜被稱為MPEG-4 Part 14,出⾃MPEG-4標準第14部分 。它是⼀種多媒體格式容器,⼴泛⽤於包裝視訊和⾳頻資料流、海報、字幕和後設資料等。(順便⼀提,⽬前流⾏的視訊編碼格式AVC/H264
定義在MPEG-4 Part 10)。
mp4⽂件由box組成,每個box分為Header和Data。其中Header部分包含了box的型別和⼤⼩,Data包含了⼦box或者資料,box可以巢狀⼦box。
下圖是⼀個典型mp4⽂件的基本結構:
MP4⽂件的基本組成單元是box,也就是說MP4⽂件是由各種各樣的box組成的,有parent box,還有children box。因此,這些boxes之間存在⼀定的層次關係,總結如下表所示,表中標記出了各個box必選或可選特性,√代表Box必選。
ftyp | √ | file type and compatibility ⽂件型別和相容性 | |||||
pdin | progressive download information | ||||||
moov | √ | container for all the metadata 所有後設資料的容器 | |||||
mvhd | √ | movie header, overall declarations 電影頭,整體宣告 | |||||
trak | √ | container for an individual track or stream 單個軌或流的容器 | |||||
tkhd | √ | track header, overall information about the track 軌的頭部,關於該軌的概括資訊,⽐如視訊寬⾼ | |||||
tref | track reference container | ||||||
edts | edit list container | ||||||
elst | an edit list | ||||||
mdia | √ | container for the media information in a track 軌媒體資訊的容器 | |||||
mdhd | √ | media header, overall information about the media 媒體頭,關於媒體的總體資訊 | |||||
hdlr | √ | handler, declares the media (handler) type 媒體的播放過程資訊 | |||||
minf | √ | media information container 媒體資訊容器 | |||||
vmhd | video media header, overall information (video track only) | ||||||
smhd | sound media header, overall information (sound track only) | ||||||
hmhd | hint media header, overall information (hint track only) | ||||||
nmhd | Null media header, overall information (some tracks only) | ||||||
dinf | √ | data information box, container 資料資訊box,容器 | |||||
dref | √ | data reference box, declares source(s) of media data in track 如何定位媒體資訊 | |||||
stbl | √ | sample table box, container for the time/space map 包含了track中的sample的所有時間和位置資訊,以及sample的編解碼等資訊。利⽤這個表可以解析sample的時序、型別、⼤⼩以及在各⾃儲存容器中的位置。 | |||||
stsd | √ | sample descriptions (codec types,initialization etc.) 如果是視訊,包含:編碼型別、寬⾼、⻓度等資訊;如果是⾳頻,包含:聲道、取樣率等資訊 | |||||
stts | √ | (decoding) time-to-sample描述了sample時序的對映⽅法,我們可以通過它找到任何時間的sample。 | |||||
ctts | (composition) time to sample。 | ||||||
stsc | √ | sample-to-chunk, partial data-offset information ⽤chunk組織sample可以⽅便優化資料獲取,⼀個chunk包含⼀個或多個sample。 | |||||
stsz | sample sizes (framing) 每個sample的⼤⼩。雖然這⾥沒有打勾,但對於mp4還是⾮常必要的。 | ||||||
stz2 | compact sample sizes (framing) | ||||||
stco | √ | chunk offset, partial data-offset information 定義了每個chunk在媒體流中的偏移位置 | |||||
co64 | 64-bit chunk offset | ||||||
stss | sync sample table (random access points) ⽤於確定media中的關鍵幀 | ||||||
stsh | shadow sync sample table | ||||||
padb | sample padding bits | ||||||
stdp | sample degradation priority | ||||||
sdtp | independent and disposable samples | ||||||
sbgp | sample-to-group | ||||||
sgpd | sample group description | ||||||
subs | sub-sample information | ||||||
mvex | movie extends box | ||||||
mehd | movie extends header box | ||||||
trex | √ | track extends defaults | |||||
ipmc | IPMP Control Box | ||||||
moof | movie fragment | ||||||
mfhd | √ | movie fragment header | |||||
traf | track fragment | ||||||
tfhd | √ | track fragment header | |||||
trun | track fragment run | ||||||
sdtp | independent and disposable samples | ||||||
sbgp | sample-to-group | ||||||
subs | sub-sample information | ||||||
mfra | movie fragment random access | ||||||
tfra | track fragment random access | ||||||
mfro | √ | movie fragment random access offset | |||||
mdat | media data container | ||||||
free | free space | ||||||
skip | free space | ||||||
udta | user-data | ||||||
cprt | copyright etc. | ||||||
meta | metadata | ||||||
hdlr | √ | handler, declares the metadata (handler) type | |||||
dinf | data information box, container | ||||||
dref | data reference box, declares source(s) of metadata items | ||||||
ipmc | IPMP Control Box | ||||||
iloc | item location | ||||||
ipro | item protection | ||||||
sinf | protection scheme information box | ||||||
frma | original format box | ||||||
imif | IPMP Information box | ||||||
schm | scheme type box | ||||||
schi | scheme information box | ||||||
iinf | item information | ||||||
xml | XML container | ||||||
bxml | binary XML container | ||||||
pitm | primary item reference | ||||||
fiin | file delivery item information | ||||||
paen | partition entry | ||||||
fpar | file partition | ||||||
fecr | FEC reservoir | ||||||
segr | file delivery session group | ||||||
gitn | group id to name | ||||||
tsel | track selection | ||||||
meco | additional metadata container | ||||||
mere | metabox relation |
本⽂使⽤mediainfo和mp4box進⾏分析
圖中看到mp4⽂件由⼏個主要組成部分,下⾯以