📊

M3U8 File Format Explained

M3U8 File Basic Structure

An M3U8 file is a plain text file using UTF-8 encoding. The first line of the file must be #EXTM3U, which is the identifier for M3U8 files, telling the player that this is an M3U8 playlist file.

Main Tag Types

M3U8 files contain various tags, each with specific functions:

1. #EXTM3U

File header identifier, must appear on the first line of the file. Indicates this is an M3U8 playlist file.

2. #EXT-X-VERSION

Specifies the version number of the M3U8 file, for example #EXT-X-VERSION:3. Different versions support different features.

3. #EXTINF

Media segment information tag, format: #EXTINF:duration,title. Where:

  • Duration: Playback duration of the segment (seconds), can be integer or decimal
  • Title: Optional segment title

The next line must be the URL address of that segment.

4. #EXT-X-STREAM-INF

Multi-bitrate master playlist tag, used to specify streams of different bitrates. Contains the following attributes:

  • BANDWIDTH: Bitrate (bits per second)
  • RESOLUTION: Resolution (e.g., 1920x1080)
  • CODECS: Codec format (e.g., avc1.4d001f,mp4a.40.2)
  • NAME: Name of the stream
5. #EXT-X-PLAYLIST-TYPE

Playlist type, can be:

  • VOD: Video On Demand, playlist does not change
  • EVENT: Event stream, playlist continues to update
6. #EXT-X-TARGETDURATION

Specifies the maximum duration (seconds) of each media segment, for example #EXT-X-TARGETDURATION:10 means each segment is at most 10 seconds.

7. #EXT-X-MEDIA-SEQUENCE

Media sequence number, indicates the sequence number of the first segment in the playlist, usually starting from 0.

8. #EXT-X-ENDLIST

Indicates the end of the playlist, no new segments will be added. Usually appears in Video On Demand (VOD) playlists.

9. #EXT-X-KEY

Encryption key information for encrypted streams. Contains:

  • METHOD: Encryption method (e.g., AES-128, NONE)
  • URI: URL of the key file
  • IV: Initialization vector (optional)

Playlist Types

Master Playlist

Contains multiple streams of different bitrates for adaptive bitrate playback. Example:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=1280000,RESOLUTION=854x480
stream_480p.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2560000,RESOLUTION=1280x720
stream_720p.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=5120000,RESOLUTION=1920x1080
stream_1080p.m3u8
Media Playlist

Contains the actual list of video segments. Example:

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10.0,
segment_000.ts
#EXTINF:10.0,
segment_001.ts
#EXTINF:10.0,
segment_002.ts
#EXT-X-ENDLIST

Relative and Absolute Paths

URLs in M3U8 files can be:

  • Absolute path: Complete URL, such as https://example.com/video/segment.ts
  • Relative path: Path relative to the M3U8 file location, such as segment.ts or ../video/segment.ts

Common Issues and Debugging

When editing or debugging M3U8 files, note:

  • Ensure the file uses UTF-8 encoding
  • The first line must be #EXTM3U
  • Each #EXTINF tag must be immediately followed by a URL
  • Special characters in URLs need to be properly encoded
  • Check that segment file paths are correct
  • Ensure the server supports CORS (Cross-Origin Resource Sharing)

Manual Editing of M3U8 Files

You can open and edit M3U8 files with any text editor. When editing, note:

  • Keep tag formats correct
  • Ensure URL addresses are accessible
  • Verify segment duration information is accurate
  • Save using UTF-8 encoding

By understanding the structure and tag meanings of M3U8 files, you can better understand how streaming media playback works and manually edit or debug playlist files when needed.

← Back to Articles