最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

音視頻八股文(10)-- mp4結(jié)構(gòu)

2023-05-05 20:20 作者:福大大架構(gòu)師每日一題  | 我要投稿

介紹

mp4?件格式?被稱為MPEG-4 Part 14,出?MPEG-4標(biāo)準(zhǔn)第14部分 。它是?種多媒體格式容器,?泛?于包裝視頻和?頻數(shù)據(jù)流、海報(bào)、字幕和元數(shù)據(jù)等。(順便?提,?前流?的視頻編碼格式AVC/H264 定義在MPEG-4 Part 10)。

概述

mp4?件由box組成,每個(gè)box分為Header和Data。其中Header部分包含了box的類型和??,Data包含了?box或者數(shù)據(jù),box可以嵌套?box。

下圖是?個(gè)典型mp4?件的基本結(jié)構(gòu):

圖片
在這里插入圖片描述

MP4?件的基本組成單元是box,也就是說(shuō)MP4?件是由各種各樣的box組成的,有parent box,還有children box。因此,這些boxes之間存在?定的層次關(guān)系,總結(jié)如下表所示,表中標(biāo)記出了各個(gè)box必選或可選特性,√代表Box必選。









ftyp




√file type and compatibility ?件類型和兼容性pdin





progressive download informationmoov




√container for all the metadata 所有元數(shù)據(jù)的容器
mvhd



√movie header, overall declarations 電影頭,整體聲明
trak



√container for an individual track or stream 單個(gè)軌或流的容器

tkhd


√track header, overall information about the track 軌的頭部,關(guān)于該軌的概括信息,?如視頻寬?

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 媒體頭,關(guān)于媒體的總體信息


hdlr

√handler, declares the media (handler) type 媒體的播放過(guò)程信息


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 數(shù)據(jù)信息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的所有時(shí)間和位置信息,以及sample的編解碼等信息。利?這個(gè)表可以解析sample的時(shí)序、類型、??以及在各?存儲(chǔ)容器中的位置。




stsd√sample descriptions (codec types,initialization etc.) 如果是視頻,包含:編碼類型、寬?、?度等信息;如果是?頻,包含:聲道、采樣率等信息




stts√(decoding) time-to-sample描述了sample時(shí)序的映射?法,我們可以通過(guò)它找到任何時(shí)間的sample。




ctts
(composition) time to sample。




stsc√sample-to-chunk, partial data-offset information ?chunk組織sample可以?便優(yōu)化數(shù)據(jù)獲取,?個(gè)chunk包含?個(gè)或多個(gè)sample。




stsz
sample sizes (framing) 每個(gè)sample的??。雖然這?沒(méi)有打勾,但對(duì)于mp4還是?常必要的。




stz2
compact sample sizes (framing)




stco√chunk offset, partial data-offset information 定義了每個(gè)chunk在媒體流中的偏移位置




co64
64-bit chunk offset




stss
sync sample table (random access points) ?于確定media中的關(guān)鍵幀




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 Boxmoof





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 informationmfra





movie fragment random access
tfra




track fragment random access
mfro



√movie fragment random access offsetmdat





media data containerfree





free spaceskip





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 selectionmeco





additional metadata container
mere




metabox relation

本?使?mediainfo和mp4box進(jìn)?分析

圖中看到mp4?件由?個(gè)主要組成部分,下?以?? 2_audio_track_5s.mp4?件為分析案例:

ftyp

File Type Box,?般在?件的開(kāi)始位置,描述的?件的版本、兼容協(xié)議等。

1?000000?File?Type?(32?bytes)
2?000000?Header?(8?bytes)
3?000000?Size:?32?(0x00000020)
4?000004?Name:?ftyp
5?000008?MajorBrand:?isom
6?00000C?MajorBrandVersion:?512?(0x00000200)
7?000010?CompatibleBrand:?isom
8?000014?CompatibleBrand:?iso2
9?000018?CompatibleBrand:?avc1
10?00001C?CompatibleBrand:?mp41

moov

Movie Box,包含本?件中所有媒體數(shù)據(jù)的宏觀描述信息以及每路媒體軌道的具體信息。?般位于放在?件末尾,但如果為了?持http邊下載邊播放則需要將moov提前。注意,當(dāng)改變moov位置時(shí),內(nèi)部?些值需要重新計(jì)算。

1?14B2CE?File?header?(10341?bytes)
2?14B2CE?Header?(8?bytes)
3?14B2CE?Size:?10341?(0x00002865)
4?14B2D2?Name:?moov

moov??的box才是我們主要分析的box

mdat

Media Data Box,存放具體的媒體數(shù)據(jù)。

1?000028?Data?(1356454?bytes)
2?000028?Header?(8?bytes)
3?000028?Size:?1356454?(0x0014B2A6)
4?00002C?Name:?mdat
5?000030?Data:?(1356446?bytes)
6?.............數(shù)據(jù)區(qū)域?連續(xù)儲(chǔ).........................................

Moov Insider

mp4的媒體數(shù)據(jù)信息主要存放在Moov Box中,是我們需要分析的重點(diǎn)。moov的主要組成部分如下:

mvhd

