当前位置:网站首页>Simple solution of m3u8 file format
Simple solution of m3u8 file format
2022-07-03 22:27:00 【Back end coder】
m3u8 File format details
M3U8 yes Unicode Version of M3U, use UTF-8 code ."M3U" and "M3U8" The files are all used by apple HTTP Live Streaming(HLS) The basis of the protocol format , This protocol format can be used in iPhone and Macbook And other devices .
The above text definition comes from Wikipedia . You can see ,m3u8 The file is actually HTTP Live Streaming( Abbreviation for HLS) Part of the agreement , and HLS It's based on HTTP Streaming media network transmission protocol .
HLS The working principle of is to divide the whole flow into small ones based on HTTP To download , Download only a few at a time . When the media stream is playing , Clients can choose to download the same resources at different rates from many different alternate sources , Allow streaming sessions to adapt to different data rates . When starting a streaming session , The client will download a extended M3U (m3u8) playlist file , Used to find available media streams .HLS Just ask for basic HTTP message , With real-time transmission protocol (RTP) Different ,HLS Can go through any permit HTTP Data through firewalls or proxy servers . It's also easy to use content distribution networks to stream media .
In short ,HLS It's a new generation of streaming media transport protocol , Its basic principle is to partition a large media file , Record the partition file resource path in m3u8 file ( namely playlist) Inside , With some additional descriptions ( For example, the multi bandwidth information of the resource ···) Used to provide to the client . The client uses the m3u8 File to get the corresponding media resources , Play it .
therefore , Client acquisition HLS Streaming files , Mainly right m3u8 File parsing operation .
that , Here is a brief introduction m3u8 file .
M3U8 File info
m3u8 The file is essentially a play list (playlist), It could be a media play list (Media Playlist), Or a master list (Master Playlist). But no matter what kind of playlist , All the words inside are utf-8 code .
When m3u8 Files as media playlists (Meida Playlist) when , Its internal information records a series of media fragment resources , Play the clip resource in sequence , The multimedia resources can be displayed completely . The format is as follows :
#EXTM3U #EXT-X-TARGETDURATION:10 #EXTINF:9.009, http://media.example.com/first.ts #EXTINF:9.009, http://media.example.com/second.ts #EXTINF:3.003, http://media.example.com/third.ts
For VOD , The client only needs to download the above fragment resources in order , Play in sequence . And for live broadcast , The client needs Periodically re request The m3u8 file , See if there is new clip data to download and play .
When m3u8 As an anchor list (Master Playlist) when , It provides multiple stream list resources of the same media resource (Variant Stream). The format is as follows :
#EXTM3U #EXT-X-STREAM-INF:BANDWIDTH=150000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2" http://example.com/low/index.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=240000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2" http://example.com/lo_mid/index.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=440000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2" http://example.com/hi_mid/index.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=640000,RESOLUTION=640x360,CODECS="avc1.42e00a,mp4a.40.2" http://example.com/high/index.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=64000,CODECS="mp4a.40.5" http://example.com/audio/index.m3u8
The standby stream resource specifies a variety of different bit rates , Media playlists in different formats , also , The standby stream resource can also provide different versions of resource content at the same time , For example, audio files in different languages , Video files taken from different angles, etc . Customers can select appropriate bitstream resources according to different network states , And it's best to choose the appropriate resource content according to user preferences .
Some precautions
- There are two kinds of requests m3u8 Playlist method : One is to pass. m3u8 Of URI For the request , Then the document must be in .m3u8 or .m3u ending ; Two is through HTTP For the request , Then the request header
Content-Type
Must be set toapplication/vnd.apple.mpegurl
perhapsaudio/mpegurl
. - Empty lines and comment lines are ignored in parsing .
- Media play lists (Media Playlist) The total duration of stream resources is the sum of the duration of each slice resource .
- Bit rate of each slice (bit rate) Is the size of the slice divided by its corresponding duration (EXTINF A specified length of time ).
- The same attribute in the attribute list of a tag
AttributeName
Only once . - EXT-X-TARGETDURATION The specified duration must not be changed . Usually, the duration specified by this value is 10 second .
- For the designated EXT-X-I-FRAMES-ONLY And The first media segment ( Or the first one to follow EXT-X-DISCONTINUITY Fragments of ) Its resources do not immediately carry slices of the media initialization block , Labels should be added EXT-X-MAP Specify the media initialization block access .
- Use EXT-X-MAP The label contains labels EXT-X-I-FRAMES-ONLY Required compatible version number EXT-X-VERSION Be greater than or equal to 5; Use only EXT-X-MAP The required compatible version number must be greater than or equal to 6.
- By label EXT-X-MAP The declared media initialization block can be used AES-128 Method to encrypt , here , Act on EXT-X-MAP Labeled EXT-X-KEY The label must be set IV attribute .
- With attributes END-ON-NEXT=YES The label of EXT-X-DATERANGE Must carry CLASS attribute , But you can't carry DURATION and END-DATE attribute . The rest have the same CLASS The label of EXT-X-DATERANGE Overlapping date ranges cannot be specified .
- If the date range is not specified DURATION,END_DATE,END-ON-NEXT=YES Attribute , Then it will last (duration) Unknown , Even if it is set PLANNED-DURATION attribute .
- If the playlist is set EXT-X-DATERANGE label , Must be set at the same time EXT-X-PROGRAM-DATE-TIME label .
- If the playlist is set to have the same ID Two of the attribute values EXT-X-DATERANGE label , For the same attribute name , Between the two EXT-X-DATERANGE The corresponding values in must be consistent .
- If EXT-X-DATERANGE Also set up DURATION and END-DATE attribute , be END-DATE Attribute value must be equal to START-DATE Attribute value plus DURATION Property value .
- EXT-X-MEDIA-SEQUENCE The tag must appear before the first slice of the playlist .
- EXT-X-DISCONTINUITY-DEQUENCE The tag must appear before the first slice of the playlist .
- EXT-X-DISCONTINUITY-DEQUENCE The label must appear in any EXT-X-DISCONTINUITY Before the label .
- m3u8 File if not set EXT-X-PLAYLIST-TYPE label , Then the playlist can be changed at any time . such as , You can update or delete media clips in the playlist .
- Every EXT-X-I-FRAME-STREAM-INF The label must contain a BANDWIDTH and URI attribute .
- Every EXT-X-SESSION-DATA Labels must contain a VALUE or URI attribute , But not both .
- A playlist can contain multiple players with the same DATA-ID Attribute EXT-X-SESSION-DATA label . However, it cannot contain more than one carrying the same DATA-ID Same as LANGUAGE Attribute EXT-X-SESSION-DATA label .
- If set EXT-X-SESSION-KEY, So METHOD,KEYFORMAT and KEYFORMATVERSIONS The attribute value must be the same as any URI Of EXT-X-KEY The tag values are the same .
- If multiple backup streams or multilingual streams use the same encryption key and format , You should set EXT-X-SESSION-KEY label .
- The main playlist must not have multiple settings with the same METHOD,URI,IV,KEYFORMAT and KEYFORMATVERSIONS Attribute value EXT-X-SESSION-KEY label .
边栏推荐
- js demo 计算本年度还剩下多少天
- Opengauss database log management guide
- IDENTITY
- Shell script three swordsman awk
- 国泰君安证券开户是安全可靠的么?怎么开国泰君安证券账户
- The 2022 global software R & D technology conference was released, and world-class masters such as Turing prize winners attended
- How to solve win10 black screen with only mouse arrow
- Data consistency between redis and database
- [sg function]split game (2020 Jiangxi university student programming competition)
- Bluebridge cup Guoxin Changtian single chip microcomputer -- detailed explanation of schematic diagram (IV)
猜你喜欢
The overseas listing of Shangmei group received feedback, and brands such as Han Shu and Yiye have been notified for many times and received attention
Electronic tube: Literature Research on basic characteristics of 6j1
2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions
[automation operation and maintenance novice village] flask-2 certification
To rotate 90 degrees clockwise and modify the video format
540. Single element in ordered array
BUUCTF,Misc:LSB
In 2022, 6G development has indeed warmed up
Blue Bridge Cup -- guess age
How to solve win10 black screen with only mouse arrow
随机推荐
IPhone development swift foundation 09 assets
1068. Consolidation of ring stones (ring, interval DP)
Teach you how to run two or more MySQL databases at the same time in one system
C deep anatomy - the concept of keywords and variables # dry inventory #
540. Single element in ordered array
Is the account opening of Guotai Junan Securities safe and reliable? How to open Guotai Junan Securities Account
Go language slice interview real question 7 consecutive questions
Bluebridge cup Guoxin Changtian single chip microcomputer -- hardware environment (I)
Why should enterprises do more application activities?
Pat grade A - 1164 good in C (20 points)
The latest analysis of crane driver (limited to bridge crane) in 2022 and the test questions and analysis of crane driver (limited to bridge crane)
Code in keil5 -- use the code formatting tool astyle (plug-in)
4 environment construction -standalone ha
The overseas listing of Shangmei group received feedback, and brands such as Han Shu and Yiye have been notified for many times and received attention
Data consistency between redis and database
Plug - in Oil Monkey
[sg function] 2021 Niuke winter vacation training camp 6 h. winter messenger 2
Bluebridge cup Guoxin Changtian single chip microcomputer -- detailed explanation of schematic diagram (IV)
How to obtain opensea data through opensea JS
Blue Bridge Cup Guoxin Changtian MCU -- program download (III)