How Browsers Play HLS: MSE and Remuxing

この記事は中文と英語で提供されています。日本語訳は準備中です。

Safari plays HLS out of the box, but Chrome, Firefox and others don't support it natively. They rely on a JavaScript approach: Media Source Extensions (MSE) feed network data into a <video> element.

The role of MSE

MSE lets page scripts build a media stream and hand it to the video element for playback. After downloading the M3U8 and TS segments, the player must remux TS (MPEG-2 Transport Stream) into a browser-friendly format — usually fMP4, or fragmented MP4 — and append it to the MediaSource buffer.

What hls.js does

As the most popular HLS playback library, hls.js handles playlist parsing, segment downloading, ABR decisions, TS→fMP4 remuxing (which can run asynchronously in a Web Worker) and error recovery. Player sites stand on its shoulders to deliver "open a page and play".

Why CORS still matters

Both the playlist and the segments are requested by JavaScript via fetch/XHR, so the browser runs cross-origin checks on them. If the source hasn't enabled CORS, the requests are blocked — the main reason web playback fails.

← Common ffmpeg Commands for M3U8Playing and Saving M3U8 on Mobile: Practical Tips →