Movie Header Box,記錄整個(gè)媒體?件的描述信息,如創(chuàng)建時(shí)間、修改時(shí)間、時(shí)間度量標(biāo)尺、可播放時(shí)?等。

下圖示例中,可以獲取?件信息如時(shí)?為 Duration: 5016 ms秒。

1?14B2D6?Movie?header?(108?bytes)
2?14B2D6?Header?(8?bytes)
3?14B2D6?Size:?108?(0x0000006C)
4?14B2DA?Name:?mvhd
5?14B2DE?Version:?0?(0x00)
6?14B2DF?Flags:?0?(0x000000)
7?14B2E2?Creation?time:?0?(0x00000000)?-
8?14B2E6?Modification?time:?0?(0x00000000)?-
9?14B2EA?Time?scale:?1000?(0x000003E8)
-?1000?Hz
10?14B2EE?Duration:?5016?(0x00001398)
-?5016?ms
11?14B2F2?Preferred?rate:?65536?(0x00010000)
-?1.000
12?14B2F6?Preferred?volume:?256?(0x0100)?-?1.0
00
13?14B2F8?Reserved:?(10?bytes)
14?14B302?Matrix?structure?(36?bytes)
15?14B302?a?(width?scale):?1.000
16?14B306?b?(width?rotate):?0.000
17?14B30A?u?(width?angle):?0.000
18?14B30E?c?(height?rotate):?0.000
19?14B312?d?(height?scale):?1.000
20?14B316?v?(height?angle):?0.000
21?14B31A?x?(position?left):?0.000
22?14B31E?y?(position?top):?0.000
23?14B322?w?(divider):?1.000
24?14B326?Preview?time:?0?(0x00000000)
25?14B32A?Preview?duration:?0?(0x00000000)
26?14B32E?Poster?time:?0?(0x00000000)
27?14B332?Selection?time:?0?(0x00000000)
28?14B336?Selection?duration:?0?(0x00000000)
29?14B33A?Current?time:?0?(0x00000000)
30?14B33E?Next?track?ID:?4?(0x00000004)

udta

User Data Box,?定義數(shù)據(jù)。

track

Track Box,記錄媒體流信息,?件中可以存在?個(gè)或多個(gè)track,它們之間是相互獨(dú)?的。

每個(gè)track包含以下?個(gè)組成部分:

tkhd

Track Header Box,包含關(guān)于媒體流的頭信息。

下圖示例中,可以看到流信息如視頻流寬度720,?度1280。

1?14CEA6?Track?Header?(92?bytes)
2?14CEA6?Header?(8?bytes)
3?14CEA6?Size:?92?(0x0000005C)
4?14CEAA?Name:?tkhd
5?14CEAE?Version:?0?(0x00)
6?14CEAF?Flags:?3?(0x000003)
7?14CEB2?Track?Enabled:?Yes
8?14CEB2?Track?in?Movie:?2?(0x0000000000000
002)
9?14CEB2?Track?in?Preview:?0?(0x0000000000000
000)
10?14CEB2?Track?in?Poster:?0?(0x0000000000000
000)
11?14CEB2?Creation?time:?0?(0x00000000)?-
12?14CEB6?Modification?time:?0?(0x00000000)?-
13?14CEBA?Track?ID:?3?(0x00000003)
14?14CEBE?Reserved:?0?(0x00000000)
15?14CEC2?Duration:?4875?(0x0000130B)
-?4875?(0x130B)?ms
16?14CEC6?Reserved:?0?(0x00000000)
17?14CECA?Reserved:?0?(0x00000000)
18?14CECE?Layer:?0?(0x0000)
19?14CED0?Alternate?group:?2?(0x0002)
20?14CED2?Volume:?0?(0x0000)?-?0.000
21?14CED4?Reserved:?0?(0x0000)
22?14CED6?Matrix?structure?(36?bytes)
23?14CED6?a?(width?scale):?1.000
24?14CEDA?b?(width?rotate):?0.000
25?14CEDE?u?(width?angle):?0.000
26?14CEE2?c?(height?rotate):?0.000
27?14CEE6?d?(height?scale):?1.000
28?14CEEA?v?(height?angle):?0.000
29?14CEEE?x?(position?left):?0.000
30?14CEF2?y?(position?top):?0.000
31?14CEF6?w?(divider):?1.000
32?14CEFA?Track?width:?1920.000
33?14CEFE?Track?height:?800.000

?頻的tkhd,則?如duration、volume等。

