1. 程式人生 > >mp4格式分析之元資料moov(三)

mp4格式分析之元資料moov(三)

由於我本地沒有找到包含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關係。

下面看具體欄位:

[cpp] view plaincopyprint?
  1. aligned(8) class TrackReferenceBox extends Box(‘tref’)   
  2. {  
  3. }   
  4. aligned(8) class TrackReferenceTypeBox (unsigned int
    (32) reference_type) extends Box(reference_type)   
  5. {  
  6.   unsigned int(32) track_IDs[];   
  7. }   

顧名思意,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

'tmcd'

Time code. Usually references a time code track.

'chap'

Chapter or scene list. Usually references a text track.

'sync'

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.

'scpt'

Transcript. Usually references a text track.

'ssrc'

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  for more information.

'hint'

The referenced tracks contain the original media for this hint track.

ISO-14496-12又重新整理了這些type欄位為以下三種:

•  ‘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.