Apple HLS: introduction
A sequel to this article is available as: Apple HLS: comparing versions.
What is HLS
HLS is a protocol for transmitting multimedia data over HTTP. HLS describes a playlist format called M3U8 and a media segment format based on:
- MPEG-2 (TS, PS, ES),
- or ISOBMFF MPEG-4 Fragmented (starting at version 7, revision 20 from September 20, 2016).
HLS supports the provision of alternate versions (e.g. bitrates, languages) and encryption of media data. HLS is suitable for live and on-demand playback.
The input media stream is divided into Media Segments. Media segments typically last from 2 to 10 seconds. The playlist format is derived from the M3U format, a simple format for MP3 playlists, into a new extended format called M3U8 (the '8' suffix stands for UTF-8).
Master and Media Playlist examples
Here is a simple example of a Media Playlist:
#EXTM3U #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-TARGETDURATION:5 #EXTINF:5, output_96000_0.ts #EXTINF:5, output_96000_1.ts #EXTINF:5, output_96000_2.ts #EXTINF:5, output_96000_3.ts #EXT-X-ENDLIST
A server may offer multiple Media Playlist files to provide different encodings of the same presentation. It is presented in a Master Playlist file. Here is an example:
#EXTM3U #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=96000 96000/output_96000.m3u8 #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=256000 256000/output_256000.m3u8
M3U8 playlist description
The Extended M3U file format defines new tags detailed below.
The playlist is called M3U8 by reference of the UTF-8 encoding used. The extension of the playlist file is .m3u8 and the expected mimetype is application/x-mpegURL (old) or application/vnd.apple.mpegurl (newer).
Each line is a URI, a blank, or starts with the comment character '#'. Lines that start with the comment character '#' are either comments or tags. Tags begin with #EXT.
Media Segment format
The media segment format can be either:
- an MPEG-2 Transport Stream,
- an MPEG-2 Program Stream,
- an MPEG-2 audio elementary stream (AAC with ADTS framing, MP3 ; (Enhanced) AC-3 added at revision 20),
- an MPEG-4 Fragmented (revision 20), CMAF compliance (revision 23).
Media Segments are self-initialized, i.e. they start with:
- MPEG-2 TS: a PAT then a PMT table,
- MPEG-4 Fragmented: CMAF Header compliance and CMAF Segment compliance,
- Video track: one key frame and enough information to completely initialize a video
Media Segment files may contain several audio or video. Starting at revision 4, it should consider the track with the lowest PID.