1?14B34A?Track?Header?(92?bytes)
2?14B34A?Header?(8?bytes)
3?14B34A?Size:?92?(0x0000005C)
4?14B34E?Name:?tkhd
5?14B352?Version:?0?(0x00)
6?14B353?Flags:?3?(0x000003)
7?14B356?Track?Enabled:?Yes
8?14B356?Track?in?Movie:?2?(0x0000000000000
002)
9?14B356?Track?in?Preview:?0?(0x0000000000000
000)
10?14B356?Track?in?Poster:?0?(0x0000000000000
000)
11?14B356?Creation?time:?0?(0x00000000)?-
12?14B35A?Modification?time:?0?(0x00000000)?-
13?14B35E?Track?ID:?1?(0x00000001)
14?14B362?Reserved:?0?(0x00000000)
15?14B366?Duration:?5016?(0x00001398)
-?5016?(0x1398)?ms
16?14B36A?Reserved:?0?(0x00000000)
17?14B36E?Reserved:?0?(0x00000000)
18?14B372?Layer:?0?(0x0000)
19?14B374?Alternate?group:?0?(0x0000)
20?14B376?Volume:?256?(0x0100)?-?1.0
00
21?14B378?Reserved:?0?(0x0000)
22?14B37A?Matrix?structure?(36?bytes)
23?14B37A?a?(width?scale):?1.000
24?14B37E?b?(width?rotate):?0.000
25?14B382?u?(width?angle):?0.000
26?14B386?c?(height?rotate):?0.000
27?14B38A?d?(height?scale):?1.000
28?14B38E?v?(height?angle):?0.000
29?14B392?x?(position?left):?0.000
30?14B396?y?(position?top):?0.000
31?14B39A?w?(divider):?1.000
32?14B39E?Track?width:?0.000
33?14B3A2?Track?height:?0.000

mdia

Media Box,這是?個(gè)包含track媒體數(shù)據(jù)信息的container box。?box包括:

mdhd:Media Header Box,存放視頻流創(chuàng)建時(shí)間,?度等信息。

hdlr:Handler Reference Box,媒體的播放過(guò)程信息。

minf:Media Information Box,解釋track媒體數(shù)據(jù)的handler-specific信息。minf同樣是個(gè)container

box,其內(nèi)部需要關(guān)注的內(nèi)容是stbl,這也是moov中最復(fù)雜的部分。stbl包含了媒體流每?個(gè)sample在?件中的offset,pts,duration等信息。想要播放?個(gè)mp4?件,必須根據(jù)stbl正確找到每個(gè)sample并送給解碼器。

mdia展開(kāi)如下圖所示:

1?14CF32?Media?(2975?bytes)
2?14CF32?Header?(8?bytes)
3?14CF32?Size:?2975?(0x00000B9F)
4?14CF36?Name:?mdia

在這里插入圖片描述

mdhd

Media Header Box,存放視頻流創(chuàng)建時(shí)間,?度等信息。

視頻的mdhd,Time scale,Duration等信息。

1?14CF3A?Media?Header?(32?bytes)
2?14CF3A?Header?(8?bytes)
3?14CF3A?Size:?32?(0x00000020)
4?14CF3E?Name:?mdhd
5?14CF42?Version:?0?(0x00)
6?14CF43?Flags:?0?(0x000000)
7?14CF46?Creation?time:?0?(0x00000000)?-
8?14CF4A?Modification?time:?0?(0x00000000)?-
9?14CF4E?Time?scale:?90000?(0x00015F90)
10?14CF52?Duration:?438750?(0x0006B1DE
)?-?4875?(0x130B)?ms
11?14CF56?Language:?21956?(0x55C4)?-?u
nd
12?14CF58?Quality:?0?(0x0000)

?頻的mdhd,也類似視頻,但要注意Time scale,我們?cè)谟?jì)算時(shí)間戳的時(shí)候都要使?該Time scale,對(duì)應(yīng)我們流??的AVStream->time_base

1?14B3D2?Media?Header?(32?bytes)
2?14B3D2?Header?(8?bytes)
3?14B3D2?Size:?32?(0x00000020)
4?14B3D6?Name:?mdhd
5?14B3DA?Version:?0?(0x00)
6?14B3DB?Flags:?0?(0x000000)
7?14B3DE?Creation?time:?0?(0x00000000)?-
8?14B3E2?Modification?time:?0?(0x00000000)?-
9?14B3E6?Time?scale:?44100?(0x0000AC44)
10?14B3EA?Duration:?221184?(0x00036000
)?-?5015?(0x1397)?ms
11?14B3EE?Language:?21956?(0x55C4)?-?u
nd
12?14B3F0?Quality:?0?(0x0000)

hdlr

Handler Reference Box,媒體的播放過(guò)程信息。

視頻的hdlr,重點(diǎn)Component subtype: vide

1?14CF5A?Handler?Reference?(45?bytes)
2?14CF5A?Header?(8?bytes)
3?14CF5A?Size:?45?(0x0000002D)
4?14CF5E?Name:?hdlr
5?14CF62?Version:?0?(0x00)
6?14CF63?Flags:?0?(0x000000)
7?14CF66?Component?type:
8?14CF6A?Component?subtype:?vide
9?14CF6E?Component?manufacturer:
10?14CF72?Component?flags:?0?(0x00000000)
11?14CF76?Component?flags?mask:?0?(0x00000000)
12?14CF7A?Component?name:?VideoHandler

?頻的hdlr,Component subtype: soun,如果我們多個(gè)?軌的時(shí)候,Component name:粵語(yǔ)

1?14B3F2?Handler?Reference?(39?bytes)
2?14B3F2?Header?(8?bytes)
3?14B3F2?Size:?39?(0x00000027)
4?14B3F6?Name:?hdlr
5?14B3FA?Version:?0?(0x00)
6?14B3FB?Flags:?0?(0x000000)
7?14B3FE?Component?type:
8?14B402?Component?subtype:?soun
9?14B406?Component?manufacturer:
10?14B40A?Component?flags:?0?(0x00000000)
11?14B40E?Component?flags?mask:?0?(0x00000000)
12?14B412?Component?name:?粵語(yǔ)

