Advertisement
— 广告位 In-Article —

What Is HLS?

HTTP Live Streaming (HLS) is an adaptive bitrate streaming protocol introduced by Apple in 2009. Built on standard HTTP, it has become the dominant standard for internet video delivery. Netflix, YouTube, and virtually every major streaming platform use HLS.

HLS works in three steps: ① The server splits the video into short segments (2–10 seconds each, stored as .ts files); ② A M3U8 playlist file is generated, listing all segment URLs; ③ The player reads the M3U8, downloads segments in order, and switches quality based on network speed.

Two Types of M3U8 Files

  • Master Playlist: Lists all available quality levels, each pointing to a separate media playlist
  • Media Playlist: Lists the actual .ts segment URLs for one specific quality level

The player first parses the master playlist, picks a bitrate, fetches the corresponding media playlist, and starts downloading segments.

Master Playlist Example

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=640x360
360p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2500000,RESOLUTION=1280x720
720p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080
1080p/index.m3u8

Media Playlist Example

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:10
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:9.009,
https://cdn.example.com/seg000.ts
#EXTINF:9.009,
https://cdn.example.com/seg001.ts
#EXT-X-ENDLIST

Key Tag Reference

TagMeaning
#EXTM3UFile header — must appear on the first line
#EXT-X-VERSIONHLS spec version; affects available features
#EXT-X-TARGETDURATIONMaximum segment duration in seconds
#EXT-X-MEDIA-SEQUENCESequence number of the first segment (used for live)
#EXTINFExact duration of the following segment
#EXT-X-KEYEncryption info; points to AES-128 key URL
#EXT-X-ENDLISTEnd of playlist — present for VOD, absent for live
#EXT-X-STREAM-INFMaster playlist only — declares bitrate and resolution

How Adaptive Bitrate (ABR) Works

The player's bandwidth estimator tracks recent segment download speeds and compares them against the BANDWIDTH values in the master playlist. When bandwidth drops below 1.5× the current level for several segments, the player switches down; when bandwidth improves, it gradually steps up. The transition is seamless — no buffering, no interruption.

HLS vs. Other Streaming Protocols

ProtocolLatencyCDN-friendlyBrowser supportBest for
HLS / M3U88–30s✓ NativeAll platformsVOD, large-scale live
RTMP1–3s✗ Dedicated serverPlugin requiredEncoder → server ingest
DASH8–30s✓ NativeGoodVOD (Netflix, etc.)
WebRTC<1s✗ Hard to cacheModern browsersReal-time (video calls)

Want to try HLS playback right now? Use the StreamFlow online player — paste any M3U8 URL and play instantly, no installation needed.

💡 Expert Tips — Common M3U8 Pitfalls
  • Live streams have no #EXT-X-ENDLIST — players must poll for updates. This is by design, not a broken file.
  • Segment URLs in a playlist can be relative paths — always resolve them against the M3U8 file's own URL, not the page URL.
  • CORS errors are a server configuration issue, not a player bug. The server must return Access-Control-Allow-Origin: *.
  • The BANDWIDTH value is peak bitrate, not average. Inflating it causes unnecessary quality downgrades.
  • Encrypted streams (#EXT-X-KEY) require the key URL to also be accessible. A blocked key endpoint means no playback, even if the segments load fine.