当前位置:网站首页>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 .
边栏推荐
- Preliminary analysis of smart microwave radar module
- 2022 G3 boiler water treatment registration examination and G3 boiler water treatment examination papers
- Can you draw with turtle?
- How to switch between dual graphics cards of notebook computer
- Mysql database - Advanced SQL statement (I)
- Leetcode: a single element in an ordered array
- The reason why the computer runs slowly and how to solve it
- Sed、Awk
- [actual combat record] record the whole process of the server being attacked (redis vulnerability)
- 2022 free examination questions for safety management personnel of hazardous chemical business units and reexamination examination for safety management personnel of hazardous chemical business units
猜你喜欢
On my first day at work, this API timeout optimization put me down!
Redis single thread and multi thread
Morning flowers and evening flowers
The reason why the computer runs slowly and how to solve it
Code in keil5 -- use the code formatting tool astyle (plug-in)
How to switch between dual graphics cards of notebook computer
Data consistency between redis and database
What are the common computer problems and solutions
Programming language (2)
2022 electrician (elementary) examination questions and electrician (elementary) registration examination
随机推荐
WiFi 2.4g/5g/6g channel distribution
[template summary] - binary search tree BST - Basics
Report on the current situation and development trend of ethoxylated sodium alkyl sulfate industry in the world and China Ⓞ 2022 ~ 2027
Oil monkey plug-in
Is the account opening of Guotai Junan Securities safe and reliable? How to open Guotai Junan Securities Account
In 2022, 6G development has indeed warmed up
Overview of Yunxi database executor
Exness: the Central Bank of England will raise interest rates again in March, and inflation is coming
Awk getting started to proficient series - awk quick start
Take you to master the formatter of visual studio code
国泰君安证券开户是安全可靠的么?怎么开国泰君安证券账户
AST (Abstract Syntax Tree)
C deep anatomy - the concept of keywords and variables # dry inventory #
Leetcode week 4: maximum sum of arrays (shape pressing DP bit operation)
Wisdom tooth technology announced that it had completed the round D financing of US $100million and had not obtained a valid patent yet
Cesium terrain clipping draw polygon clipping
Investment planning analysis and prospect prediction report of China's satellite application industry during the 14th five year plan Ⓑ 2022 ~ 2028
JS closure knowledge points essence
Is it safe and reliable to open an account and register for stock speculation? Is there any risk?
How can enterprises and developers take advantage of the explosion of cloud native landing?