我們分析的?件另?路?軌

1?14C0EA?Handler?Reference?(39?bytes)
2?14C0EA?Header?(8?bytes)
3?14C0EA?Size:?39?(0x00000027)
4?14C0EE?Name:?hdlr
5?14C0F2?Version:?0?(0x00)
6?14C0F3?Flags:?0?(0x000000)
7?14C0F6?Component?type:
8?14C0FA?Component?subtype:?soun
9?14C0FE?Component?manufacturer:
10?14C102?Component?flags:?0?(0x00000000)
11?14C106?Component?flags?mask:?0?(0x00000000)
12?14C10A?Component?name:?國(guó)語(yǔ)

minf

minf:Media Information Box,解釋track媒體數(shù)據(jù)的handler-specific信息。minf同樣是個(gè)container box,其內(nèi)部需要關(guān)注的內(nèi)容是stbl,這也是moov中最復(fù)雜的部分。stbl包含了媒體流每?個(gè)sample在?件中的offset,pts,duration等信息。想要播放?個(gè)mp4?件,必須根據(jù)stbl正確找到每個(gè)sample并送給解碼器。

?且需要注意的是,minf??的?容器,?頻和視頻軌是有區(qū)別的,?如視頻軌:vmhd, ?頻軌則為:smhd

vmhd

1?14CF8F?Video?Media?Header?(20?bytes)
2?14CF8F?Header?(8?bytes)
3?14CF8F?Size:?20?(0x00000014)
4?14CF93?Name:?vmhd
5?14CF97?Version:?0?(0x00)
6?14CF98?Flags:?1?(0x000001)
7?14CF9B?Graphic?mode:?0?(0x0000)
8?14CF9D?Graphic?mode?color?R:?0?(0x0000)
9?14CF9F?Graphic?mode?color?G:?0?(0x0000)
10?14CFA1?Graphic?mode?color?B:?0?(0x0000)

smhd

1?14B421?Sound?Media?Header?(16?bytes)
2?14B421?Header?(8?bytes)
3?14B421?Size:?16?(0x00000010)
4?14B425?Name:?smhd
5?14B429?Version:?0?(0x00)
6?14B42A?Flags:?0?(0x000000)
7?14B42D?Audio?balance:?0?(0x0000)
8?14B42F?Reserved:?0?(0x0000)

Stbl Insider

Sample Table Box,上?提到mdia中最主要的部分是存放?件中每個(gè)sample信息的stbl。在解析stbl前,我們需要區(qū)分chunk和sample這兩個(gè)概念。

在mp4?件中,sample是?個(gè)媒體流的基本單元,例如視頻流的?個(gè)sample代表實(shí)際的nal數(shù)據(jù)。chunk是數(shù)據(jù)存儲(chǔ)的基本單位,它是?系列sample數(shù)據(jù)的集合,?個(gè)chunk中可以包含?個(gè)或多的sample。

在這里插入圖片描述

?個(gè)chunk包含?個(gè)或多個(gè)sample

stbl?來(lái)描述每個(gè)sample的信息,包含以下?個(gè)主要的?box:

stsd

Sample Description Box,存放解碼必須的描述信息。

下圖示例中,對(duì)于h264的視頻流,其具體類型為 avc1 ,extensions中其中存放有sps,pps等解碼必要信息。

視頻的stsd

1?14CFCF?Sample?Description?(174?bytes)
2?14CFCF?Header?(8?bytes)
3?14CFCF?Size:?174?(0x000000AE)
4?14CFD3?Name:?stsd
5?14CFD7?Version:?0?(0x00)
6?14CFD8?Flags:?0?(0x000000)
7?14CFDB?Count:?1?(0x00000001)

??包含了avc1,avc1???包含了avcC和pasp

圖片
在這里插入圖片描述

avc1:包含了視頻Width、Height

avcC:包含了視頻編碼器相關(guān)的信息,包括sps、pps等信息

