How HLS works, step by step
- The encoder cuts the stream into segments. Each segment is a small file holding a few seconds of video and audio, commonly in MPEG-TS or fragmented MP4 format.
- A media playlist lists the segments. This
.m3u8file names the most recent segments and how long each one lasts. - The player downloads the playlist, then the segments, one after another, and plays them back to back.
- For live TV, the playlist keeps changing. New segments are added and old ones drop off, so the player reloads the playlist every few seconds.
Adaptive bitrate: several qualities in one stream
HLS can offer the same channel at several qualities. A master playlist lists each version, for example 1080p at 6 Mbps, 720p at 3 Mbps and 480p at 1.5 Mbps, and the player chooses one based on the speed it measures. If your connection slows, it switches to a lower quality instead of stopping. Adaptive bitrate streaming explains how players decide.
Many IPTV channels are offered at a single quality, so this only helps where the provider publishes several.
What it looks like inside
A master playlist:
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=6000000,RESOLUTION=1920x1080
1080p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=3000000,RESOLUTION=1280x720
720p/index.m3u8
A live media playlist:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:6
#EXT-X-MEDIA-SEQUENCE:48213
#EXTINF:6.000,
segment48213.ts
#EXTINF:6.000,
segment48214.ts
This .m3u8 is a different job from the M3U file that lists your channels; see M3U vs M3U8.
Strengths and weaknesses for IPTV
Strengths
- Works over ordinary web connections and through most networks
- Recovers well from brief connection drops, because each segment is a separate download
- Can switch quality when several bitrates are offered
- Native on Apple devices and widely supported elsewhere
Limitations
- Adds delay behind the live broadcast, often tens of seconds
- Channel changes can be slower while the first segments download
- More requests to the server, which can hurt when the server is overloaded
Using HLS in your app
If your app or playlist offers a choice, HLS usually appears as m3u8 or “HLS”. Try it when MPEG-TS channels drop out on a patchy connection, and switch back if channel changes feel slow. HLS vs MPEG-TS walks through the decision.
