小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

MP4文件格式詳解

 gljin_cn 2016-06-21

元數(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

  1. aligned(8) class TrackHeaderBox extends FullBox(‘tkhd’, version, flags)  
  2. {  
  3.     if (version==1)   
  4.     {   
  5.       unsigned int(64) creation_time;   
  6.       unsigned int(64) modification_time;   
  7.       unsigned int(32) track_ID;   
  8.       const unsigned int(32)  reserved = 0;   
  9.       unsigned int(64) duration;   
  10.     }   
  11.     else   
  12.     {   // version==0   
  13.         unsigned int(32) creation_time;   
  14.         unsigned int(32) modification_time;   
  15.         unsigned int(32) track_ID;   
  16.         const unsigned int(32)  reserved = 0;   
  17.         unsigned int(32) duration;   
  18.     }   
  19.     const unsigned int(32)[2]  reserved = 0;   
  20.     template int(16) layer = 0;   
  21.     template int(16) alternate_group = 0;   
  22.     template int(16)  volume = {if track_is_audio 0x0100 else 0};   
  23.     const unsigned int(16)  reserved = 0;   
  24.     template int(32)[9]  matrix= { 0x00010000,0,0,0,0x00010000,0,0,0,0x40000000 };   
  25.     // unity matrix   
  26.     unsigned int(32) width;   
  27.     unsigned int(32) height;   
  28. }<strong>  
  29. </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)行播放。


    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多