What are the advantages of m3u8?
After searching online, there are different opinions. My personal understanding is that it can adapt to multiple bit rates. Based on network bandwidth, the client selects a file suitable for its own bit rate for playing, ensuring the smoothness of the video stream.
In iOS device and Mac, HTTP can be used for distribution. Among them, playlist is a m3u8 file extended by M3U, and the media file is a MPEG2-TS or AAC file (audio only ).
M3u8 files can be used in two scenarios:
Multi-bit rate adaptive stream,
# Extm3u
# EXT-X-STREAM-INF: Program-id = 1, bandwidth = 1280000
Http://example.com/low.m3u8
# EXT-X-STREAM-INF: Program-id = 1, bandwidth = 2560000
Http://example.com/mid.m3u8
# EXT-X-STREAM-INF: Program-id = 1, bandwidth = 7680000
Http://example.com/hi.m3u8
# EXT-X-STREAM-INF: Program-id = 1, bandwidth = 65000, codecs = "mp4a. 40.5"
Http://example.com/audio-only.m3u8
Single bit rate adaptive stream
# Extm3u
# EXT-X-TARGETDURATION: 5220
# Extinf: 5220,
Http://media.example.com/entire.ts
# EXT-X-ENDLIST
The International Standards Organization defines this. rfc doc:
Http://tools.ietf.org/html/draft-pantos-http-live-streaming-06
The m3u8 file is an extension of the M3U File. The extended keyword is defined in the RFC:
Medium:
# EXT-X-TARGETDURATION
Defines the maximum duration of each ts.
# EXT-X-MEDIA-SEQUENCE
Defines the serial number of the first file in the current m3u8 file. Each ts file has a fixed and unique serial number in the m3u8 file. This serial number is used to switch the bit rate during MBR for alignment.
# EXT-X-KEY
Defines the encryption method and the URL of the key file for obtaining 16 bytes of the key file to decode the TS file.
Attribute:
Method
URL
# EXT-X-PROGRAM-DATE-TIME
Absolute Time of the first file
# EXT-X-ALLOW-CACHE
Whether to agree to the cache.
# EXT-X-ENDLIST
Indicates the end of The m3u8 file. Live m3u8 does not have this tag.
# EXT-X-STREAM-INF
Attribute:
Bandwidth specifies the bit rate
Unique id of Program-ID
Codecs specifies the stream encoding type
# EXT-X-DISCONTINUITY
When this tag is encountered, the following attributes are changed:
File Format
Number and type of tracks
Encoding Parameters
Encoding Sequence
Timestamp Sequence
# EXT-X-VERSION this attribute can not be used, can not
M3u8 is divided into top-level m3u8 and second-level m3u8. Top-level m3u8 is mainly applicable to multiple bit rates. Second-level m3u8 is the real slicing file,
By default, the client will first select the request with the highest bit rate. if it finds that the bit rate does not reach, it will request a stream with a low bit rate.
A top-level m3u8 file in actual use is as follows:
# Extm3u
# EXT-X-STREAM-INF: Program-id = 201273221265, bandwidth = 358400
11. m3u8
# EXT-X-STREAM-INF: Program-id = 201273221265, bandwidth = 972800
22. m3u8
The above top-level m3u8 file defines two level-2 files, 11. m3u8 and 22. m3u8. The client will choose one of them to get its content.
The content of level 2 m3u8 files is as follows:
# 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-0000ts
# Extinf: 8,
1-22.ts
# Extinf: 9,
1-24.ts
# Extinf: 3,
1-26.ts
# EXT-X-ENDLIST
After the client obtains the above level 2 m3u8 file, it will continue to request the file in it, and then it will be able to play back.
The above describes the on-demand video and live video. In m3u8 files, the property tells the live video, and the client regularly requests a new m3u8 file.
Http://www.ioncannon.net/programming/452/iphone-http-streaming-with-ffmpeg-and-an-open-source-segmenter/
M3u8 format explanation and Practical Application Analysis