M3U8格式講解及實際應用分析

2021-06-21 09:08:27 字數 3025 閱讀 7098

在ios device和mac上可以用http的方式進行分發,其中playlist標準為由m3u擴充套件而來的m3u8檔案,**檔案為mpeg2-ts或者aac檔案(audio only)。

m3u8檔案有兩種應用場景:

多位元速率適配流,

#extm3u

#ext-x-stream-inf:program-id=1,bandwidth=1280000

#ext-x-stream-inf:program-id=1,bandwidth=2560000

#ext-x-stream-inf:program-id=1,bandwidth=7680000

#ext-x-stream-inf:program-id=1,bandwidth=65000,codecs="mp4a.40.5"

單位元速率適配流
#extm3u

#ext-x-targetduration:5220

#extinf:5220,

#ext-x-endlist

國際標準組織對此的定義 rfc doc:

m3u8 檔案是m3u檔案的擴充套件。在該rfc中定義了擴充套件的關鍵字:

其中:

#ext-x-targetduration
定義每個ts的最大的duration。
#ext-x-media-sequence
定義當前m3u8檔案中第乙個檔案的序列號,每個ts檔案在m3u8檔案中都有固定唯一的序列號,該序列號用於在mbr時切換位元速率進行對齊。
#ext-x-key

定義加密方式和key檔案的url,用於取得16bytes的key檔案解碼ts檔案。

屬性:
method
url
#ext-x-program-date-time
第乙個檔案的絕對時間

#ext-x-allow-cache

是否允許cache。
#ext-x-endlist
表明m3u8檔案的結束。live m3u8沒有該tag。
#ext-x-stream-inf
屬性:
bandwidth              指定位元速率

program-id            唯一id

codecs                    指定流的編碼型別

#ext-x-discontinuity
當遇到該tag的時候說明以下屬性發生了變化:
file format
number and type of tracks
encoding parameters
encoding sequence
timestamp sequence

#ext-x-version             該屬性用不用都可以,可以沒有

m3u8分頂級m3u8和二級m3u8, 頂級m3u8主要是做多位元速率適配的, 二級m3u8才是真正的切片檔案,

客戶端缺省會首先選擇位元速率最高的請求,如果發現位元速率達不到,會請求郊低位元速率的流

乙個實際使用中的頂級m3u8檔案如下 :

#extm3u

#ext-x-stream-inf:program-id=201273221265,bandwidth=358400

11.m3u8

#ext-x-stream-inf:program-id=201273221265,bandwidth=972800

22.m3u8

上面頂級m3u8檔案中又定義了 11.m3u8 和 22.m3u8 兩個二級檔案,客戶端會選擇其中乙個獲取其內容。

二級m3u8檔案內容如下:

#extm3u

#ext-x-version:1

#ext-x-targetduration:10

#ext-x-media-sequence:0

#extinf:3,

1-4.ts

#extinf:8,

1-6.ts

#extinf:8,

1-8.ts

#extinf:8,

1-10.ts

#extinf:8,

1-12.ts

#extinf:8,

1-14.ts

#extinf:8,

1-16.ts

#extinf:9,

1-18.ts

#extinf:6,

1-20.ts

#extinf:8,

1-22.ts

#extinf:9,

1-24.ts

#extinf:3,

1-26.ts

#ext-x-endlist

上面講解的是點播的情況,直播的情況,m3u8檔案裡面會有屬性告訴是直播,客戶端會定時來請求新的m3u8檔案。

出自:

M3U8格式講解及實際應用分析

在ios device和mac上可以用http的方式進行分發,其中playlist標準為由m3u擴充套件而來的m3u8檔案,檔案為mpeg2 ts或者aac檔案 audio only m3u8檔案有兩種應用場景 多位元速率適配流,extm3u ext x stream inf program id ...

M3U8格式解說及實際應用分析

在ios device和mac上能夠用http的方式進行分發,當中playlist標準為由m3u擴充套件而來的m3u8檔案,檔案為mpeg2 ts或者aac檔案 audio only m3u8檔案有兩種應用場景 多位元速率適配流,extm3u ext x stream inf program id ...

HLS M3U8格式講解及實際應用分析

在ios device和mac上可以用http的方式進行分發,其中playlist標準為由m3u擴充套件而來的m3u8檔案,檔案為mpeg2 ts或者aac檔案 audio only m3u8檔案有兩種應用場景 多位元速率適配流,extm3u ext x stream inf program id ...