元數據moov(三)tref box(ISO-14496-12)
Author:Pirate Leo
Email:[email protected]
ISO 14496 - 12 定義了一種封裝媒體數據的基礎文件格式,mp4、3gp、ismv等我們常見媒體封裝格式都是以這種基礎文件格式爲基礎衍生的。
如果從全局角度瞭解基礎文件格式,請看我之前的博文《MP4文件格式詳解——結構概述》。
本系列文檔從MP4文件入手,對文件中重要的box進行解析。
<======================================================================>
本次繼續解析moov box,關於moov的解析推薦從我之前的博文《MP4文件格式詳解——元數據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 |
本次分析tref box——TrackReferenceBox
由於我本地沒有找到包含tref box的MP4文件,因此無法以實際數據分析。
但通過協議足以使我們明白tref box的作用:
tref box可以描述兩track之間關係。
比如:一個MP4文件中有三條video track,ID分別是2、3、4,以及三條audio track,ID分別是6、7、8。
在播放track 2視頻時到底應該採用6、7、8哪條音頻與其配套播放?這時候就需要在track 2與6的tref box中指定一下,將2與6兩條track綁定起來。
在我們常見的MP4文件中幾乎看不到這種情況的存在,實際應用場景在哪呢?
我們知道,ISO-14496-12是一種基礎文件格式,從這種文件格式衍生出的不僅mp4文件,還有很多用於在線實時交付的流媒體視頻格式,比如微軟的Smooth Streaming的解決方案中的ismv文件。
假設我們是一家電視臺,我們採用了微軟的Smooth Streaming技術進行節目發佈,我們推出了13套節目,分別是CCAV 1-13。這時候我們服務器推出的媒體流可能只有一個。這個流中包含了全部的13套節目,至少有13條視頻軌與13條音頻軌。用戶在收看節目時使用了某公司生產的類似機頂盒似的硬件設備,可以解碼與播放,但是必須要找到每套節目對應的視頻與音頻(不能播放CCAV 5籃球賽畫面的同時配上了CCAV 13的共同關注聲音)。這時候就需要通過tref box將視頻與音頻之間的關係一一對應起來。
這就是tref box的實際應用場景之一,有些類似ts格式中的PAT,PMT。在官方協議中描述了另一種應用,即,參考時鐘track,簡單理解就是音視頻在此處都引用了同一個time code track,以使音視頻同步播放,類似ts格式中PCR與各track的PTS關係。
下面看具體字段:
aligned(8) class TrackReferenceBox extends Box(‘tref’)
{
}
aligned(8) class TrackReferenceTypeBox (unsigned int(32) reference_type) extends Box(reference_type)
{
unsigned int(32) track_IDs[];
}
顧名思意,tref box用於列出本track解析時所參考的track有哪些。
每個trak box中只能包含[0-1]個tref box;(通常情況下,我們所見的MP4文件是沒有tref box的)
每個tref box下面可以包含1個以上的tref type box;
引用Apple官方給出的結構圖如下:
在Apple協議中,atom是box的另一種名稱;圖中可知tref box中包含多個子box,每個子box需要填寫type和track ID。
Type的填寫參照下表(Apple定義):
Track reference types
Reference type |
Description |
---|---|
|
Time code. Usually references a time code track. |
|
Chapter or scene list. Usually references a text track. |
|
Synchronization. Usually between a video and sound track. Indicates that the two tracks are synchronized. The reference can be from either track to the other, or there may be two references. |
|
Transcript. Usually references a text track. |
|
Non-primary source. Indicates that the referenced track should send its data to this track, rather than presenting it. The referencing track will use the data to modify how it presents its data. See “Track Input Map Atoms” for more information. |
|
The referenced tracks contain the original media for this hint track. |
• ‘hint’ the referenced track(s) contain the original media for this hint track
• ‘cdsc‘ this track describes the referenced track.
• ‘hind‘ this track depends on the referenced hint track, i.e., it should only be used if the referenced
hint track is used.