1?14CFDF?Video?(158?bytes)
2?14CFDF?Header?(8?bytes)
3?14CFDF?Size:?158?(0x0000009E)
4?14CFE3?Name:?avc1
5?14CFE7?Reserved:?0?(0x000000000000
0000)
6?14CFED?Data?reference?index:?1?(0x0001)
7?14CFEF?Version:?0?(0x0000)
8?14CFF1?Revision?level:?0?(0x0000)
9?14CFF3?Vendor:
10?14CFF7?Temporal?quality:?0?(0x00000000)
11?14CFFB?Spatial?quality:?0?(0x00000000)
12?14CFFF?Width:?1920?(0x0780)
13?14D001?Height:?800?(0x0320)
14?14D003?Horizontal?resolution:?4718592?(0x004800
00)
15?14D007?Vertical?resolution:?4718592?(0x004800
00)
16?14D00B?Data?size:?0?(0x00000000)
17?14D00F?Frame?count:?1?(0x0001)
18?14D011?Compressor?name?size:?0?(0x00)
19?14D012?Padding:?(31?bytes)
20?14D031?Depth:?24?(0x0018)
21?14D033?Color?table?ID:?65535?(0xFFFF)
22?14D035?AVC?decode?(56?bytes)
23?14D035?Header?(8?bytes)
24?14D035?Size:?56?(0x00000038)
25?14D039?Name:?avcC
26?14D03D?Version:?1?(0x01)
27?14D03E?Specific?(47?bytes)
28?14D03E?Profile:?100?(0x64)
29?14D03F?Compatible?profile:?0?(0x00)
30?14D040?Level:?40?(0x28)
31?14D041?Reserved:?63?(0x3F)?-?(6?bi
ts)
32?14D041?Size?of?NALU?length?minus?1:?3?(0x3)?-?(2?bits
)
33?14D042?Reserved:?7?(0x7)?-?(3?bits
)
34?14D042?seq_parameter_set?count:?1?(0x01)?-?(5?bit
s)
35?14D043?seq_parameter_set?(30?bytes)
36?14D043?Size:?28?(0x001C)
37?14D045?nal_ref_idc:?3?(0x3)?-?(2?bits
)
38?14D045?nal_unit_type:?7?(0x7)?-?(5?bits
)
39?14D046?profile_idc:?100?(0x64)
40?14D047?constraints?(1?bytes)
41?14D047?constraint_set0_flag:?No
42?14D047?constraint_set1_flag:?No
43?14D047?constraint_set2_flag:?No
44?14D047?constraint_set3_flag:?No
45?14D047?constraint_set4_flag:?No
46?14D047?constraint_set5_flag:?No
47?14D047?reserved_zero_2bits:?0?(0x0)
48?14D048?level_idc:?40?(0x28)?-?(8?bi
ts)
49?14D049?seq_parameter_set_id:?0?(0x0)
50?14D049?high?profile?specific?(1?bytes)
51?14D049?chroma_format_idc:?1?(0x1)?-?4:2:0
52?14D049?bit_depth_luma_minus8:?0?(0x0)
53?14D049?bit_depth_chroma_minus8:?0?(0x0)
54?14D049?qpprime_y_zero_transform_bypass_flag:?No
55?14D049?seq_scaling_matrix_present_flag:?No
56?14D04A?log2_max_frame_num_minus4:?0?(0x0)
57?14D04A?pic_order_cnt_type:?0?(0x0)
58?14D04A?log2_max_pic_order_cnt_lsb_minus4:?2?(0x2)
59?14D04A?max_num_ref_frames:?3?(0x3)
60?14D04B?gaps_in_frame_num_value_allowed_flag:?No
61?14D04B?pic_width_in_mbs_minus1:?119?(0x077)
62?14D04D?pic_height_in_map_units_minus1:?49?(0x031)
63?14D04E?frame_mbs_only_flag:?Yes
64?14D04E?direct_8x8_inference_flag:?Yes
65?14D04E?frame_cropping_flag:?No
66?14D04E?vui_parameters_present_flag?(17?bytes)
67?14D04E?vui_parameters_present_flag:?Yes
68?14D04E?aspect_ratio_info_present_flag?(2?bytes)
69?14D04E?aspect_ratio_info_present_flag:?Yes
70?14D04F?aspect_ratio_idc:?1?(0x01)?-?(8?bit
s)?-?1.000
71?14D050?overscan_info_present_flag:?No
72?14D050?video_signal_type_present_flag?(3?bytes)
73?14D050?video_signal_type_present_flag:?Yes
74?14D050?video_format:?5?(0x5)?-?(3?bits
)?-
75?14D050?video_full_range_flag:?0?(0x0)?-?(1?bits
)?-?Limited
76?14D050?colour_description_present_flag?(3?bytes)
77?14D050?colour_description_present_flag:?Yes
78?14D050?colour_primaries:?1?(0x01)?-?(8?bit
s)?-?BT.709
79?14D051?transfer_characteristics:?1?(0x01)?-?(8?bit
s)?-?BT.709
80?14D052?matrix_coefficients:?1?(0x01)?-?(8?bit
s)?-?BT.709
81?14D053?chroma_loc_info_present_flag:?No
82?14D054?timing_info_present_flag?(8?bytes)
83?14D054?timing_info_present_flag:?Yes
84?14D054?num_units_in_tick:?1?(0x00000001)?-
(32?bits)
85?14D058?time_scale:?48?(0x00000030)?-
(32?bits)
86?14D05C?fixed_frame_rate_flag:?Yes
87?14D05C?nal_hrd_parameters_present_flag:?No
88?14D05C?vcl_hrd_parameters_present_flag:?No
89?14D05C?pic_struct_present_flag:?No
90?14D05C?bitstream_restriction_flag?(3?bytes)
91?14D05C?bitstream_restriction_flag:?Yes
92?14D05C?motion_vectors_over_pic_boundaries_flag:?Yes
93?14D05D?max_bytes_per_pic_denom:?0?(0x0)
94?14D05D?max_bits_per_mb_denom:?0?(0x0)
95?14D05D?log2_max_mv_length_horizontal:?11?(0x0B)
96?14D05E?log2_max_mv_length_vertical:?11?(0x0B)
97?14D05F?max_num_reorder_frames:?2?(0x2)
98?14D05F?max_dec_frame_buffering:?4?(0x4)
99?14D061?pic_parameter_set?count:?1?(0x01)
100?14D062?pic_parameter_set?(6?bytes)
101?14D062?Size:?5?(0x0005)
102?14D064?nal_ref_idc:?3?(0x3)?-?(2?bits
)
103?14D064?nal_unit_type:?8?(0x8)?-?(5?bits
)
104?14D065?pic_parameter_set_id:?0?(0x0)
105?14D065?seq_parameter_set_id:?0?(0x0)
106?14D065?entropy_coding_mode_flag:?Yes
107?14D065?bottom_field_pic_order_in_frame_present_flag:?N
o
108?14D065?num_slice_groups_minus1:?0?(0x0)
109?14D065?num_ref_idx_l0_default_active_minus1:?3?(0x3)
110?14D066?num_ref_idx_l1_default_active_minus1:?0?(0x0)
111?14D066?weighted_pred_flag:?No
112?14D066?weighted_bipred_idc:?2?(0x2)?-?(2?bits
)
113?14D066?pic_init_qp_minus26:?0?(0x0)
114?14D067?pic_init_qs_minus26:?0?(0x0)
115?14D067?chroma_qp_index_offset:?0?(0x0)
116?14D067?deblocking_filter_control_present_flag:?Yes
117?14D067?constrained_intra_pred_flag:?No
118?14D067?redundant_pic_cnt_present_flag:?No
119?14D067?transform_8x8_mode_flag:?Yes
120?14D067?pic_scaling_matrix_present_flag:?No
121?14D067?second_chroma_qp_index_offset:?0?(0x0)
122?14D068?-------------------------
123?14D068?---?AVC,?accepted?---
124?14D068?-------------------------
125?14D069?Padding?:?(4?bytes)
126?14D06D?Pixel?Aspect?Ratio?(16?bytes)
127?14D06D?Header?(8?bytes)
128?14D06D?Size:?16?(0x00000010)
129?14D071?Name:?pasp
130?14D075?hSpacing:?1?(0x00000001)
131?14D079?vSpacing:?1?(0x00000001)

