|
元數(shù)據(jù)moov(二)tkhd box(ISO-14496-12)
Author:Pirate Leo
Email:codeevoship@gmail.com
ISO 14496 - 12 定義了一種封裝媒體數(shù)據(jù)的基礎(chǔ)文件格式,mp4、3gp、ismv等我們常見媒體封裝格式都是以這種基礎(chǔ)文件格式為基礎(chǔ)衍生的。
如果從全局角度了解基礎(chǔ)文件格式,請看我之前的博文《MP4文件格式詳解——結(jié)構(gòu)概述》。
本系列文檔從MP4文件入手,對文件中重要的box進(jìn)行解析。
<======================================================================>
本次繼續(xù)解析moov box,關(guān)于moov的解析推薦從我上一篇博文《MP4文件格式詳解——元數(shù)據(jù)moov(一)》看起。
|
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
|
|
|
|
|
|
|
dref
|
√
|
data reference box, declares source(s) of media data in track
|
|
|
|
|
|
stbl
|
|
√
|
sample table box, container for the time/space map
|
|
|
|
|
|
|
stsd
|
√
|
sample descriptions (codec types, initialization etc.)
|
|
|
|
|
|
|
stts
|
√
|
(decoding) time-to-sample
|
|
|
|
|
|
|
ctts
|
|
(composition) time to sample
|
|
|
|
|
|
|
stsc
|
√
|
sample-to-chunk, partial data-offset
information
|
|
|
|
|
|
|
stsz
|
|
sample sizes (framing)
|
|
|
|
|
|
|
stz2
|
|
compact sample sizes (framing)
|
|
|
|
|
|
|
stco
|
√
|
chunk offset, partial data-offset information
|
|
|
|
|
|
|
co64
|
|
64-bit chunk offset
|
|
|
|
|
|
|
stss
|
|
sync sample table (random access points)
|
|
|
|
|
|
|
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
|
前面我們已經(jīng)知道每個文件是由多個Track(軌道)組成的,每個Track都對應(yīng)了自身trak box,其中存放了本track的元數(shù)據(jù)信息。
本次繼續(xù)解析trak box的一系列子box:
1)tkhd box
- aligned(8) class TrackHeaderBox extends FullBox(‘tkhd’, version, flags)
- {
- if (version==1)
- {
- unsigned int(64) creation_time;
- unsigned int(64) modification_time;
- unsigned int(32) track_ID;
- const unsigned int(32) reserved = 0;
- unsigned int(64) duration;
- }
- else
- { // version==0
- unsigned int(32) creation_time;
- unsigned int(32) modification_time;
- unsigned int(32) track_ID;
- const unsigned int(32) reserved = 0;
- unsigned int(32) duration;
- }
- const unsigned int(32)[2] reserved = 0;
- template int(16) layer = 0;
- template int(16) alternate_group = 0;
- template int(16) volume = {if track_is_audio 0x0100 else 0};
- const unsigned int(16) reserved = 0;
- template int(32)[9] matrix= { 0x00010000,0,0,0,0x00010000,0,0,0,0x40000000 };
- // unity matrix
- unsigned int(32) width;
- unsigned int(32) height;
- }<strong>
- </strong>
類似我們moov中的mvhd box,但tkhd僅僅描述的單一Track的特性。

上圖是實(shí)際媒體中的tkhd的數(shù)據(jù):
0x5c是tkhd box長度,0x746b6864是“tkhd”的ASCII碼。
0x00 00 00 0f是使用了Full box中的flag位(Full box 8bits version + 24bits flag,詳見我第一篇日志),這里flag= 0xf,即1111b。
這4位從低到高分別代表:
Track_enabled: Indicates that the track is enabled. 若此位為0,則該track內(nèi)容無需播放(比如我們用一些非線編軟件<如Sony Vegas>做視頻剪輯時,有些Track僅為我們參考與模仿用,在輸出時將該Track關(guān)掉)。
Track_in_movie: Indicates that the track is used in the presentation.
Track_in_preview: Indicates that the track is used when previewing the presentation.
Track_in_poster: Indicates that the track is used in movie's poster.
/* -------------------------------------------------------------------------------------------------------*/
important:我們知道,MP4文件格式是ISO-14496-12基礎(chǔ)文件格式的衍生品,14496-14中對-12協(xié)議進(jìn)行了擴(kuò)充與進(jìn)一步定義。
重要的是該“14496-12 基礎(chǔ)文件格式”協(xié)議如果認(rèn)祖歸宗,我們發(fā)現(xiàn)這種文件格式最初是由Apple公司的QuickTime媒體格式發(fā)展而來的。
即,mov格式發(fā)展出了“ISO 14496 - 12協(xié)議”,再由該協(xié)議衍生出了mp4,f4v,ismv,3gp等我們常見的媒體封裝格式。
因此上述標(biāo)志位的poster位,在14496-12中并沒有見到描述,而在Apple的協(xié)議中卻看到了準(zhǔn)確定義。
詳見 https://developer.apple.com/library/mac/#documentation/QuickTime/QTFF/QTFFChap2/qtff2.html
/* -------------------------------------------------------------------------------------------------------*/
兩個0xc5268eb6 是track的創(chuàng)建時間與最后修改時間;
緊隨其后的0x00000002,代表track ID =2,Track ID是非0的,唯一的,不可重復(fù)使用的標(biāo)識track的方式;
后面32bit全0是保留位;
0x0009d97c是本track的時長,需要配合mvhd box中的timescale 計算實(shí)際的持續(xù)時間。
后續(xù)一些寫死的字段不再分析,有些與mvhd重復(fù),可以參見之前的文章。我們看兩個關(guān)鍵字段:
layer,類似photoshop中圖層的概念,數(shù)值小的在播放時更貼近用戶(上層圖層)。
alternate_group,track的備用分組ID,當(dāng)該值為0時,意味著本track內(nèi)容無備份;否則本track會可能會有零到多個備份track。當(dāng)播放時相同group ID的track只選擇一個進(jìn)行播放。
|