HLS Streaming Protocol: m3u8
For easier understanding, this article covers topics in order: “Streaming Protocols” → “HLS” → “M3U8.”
Their relationship:
- HLS is a streaming media transport protocol
- M3U8 is a component within HLS transport content
Streaming Media Protocols
Common Streaming Protocols
Streaming media delivers audio and video content in real time as data streams. The key technology is stream transmission.
Streaming protocols define how stream transmission works, specifying how streaming servers and clients communicate.
Major streaming protocols:
- RTMP (Real Time Messaging Protocol): TCP-based FLV chunked message protocol, designed for Flash clients.
- HTTP-FLV: HTTP long-connection-based FLV chunked tag protocol, usable for both VOD and live streaming.
- HLS (HTTP Live Streaming): HTTP-based MP4 segment protocol by Apple, supporting both VOD and live streaming; each segment download requires a separate HTTP request.
This article covers only HLS in detail, not RTMP or RTSP.
Streaming Encryption Principles
Most streaming protocols can be divided into two parts: segmentation and encryption.
Segmentation splits a complete video stream into consecutive video segments. Different protocols differ in segment size and video container format.
Encryption encrypts each video segment using symmetric encryption — encrypted server-side, decrypted client-side, with restricted access to decryption keys.
AES encryption is typically used.
Why Symmetric Encryption?
Symmetric encryption is relatively efficient; asymmetric encryption is slower but more secure. Streaming scenarios demand high real-time performance with large data volumes, so the more efficient symmetric encryption is preferred.
Similar patterns appear elsewhere — for example, in HTTPS: content transmission uses symmetric encryption (TLS) for efficiency, while certificate verification uses asymmetric encryption (SSL) for security.
HLS
HLS (HTTP Live Streaming) is an HTTP-based streaming protocol proposed by Apple for real-time audio/video transmission, now widely used in both VOD and live streaming.
Reference: HTTP Live Streaming Document
How It Works
The complete HLS architecture has three parts:
- Server: Encodes and segments the video stream into consecutive MPEG-TS segments, providing corresponding M3U8 media playlist and index files.
- CDN: Standard web servers that receive client requests and distribute resources.
- Client: Downloads the m3u8 index file first, selects an appropriate m3u8 media playlist based on bandwidth, then sequentially downloads all TS segments.
The complete HLS process:

Six stages:
- Capture media source
- Media encoder encodes the source
- Encoded content passes to the segmenter as MPEG-2 transport stream
- Stream Segmenter splits media into multiple
Media Segments, creating correspondingMedia PlaylistandMaster Playlistfiles - Upload: Resources uploaded to HTTP server
- Playback: Client requests playback
Structure
After step 4’s processing, the complete structure consists of Master Playlist, Media Playlist, and Media Segment:

The complete HLS structure has two parts:
- m3u8 Master Playlist file: Contains links to multiple Media Playlists differentiated by bandwidth and other parameters.
- m3u8 Media Playlist file: Contains basic video information and links to multiple Media Segments that compose the full video.
Media Segments are simply TS-format video files with no descriptive metadata, independently playable.
M3U8 is the Unicode version of M3U; the “8” denotes UTF-8 encoding. Both M3U and M3U8 are multimedia playlist file formats.
M3U8
M3U8 descriptor files consist of various descriptor fields. Below are explanations of key fields.
Here’s a random m3u8 video URL I found online: https://mgtv-com.jjyl12349.com/20210519/fXE0kuJ7/index.m3u8
Requesting this URL returns an m3u8 file — the Master Playlist.
Master Playlist
#EXTM3U#EXT-X-STREAM-INF:BANDWIDTH=150000,RESOLUTION=416x234/20210519/fXE0kuJ7/150kb/hls/index.m3u8#EXT-X-STREAM-INF:BANDWIDTH=150000,RESOLUTION=416x234/20210519/fXE0kuJ7/150kb/hls/index.m3u8#EXT-X-STREAM-INF:BANDWIDTH=1000000,RESOLUTION=1280x720/20210519/fXE0kuJ7/1000kb/hls/index.m3u8Field explanations:
- EXTM3U: Identifies the file as m3u8; every M3U file starts with this
- EXT-X-STREAM-INF: Represents a variant stream with its metadata
- BANDWIDTH: Bits per second (bitrate)
- RESOLUTION: Optimal pixel resolution for this variant
Select an appropriate Media Playlist URL based on BANDWIDTH, RESOLUTION, etc., and combine with the video URL’s domain for the full link.
For example, the 1000kb bandwidth, 1280x720 resolution variant’s URL: https://mgtv-com.jjyl12349.com/20210519/fXE0kuJ7/1000kb/hls/index.m3u8
Requesting this also returns an m3u8 file — the Media Playlist.
Media Playlist
#EXTM3U#EXT-X-VERSION:3#EXT-X-TARGETDURATION:6#EXT-X-PLAYLIST-TYPE:VOD#EXT-X-MEDIA-SEQUENCE:0#EXT-X-KEY:METHOD=AES-128,URI="https://mgtv-com.ycshengwang.com/20210519/fXE0kuJ7/1000kb/hls/key.key"#EXTINF:3,https://mgtv-com.ycshengwang.com/20210519/fXE0kuJ7/1000kb/hls/mDHy0Stk.ts#EXTINF:3,https://mgtv-com.ycshengwang.com/20210519/fXE0kuJ7/1000kb/hls/FWZjOCHy.ts.........#EXT-X-ENDLISTField explanations:
- EXT-X-VERSION: HLS protocol version
- EXT-X-TARGETDURATION: Maximum allowed TS segment duration
- EXT-X-PLAYLIST-TYPE: Streaming media type
- EXT-X-MEDIA-SEQUENCE: Sequence number of the first TS segment
- EXT-X-KEY: TS file encryption information
- METHOD: Encryption method —
NONE,AES-128, orSAMPLE-AES - URI: Key URL
- METHOD: Encryption method —
- EXTINF: Duration of the following TS segment URL