?頻的stsd

? Hexinator 分析,包含了?頻相關(guān)的信息,?如采樣率,通道數(shù)量等。

在這里插入圖片描述

stts

Time-to-Sample Box,定義每個(gè)sample時(shí)?。Time-To-Sample的table entry布局如下:

圖片
在這里插入圖片描述

stts table entry布局

--sample count:sample個(gè)數(shù)

--sample duration:sample持續(xù)時(shí)間

持續(xù)時(shí)間相同的連續(xù)sample可以放到?個(gè)entry?達(dá)到節(jié)省空間的?的。

這?先給出來(lái)的是視頻的stts,Number of entries,這個(gè)參數(shù)需要注意并不是sample的個(gè)數(shù),sample的實(shí)際數(shù)量需要將每個(gè)entry的sample count進(jìn)?累加才是真正的sample個(gè)數(shù)。

下圖示例中,第1個(gè)sample時(shí)間為3720,單位?mdhd的time scale進(jìn)?換算,?如視頻的是90000,此時(shí)換算成秒為3720/90000 = 0.0413333333333333秒。

1?14D07D?Time?to?Sample?(664?bytes)
2?14D07D?Header?(8?bytes)
3?14D07D?Size:?664?(0x00000298)
4?14D081?Name:?stts
5?14D085?Version:?0?(0x00)
6?14D086?Flags:?0?(0x000000)
7?14D089?Number?of?entries:?81?(0x00000051)
8?14D08D?Sample?Count:?1?(0x00000001)
9?14D091?Sample?Duration:?3720?(0x00000E88)
10?14D095?Sample?Count:?1?(0x00000001)
11?14D099?Sample?Duration:?3780?(0x00000EC4)
12?14D09D?Sample?Count:?1?(0x00000001)
13?14D0A1?Sample?Duration:?3690?(0x00000E6A)
14?14D0A5?Sample?Count:?2?(0x00000002)
15?14D0A9?Sample?Duration:?3780?(0x00000EC4)
16?14D0AD?Sample?Count:?1?(0x00000001)
17?14D0B1?Sample?Duration:?3690?(0x00000E6A)
18?14D0B5?Sample?Count:?2?(0x00000002)
19?14D0B9?Sample?Duration:?3780?(0x00000EC4)
20?14D0BD?Sample?Count:?1?(0x00000001)
21?14D0C1?Sample?Duration:?3690?(0x00000E6A)
22?14D0C5?Sample?Count:?2?(0x00000002)
23?14D0C9?Sample?Duration:?3780?(0x00000EC4)
24?14D0CD?Sample?Count:?1?(0x00000001)
25?14D0D1?Sample?Duration:?3690?(0x00000E6A)
26?14D0D5?Sample?Count:?2?(0x00000002)
27?14D0D9?Sample?Duration:?3780?(0x00000EC4)
28?14D0DD?Sample?Count:?1?(0x00000001)
29?14D0E1?Sample?Duration:?3690?(0x00000E6A)
30?........
31?14D305?Sample?Count:?2?(0x00000002)
32?14D309?Sample?Duration:?3780?(0x00000EC4)
33?14D30D?Sample?Count:?1?(0x00000001)
34?14D311?Sample?Duration:?3750?(0x00000EA6)
35?14D315?結(jié)束位置

