Recently, I have been working on a live streaming media app with my friends in my spare time. During this time, I collected some information and sorted it out. At the same time, I sometimes recorded solutions to some problems, -- technology is everywhere because of sharing! First, this chapter describes the format and meaning of the m3u8 file.
I. Concepts
1. playlist file
A M3U playlist is a text file consisting of multiple independent lines, each line is differentiated by carriage return/line feed. Each row can be a URI blank line or
It is a string starting with "#", and spaces can only be separated between different elements in a row.
A URI represents a media segment or "variant playlist file" (a maximum of one layer of nesting is supported, that is, one mm3u8 file is nested with another m3u8 ),
A "tag" starting with "# Ext". Otherwise, it indicates a comment and is ignored directly.
2. tags
# Extm3u: the first line of each m3u file must be this tag.
# Extinf: specifies the duration of each media segment (TS). This parameter is only valid for the Uris following it. The Uris of each two media segments are separated by this tag. The format is as follows:
# Extinf: <duration >,< title>:
Duration indicates the duration (in seconds) "durations must be integers if the Protocol version of the playlist file is less
Than 3 ", otherwise it can be a floating point number.
# EXT-X-BYTERANGE: indicates that a media segment is a part of a media URI resource, only valid for the media URI after it, the format is as follows:
# EXT-X-BYTERANGE: <n> [@ o]:
Where n represents the size of this interval, the offset of the O table in the URI; "The EXT-X-BYTERANGE tag appeared in version 4 of the Protocol".
# EXT-X-TARGETDURATION: specifies the maximum media segment length (seconds ). So # the specified time length in extinf must be smaller than or equal to the maximum
Value. This tag can only appear once in the entire playlist file (in the case of nesting, m3u8 with a real ts URL will usually appear ). The format is as follows:
# EXT-X-TARGETDURATION: <S>: s indicates the maximum number of seconds.
# EXT-X-MEDIA-SEQUENCE: each media URI in playlist only has a unique serial number, adjacent serial number + 1.
# EXT-X-MEDIA-SEQUENCE: <number>:
A media URI does not have to be included. If it does not exist, the default value is 0.
# EXT-X-KEY: indicates how to decode media segments. It applies to all media Uris before the tag appears next time. The format is as follows:
# EXT-X-KEY: <Attribute-List>:
None or AES-128. If it is none, the URI and IV attributes must not exist, if it is a AES-128 (Advanced Encryption
Standard), The URI must exist, and the IV can not exist.
For the AES-128, The keytag and Uri attributes represent a key file, which can be obtained through the URI, if no
IV (initialization vector), the serial number is used as the IV for encoding and decoding, and the serial number is assigned to 16 bytes of buffer at a high level. If
If there is IV, the value is changed to the hexadecimal number of 16 bytes.
# EXT-X-PROGRAM-DATE-TIME: Associate an absolute time or date with the first sample in a media segment, valid only for the next Meida Uri, in the following format:
# EXT-X-PROGRAM-DATE-TIME: <yyyy-mm-ddthh: mm: SSZ>
For example:
# EXT-X-PROGRAM-DATE-TIME: 2010-02-19t14: 54: 23.031 + 08: 00
# EXT-X-ALLOW-CACHE: whether to allow cache, which can appear anywhere in the playlist file, and can appear at most once, the effect is all media segments. The format is as follows:
# EXT-X-ALLOW-CACHE: <Yes | NO>
# EXT-X-PLAYLIST-TYPE: provides information about the variability of playlist, which is optional for the entire playlist file in the following format:
# EXT-X-PLAYLIST-TYPE: <event | VOD>: for VOD, the server cannot change the playlist file; for event
The server cannot change or delete any part of the playlist file, but you can add a new row to the file.
# EXT-X-ENDLIST: indicates the end of playlist, which can appear anywhere in playlist, but only one, in the following format:
# EXT-X-ENDLIST
# EXT-X-MEDIA: used to represent the same content in playlist without a language/translation version, for example, you can use three such tags to represent the sound of 3 without speech
Or use two tags to indicate that videos of different angles are in playlists. This tag exists independently in the following format:
# EXT-X-MEDIA: <Attribute-List>: The property list contains: URI, type, group-ID, language, name, default, Autoselect.
Uri: if not, it indicates that the selectable version of the tag description exists in the EXT-X-STREAM-INF of the primary playlist;
Type: audio and video;
Group-ID: mediatag with the same ID, forming a group of styles;
Language: identifies the primary language used in the rendition.
Name: The value is a quoted-string containing a human-readable description of the rendition. If the language attribute is present then description shocould be in that language.
Default: yes or no. The default value is no. If yes, the client uses this option to play the video unless you select it.
Autoselect: yes or no. The default value is no. If yes, the client selects the value based on the current playback environment (the user does not select the value based on his/her preference ).
The EXT-X-MEDIA tag appeared in version 4 of the Protocol.
O all EXT-X-MEDIA tags in the same group must have the same type
Attribute.
O all EXT-X-MEDIA tags in the same group must have different name
Attributes.
O a group must not have more than one member with a default
Attribute of yes.
O all members of a group whose Autoselect attribute has a value
Yes must have language [rfc5646] attributes with unique values.
O all members of a group with type = audio must use the same audio
Sample format.
O all members of a group with type = video must use the same video
Sample format.
# EXT-X-STREAM-INF: specify a media URI that contains multimedia information as playlist, generally used for m3u8 nesting, it is only followed by the URI
Effect. The format is as follows:
# EXT-X-STREAM-INF: <Attribute-List>
<URI>
Has the following attributes:
Bandwidth: Required bandwidth.
Program-ID: this value is a decimal integer that uniquely identifies a specific description within the playlist file range. In a playlist file
It can contain multiple tags with the same ID.
Codecs: not required.
Resolution: resolution.
Audio: This value must match the group-ID attribute value in the EXT-X-MEDIA tab of the audio category.
Video: Same as above
M3u8 consists of multiple formats. The following is an example:
# Extm3u
# EXT-X-ALLOW-CACHE: No
# EXT-X-TARGETDURATION: 10
# EXT-X-MEDIA-SEQUENCE: 8453235
# Extinf: 19,
Http: // 124.232.164.44: 80/iPad/160_15601164572/20130804075250.ts? Userid = VSNDNP-183061027101_160_15601_4572
# Extinf: 2,
Http: // 124.232.164.44: 80/iPad/160_15608244572/20130804075300.ts? Userid = VSNDNP-183061027101_160_15601_4572
# Extinf: 10,
Http: // 124.232.164.44: 80/iPad/160_15601164572/20130804075310.ts? Userid = VSNDNP-183061027101_160_15601_4572
In this case, the HTTP line is a complete link. Otherwise, the link must be spliced.
The next chapter will provide a draft of the HLS Chinese version.