M3U8 is essentially a UTF-8 encoded plain text file that complies with the HLS protocol specification. Its core is not simply a list of URLs, but a standardized syntax system containing specific tags and parameters. Players parse these tags to implement complex playback logic.
1. Basic Structure: Mandatory Protocol Specifications
A valid M3U8 file must start with `#EXTM3U` as the first line, which is the identification header of the HLS protocol. Files lacking this identifier cannot be recognized by standard players. The main body of the file consists of two types of content: tag lines starting with `#` (used to define metadata and control instructions) and ordinary URL lines (pointing to TS segment files or sub-M3U8 files).
2. Core Tags: Key Instructions for Controlling Playback
The core capabilities of M3U8 are realized through a series of standardized tags. The commonly used core tags and their functions are as follows:
• #EXT-X-VERSION: Specifies the HLS protocol version (e.g., V3/V4/V5), with different versions supporting different features;
• #EXT-X-TARGETDURATION: Defines the maximum duration of segments (unit: seconds), based on which players set buffering strategies;
• #EXTINF: Specifies the duration of a single TS segment (format: `#EXTINF:10.0,`), the most basic segment description tag;
• #EXT-X-MEDIA-SEQUENCE: Defines the starting sequence number of segments, used for resuming playback from breakpoints and locating live broadcast segments;
• #EXT-X-ENDLIST: Identifies the end of a video-on-demand (VOD) file, not present in live streams;
• #EXT-X-STREAM-INF: Used for multi-bitrate adaptation, pointing to sub-M3U8 files of different bitrates.
3. Two Core Types: Structural Differences Between VOD and Live Broadcast
A VOD M3U8 is a static file containing a complete list of segments and the `#EXT-X-ENDLIST` end tag; a live broadcast M3U8 is a dynamically updated file without an end tag. It manages the addition and deletion of segments through the `#EXT-X-MEDIA-SEQUENCE` and `#EXT-X-DISCONTINUITY` tags, and players refresh regularly to obtain the latest segment list.