再給出個(gè)?頻的stts,只是mdhd的time scale的差別,之前我們看到?頻為44100,則計(jì)算第?個(gè)sample的時(shí)間1024/44100=0.0232199546485261秒。

1?14B4C4?Time?to?Sample?(1048?bytes)
2?14B4C4?Header?(8?bytes)
3?14B4C4?Size:?1048?(0x00000418)
4?14B4C8?Name:?stts
5?14B4CC?Version:?0?(0x00)
6?14B4CD?Flags:?0?(0x000000)
7?14B4D0?Number?of?entries:?129?(0x00000081)
8?14B4D4?Sample?Count:?1?(0x00000001)
9?14B4D8?Sample?Duration:?1024?(0x00000400)
10?14B4DC?Sample?Count:?1?(0x00000001)
11?14B4E0?Sample?Duration:?1025?(0x00000401)
12?14B4E4?Sample?Count:?2?(0x00000002)
13?14B4E8?Sample?Duration:?1024?(0x00000400)
14?14B4EC?Sample?Count:?1?(0x00000001)
15?14B4F0?Sample?Duration:?1023?(0x000003FF)

stss

Sync Sample Box,同步sample表,存放關(guān)鍵幀列表,關(guān)鍵幀是為了?持隨機(jī)訪問(wèn)。

stss的table entry布局如下:

在這里插入圖片描述

下圖示例中,該視頻track有3個(gè)關(guān)鍵幀:

1?14D315?Sync?Sample?(28?bytes)
2?14D315?Header?(8?bytes)
3?14D315?Size:?28?(0x0000001C)
4?14D319?Name:?stss
5?14D31D?Version:?0?(0x00)
6?14D31E?Flags:?0?(0x000000)
7?14D321?entry-count:?3?(0x00000003)
8?14D325?number:1?darren補(bǔ)充(mediainfo沒(méi)有解析出來(lái))
9?14D329?number:54?darren補(bǔ)充
10?14D32D?number:103?darren補(bǔ)充

圖片
在這里插入圖片描述

stsc

Sample-To-Chunk Box,sample-chunk映射表。上?提到mp4通常把sample封裝到chunk中,?個(gè)chunk可能會(huì)包含?個(gè)或者?個(gè)sample。Sample-To-Chunk Atom的table entry布局如下圖所示:

在這里插入圖片描述

--First chunk:使?該表項(xiàng)的第?個(gè)chunk序號(hào)

--Samples per chunk:使?該表項(xiàng)的chunk中包含有?個(gè)sample

--Sample description ID:使?該表項(xiàng)的chunk參考的stsd表項(xiàng)序號(hào)

下圖示例中,可以看到該視頻track?共有1個(gè)stsc表項(xiàng),chunk序列1-x,每個(gè)chunk包含?個(gè)sample。這?則說(shuō)明每個(gè)chunk??只有?個(gè)sample(?個(gè)chunk是可以有多個(gè)sample)。

在這里插入圖片描述

stsz

Sample Size Box,指定了每個(gè)sample的size。Sample Size Atom包含兩sample總數(shù)和?張包含了每個(gè)sample size的表。

sample size 表的entry布局如下圖:

在這里插入圖片描述

下圖示例中,該視頻流?共有110個(gè)sample,第1個(gè)sample??為42072字節(jié),第2個(gè)sample??為7354個(gè)字節(jié)。

1?14D705?Sample?Size?(488?bytes)
2?14D705?Header?(8?bytes)
3?14D705?Size:?488?(0x000001E8)
4?14D709?Name:?stsz
5?14D70D?Version:?0?(0x00)
6?14D70E?Flags:?0?(0x000000)
7?14D711?Sample?Size:?0?(0x00000000)
8?14D715?Number?of?entries:?117?(0x00000075)

圖片
在這里插入圖片描述

stco

Chunk Offset Box,指定了每個(gè)chunk在?件中的位置,這個(gè)表是確定每個(gè)sample在?件中位置的關(guān)鍵。該表包含了chunk個(gè)數(shù)和?個(gè)包含每個(gè)chunk在?件中偏移位置的表。每個(gè)表項(xiàng)的內(nèi)存布局如下:

圖片
在這里插入圖片描述

需要注意,這?stco只是指定的每個(gè)chunk在?件中的偏移位置,并沒(méi)有給出每個(gè)sample在?件中的偏移。想要獲得每個(gè)sample的偏移位置,需要結(jié)合 Sample Size box(stsz)和Sample-To-Chunk(stsc) 計(jì)算后取得。

下圖示例中,該視頻流第1個(gè)chunk在?件中的偏移為4750,?這?是每個(gè)chunk只有?個(gè)sample,此時(shí)第?個(gè)sample的起始位置就為4750->0x1D78,數(shù)據(jù)??則參照stsz,第?個(gè)sample size為172818。

在這里插入圖片描述

?如偏移位置,7544->0x1D78

在這里插入圖片描述

如何計(jì)算sample偏移位置

上?提到通過(guò)stco并不能直接獲取某個(gè)sample的偏移位置,下?舉例說(shuō)明如何獲取某?個(gè)pts對(duì)應(yīng)的sample在?件中的位置。

?體需要以下步驟:

