HLS in plain words
HLS (HTTP Live Streaming) is a way of delivering video over the web. Apple created it, and it is now widely used, including by many councils, legislatures and courts that stream their meetings. The format is described in RFC 8216, and Apple keeps its own HTTP Live Streaming documentation.
Instead of one big file, the video is cut into short pieces, called segments, usually a few seconds long each. An m3u8 file is the playlist that lists those pieces in order. The player downloads the playlist, then fetches and plays the pieces one after another. Because each piece is a small separate download, playback starts quickly, and the player can switch to a lower quality in the middle of a video when your connection slows down.
The name comes from M3U, an older playlist format for music. The "8" stands for UTF-8, the standard way of storing text. Under RFC 8216, a playlist's address ends in .m3u8 or .m3u, or the server labels it with the type application/vnd.apple.mpegurl or audio/mpegurl.
Master playlists and media playlists
There are two kinds of m3u8 file. RFC 8216 calls them the master playlist and the media playlist. Newer drafts of the specification call the first one a multivariant playlist.
- Master playlist
- A menu of versions. Each
#EXT-X-STREAM-INFline describes one quality: its peak bandwidth in bits per second and, usually, its resolution and codecs (the compression formats used). The line after it is the address of that quality's own playlist. Separate audio languages and subtitle tracks are listed with#EXT-X-MEDIAlines. - Media playlist
- The list of pieces for one version. Each piece has an
#EXTINFline giving its length in seconds, followed by its address.
A short master playlist looks like this:
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080
1080p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2800000,RESOLUTION=1280x720
720p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1400000,RESOLUTION=854x480
480p/index.m3u8
Addresses such as 720p/index.m3u8 are relative: they are read from the same folder as the playlist that lists them. Give a player the master playlist and it picks a quality to suit your screen and connection. Give it a media playlist and you get that one version.
The pieces: .ts and fMP4 segments
HLS pieces come in a few formats:
- MPEG-2 Transport Stream (.ts). The original HLS format and still very common. Each piece normally carries the information a player needs to read it, so .ts pieces can be joined end to end into one file.
- Fragmented MP4 (fMP4). Newer streams often use MP4 pieces, commonly ending in
.m4sor.mp4. They depend on a small header file, the initialization section, named in an#EXT-X-MAPline. - Audio and subtitles. Audio-only tracks can use plain audio pieces such as
.aac, and subtitles use WebVTT (.vtt) pieces.
m3u8.cloud can save either kind of video stream as MP4. If you choose the original pieces instead, .ts pieces are joined into one .ts file and fMP4 pieces into one fragmented .mp4. If you already have .ts files on your computer, Merge TS joins them and TS to MP4 converts them, without uploading anything.
An example media playlist, line by line
Here is a complete media playlist for a short on-demand video:
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:6
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:6.000,
segment0.ts
#EXTINF:6.000,
segment1.ts
#EXTINF:4.200,
segment2.ts
#EXT-X-ENDLIST
Lines that start with #EXT are tags. Other lines that start with # are comments, and every remaining line is the address of a piece or playlist.
#EXTM3Umust be the first line of every HLS playlist. Without it, the file is not a valid playlist.#EXT-X-VERSIONsays which version of the format the playlist needs.#EXT-X-TARGETDURATIONsets the maximum length of a piece, in whole seconds.#EXT-X-MEDIA-SEQUENCEis the number of the first piece in the list.#EXT-X-PLAYLIST-TYPE:VODpromises that the list will never change.#EXTINF:6.000,gives the length of the next piece in seconds. The line below it,segment0.ts, is that piece's address.#EXT-X-ENDLISTmeans no more pieces will be added.
Add up the #EXTINF values and you get the length of the video: 16.2 seconds here. Reading values like these is how m3u8.cloud can show a video's length and number of pieces before you download anything.
Live and on-demand playlists
An on-demand playlist is complete. It ends with #EXT-X-ENDLIST, every piece is listed, and you can save the whole video at once.
A live playlist has no #EXT-X-ENDLIST line. The player reloads it every few seconds to find new pieces. Many live playlists are a sliding window: each time new pieces are added, the oldest ones are removed and #EXT-X-MEDIA-SEQUENCE goes up. The list may hold only the last minute or two of the stream, and pieces that drop off it can soon disappear from the server.
A third type, marked #EXT-X-PLAYLIST-TYPE:EVENT, only ever adds pieces, so everything since the start stays in the list until the event ends. When a live event finishes, some sites add #EXT-X-ENDLIST to the same playlist; others publish the recording under a new link later.
m3u8.cloud can record a live playlist. Press Record, then "Stop and save" to finish the file. The recording also includes whatever the stream still keeps from before you pressed Record, often a minute or two.
Why it won't open like an MP4, and what to do instead
Double-clicking a downloaded .m3u8 file rarely gets you a video. The file holds only text, and its addresses are often relative, like segment0.ts, which only make sense next to the original link. A saved copy can't find its pieces, and on many sites the pieces stay available only for a limited time. Most video editors and phones also expect one complete file such as MP4.
To watch it
- Paste the link into the m3u8 player. It plays in your browser when the stream's server allows direct access.
- In VLC, choose Media › Open Network Stream (File › Open Network on a Mac) and paste the link.
- Safari on a Mac, iPhone or iPad plays HLS natively, so pasting the link into its address bar often works.
To save it as one file
Paste the link on the m3u8.cloud home page. You can pick a quality, trim the start and end, and save as MP4, audio only (.m4a) or the original pieces. If you prefer the command line, see how to download an m3u8 with ffmpeg. Don't have the link yet? Here's how to find it.
To look inside it
The m3u8 inspector shows the qualities, audio and subtitle tracks, pieces, durations, tags, encryption and any warnings for a playlist. For what each tag means, see the HLS tag reference.
Questions
Is an m3u8 file a video?
No. It is a plain text playlist that lists the addresses of the video's pieces. The video and audio are in those pieces, which stay on the server.
What is the difference between m3u and m3u8?
Both are playlist formats. M3U came first, for music playlists. An m3u8 file is an M3U playlist stored as UTF-8 text. HLS playlists are always UTF-8, and RFC 8216 allows either extension, though .m3u8 is the usual one.
Can I convert an m3u8 file to MP4?
Is it legal to download an m3u8 stream?
That depends on the video, not the format. Save only videos you have the right to save, such as public meeting recordings the publisher allows you to keep, your own videos or openly licensed material. m3u8.cloud refuses encrypted and DRM-protected streams.
Related
Have the link? Save the stream as one video file.
Paste a link