Concept 01

M3U8 Playlists

HLS is, at its core, just plain-text files. A playlist (.m3u8) is a list of instructions that tells the player what to fetch and in what order. There are two kinds: a master playlist that lists quality variants, and media playlists that list the actual video segments.

The master playlist

The entry point. Each EXT-X-STREAM-INF line describes one quality variant — its bandwidth, resolution, and codecs — followed by a URL to that variant's media playlist. This is exactly what this sandbox serves.

#EXTM3U
#EXT-X-VERSION:3

#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="English",
  LANGUAGE="en",DEFAULT=YES,URI="subs_en.m3u8"

#EXT-X-STREAM-INF:BANDWIDTH=5144131,RESOLUTION=1920x1080,
  CODECS="avc1.640028,mp4a.40.2",SUBTITLES="subs"
stream_0.m3u8

#EXT-X-STREAM-INF:BANDWIDTH=3130425,RESOLUTION=1280x720,
  CODECS="avc1.64001f,mp4a.40.2",SUBTITLES="subs"
stream_1.m3u8
/hls/master.m3u8 (abridged)

A media playlist

Each variant has its own playlist listing the .ts segments. EXTINF gives each segment's duration; EXT-X-ENDLIST marks a finished VOD asset.

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:8
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-KEY:METHOD=AES-128,URI="/hls/enc.key",IV=0xa47b...
#EXTINF:8.333333,
stream_0_000.ts
#EXTINF:8.333333,
stream_0_001.ts
#EXTINF:3.333333,
stream_0_002.ts
#EXT-X-ENDLIST
/hls/stream_0.m3u8

How a player parses it

  1. 1

    Fetch the master playlist

    The player downloads master.m3u8 and reads every EXT-X-STREAM-INF to build a list of available quality levels.

  2. 2

    Pick a starting variant

    Based on the current bandwidth estimate, it chooses one variant and fetches that variant's media playlist.

  3. 3

    Download segments in order

    It walks the EXTINF list, downloading each .ts segment and appending it to a buffer.

  4. 4

    Re-evaluate continuously

    After each segment the player re-checks bandwidth and can switch to a different variant's playlist mid-stream — that's adaptive bitrate.

Key tags at a glance

#EXTM3U
Required first line — marks the file as an M3U playlist.
#EXT-X-VERSION
The HLS protocol version the playlist uses.
#EXT-X-STREAM-INF
Describes one quality variant (master playlist).
#EXT-X-TARGETDURATION
Maximum segment length, in seconds (media playlist).
#EXTINF
Duration of the segment on the next line.
#EXT-X-KEY
Encryption method + key location for segments.
#EXT-X-MEDIA
Alternate renditions: subtitles, audio, etc.
#EXT-X-ENDLIST
No more segments — this is a complete VOD.