HLS Protocol Explained: From Segments to Playback
In-depth technical explanation of the HLS protocol. Master playlists, media playlists, segments, encryption, and the complete playback flow.
HLS Protocol Layers
The HLS protocol operates on three layers:
1. Content Preparation Layer
- Video is encoded at multiple bitrates using codecs like H.264, HEVC, or AV1
- Audio is encoded separately, often in AAC or MP3
- Content is fragmented into segments of equal duration (typically 6 seconds)
- Each segment is independently decodable (keyframe at the start of each segment)
2. Playlist Layer
- Master playlist describes available variants (bitrate, resolution, codec)
- Media playlists list segment URLs for each variant
- Additional playlists for audio tracks, subtitles, and I-frames
3. Delivery Layer
- All files served over HTTP/HTTPS
- Standard HTTP caching applies at every level
- Playlists may redirect to variant playlists based on client capabilities
Playback Flow
- Player fetches the master playlist URL
- Player parses the available variant streams and their bandwidth requirements
- Player starts with the lowest variant or uses previously stored bandwidth estimates
- Player fetches the media playlist for the selected variant
- Player begins downloading segments in sequence
- As segments download, the player feeds them to the media buffer via MSE
- The ABR algorithm continuously monitors download speed and buffer health
- When switching quality, the player fetches the new variant's playlist and aligns segments
- Playback continues seamlessly until the last segment (VOD) or indefinitely (live)
Encryption and DRM
HLS supports AES-128 encryption for content protection. The encryption key is referenced in the playlist via the #EXT-X-KEY tag:
#EXT-X-KEY:METHOD=AES-128,URI="https://keyserver.com/key.bin",IV=0x...
The player fetches the key before decrypting segments. For commercial DRM, HLS supports FairPlay Streaming (Apple's DRM), which integrates with iOS, macOS, and tvOS for protected content delivery.
Server Requirements
An HLS server needs to:
- Serve .m3u8 files with Content-Type: application/vnd.apple.mpegurl
- Serve .ts files with Content-Type: video/mp2t
- Support byte-range requests (optional, used by some implementations)
- Configure CORS headers for cross-origin playback
- Handle concurrent connections for many viewers
Related Articles
What Is HLS Streaming? A Complete Beginner's Guide
Learn what HLS (HTTP Live Streaming) is, how it works, and why it's the most popular streaming protocol for web video delivery.
How HLS Streaming Works: Protocol Explained in Detail
Deep dive into the HLS protocol. Understand master playlists, media segments, adaptive bitrate, and the complete HLS delivery pipeline.