--1.將pts轉(zhuǎn)換到媒體對(duì)應(yīng)的時(shí)間坐標(biāo)系

--2.根據(jù)stts((decoding) time-to-sample)計(jì)算某個(gè)pts對(duì)應(yīng)的sample序號(hào)

--3.根據(jù)stsc(sample-to-chunk)計(jì)算sample序號(hào)存放在哪個(gè)chunk中

--4.根據(jù)stco(chunk offset)獲取對(duì)應(yīng)chunk在?件中的偏移位置

--5.根據(jù)stsz獲取sample在chunk內(nèi)的偏移位置并加上第4步獲取的偏移,計(jì)算出sample在?件中的偏移

例如,想要獲取3.64秒視頻sample數(shù)據(jù)在?件中的位置(使?我們上課?的2_audio_track_5s.mp4):

--1.根據(jù)time scale參數(shù),將3.64秒轉(zhuǎn)換為視頻時(shí)間軸對(duì)應(yīng)的3640000 (假如時(shí)間刻度不為毫秒) 視頻軌:time scale為90000,轉(zhuǎn)成對(duì)應(yīng)的時(shí)間戳為3.64秒*90000

--2.遍歷累加下表所示stts所有項(xiàng)?,計(jì)算得到3640000位于第110個(gè)sample = 327600

--3.計(jì)算出多個(gè)sample_deltas疊加才到了327600, 我們這?姑且按3780作為平均值計(jì)算,實(shí)際是37201+37801+36901+37802 ...... 這樣?直疊加進(jìn)?。327600/3780 = 86.66666666666667,取整為86

1?type?stts
2?size?664
3?flags?0
4?version?0
5?sample_counts?1,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,
2,1,2,1,2,1,2,1,2,1,1,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,
2,1,2,1,2,1,2,1,2,1,2,1,1,1,1,2,1,2,1,2,1,2,1
6?sample_deltas?3720,3780,3690,3780,3690,3780,3690,3780,3690,3780,
3690,3780,3690,3780,3690,3780,3690,3780,3690,3780,3690,3780,3690,3
780,3690,3780,3690,3780,3690,3780,3690,3780,3690,3780,3690,3780,37
50,3720,3780,3690,3780,3690,3780,3690,3780,3690,3780,3690,3780,369
0,3780,3690,3780,3690,3780,3690,3780,3690,3780,3690,3780,3690,3780
,3690,3780,3690,3780,3690,3780,3750,3720,3780,3690,3780,3690,3780,
3690,3780,3690,3780,3750

--4.查詢下表所示stsc所有項(xiàng)?,計(jì)算得到第86個(gè)sample位于第86個(gè)chunk,并且在該chunk中位于第1個(gè)sample(因?yàn)槲覀兊拇a流是每個(gè)chunk對(duì)應(yīng)了?個(gè)sample)

1?Property?name?Property?value
2?type?stsc
3?size?28
4?flags?0
5?version?0
6?first_chunk?1
7?samples_per_chunk?1
8?sample_description_index?1

--5.查詢下表所示stco所有項(xiàng)?,得到第86個(gè)chunk在?件中偏移位置為1004678。使?hexinator

1?Property?name?Property?value
2?type?stco
3?size?484
4?flags?0
5?version?0
6?chunk_offsets?7544,182562,204381,206907,209520,236820,240924,242
781,..............省略

--6.查詢下表所示stsz所有項(xiàng)?,得到第86個(gè)sample的size為20934。計(jì)算得到3.64秒視頻sample數(shù)據(jù)在?件中

offset:1004678+0 = 1004678

size:20934

1?Property?name?Property?value
2?type?stsz
3?size?488
4?flags?0
5?version?0
6?sample_sizes?172818,20829,722,567,25207,1946,822,674,23828,2141
,824,974,22426,2794..省略
7?sample_count?117

--驗(yàn)證:?編輯器打開(kāi)mp4?件,定位到?件偏移1004678位置,。 09分隔符,這?占?了6個(gè)字節(jié), 再看真正的數(shù)據(jù)區(qū)域,前4字節(jié)也為 NALU的?度0x000051bc=20924

總共占?的字節(jié)計(jì)算 4+2+4+20924 = 20934

圖片
在這里插入圖片描述

福大大架構(gòu)師每日一題

java當(dāng)死,golang當(dāng)立。最新面試題,涉及golang,rust,mysql,redis,云原生,算法,分布式,網(wǎng)絡(luò),操作系統(tǒng)。

495篇原創(chuàng)內(nèi)容

公眾號(hào)



音視頻八股文(10)-- mp4結(jié)構(gòu)的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
遂昌县| 仙游县| 南汇区| 民勤县| 广平县| 屯门区| 阿拉尔市| 新和县| 康定县| 潼南县| 广汉市| 南部县| 余庆县| 化州市| 大名县| 邓州市| 延吉市| 贵溪市| 汝阳县| 文水县| 邵武市| 清徐县| 介休市| 张家口市| 大庆市| 洪江市| 锡林郭勒盟| 浦北县| 龙江县| 重庆市| 淮滨县| 达拉特旗| 宁晋县| 大港区| 平果县| 花垣县| 邵阳市| 南靖县| 凤凰县| 龙海市| 盱眙县|