The playlist is only an index; the media is in the segments it points to. HLS allows a few segment formats, and can encrypt them with keys that the playlist names.
Segment formats
| Format | Rules |
|---|---|
| MPEG-2 transport stream | Each segment holds a PAT and a PMT, or an EXT-X-MAP points to them. The original HLS format. |
| Fragmented MP4 (CMAF) | An initialisation section, named by EXT-X-MAP, holds the ftyp and moov boxes; each segment is one or more moof and mdat fragments. |
| Packed audio | Plain AAC (ADTS), MP3, AC-3 or Enhanced AC-3 frames. Each segment starts with an ID3 tag holding the timestamp of its first sample (below). |
| WebVTT | Subtitle segments, each a complete WebVTT file, with an X-TIMESTAMP-MAP header line tying cue times to the video’s 90 kHz clock. |
| IMSC | Subtitles in fragmented MP4, following the IMSC1 Text profile. |
Packed audio timestamp
The ID3 tag at the start of a packed audio segment holds a PRIV frame
whose owner is com.apple.streaming.transportStreamTimestamp. Its data is
8 bytes, a big-endian number whose lowest 33 bits are an MPEG-2 presentation timestamp
(90 kHz) and whose upper 31 bits are zero.
50 52 49 56 PRIV
00 00 00 35 frame size 53
00 00 flags
63 6F 6D 2E … 61 6D 70 00 "com.apple.streaming.transportStreamTimestamp", NUL
00 00 00 00 00 0D BB A0 timestamp 900000 = 10 seconds
Encryption
#EXT-X-KEY says how the following segments are encrypted.
| Attribute | Type | Meaning |
|---|---|---|
METHOD | required | One of the methods below. |
URI | quoted string | Where to get the key. Required unless METHOD=NONE. |
IV | 128-bit hexadecimal | Version 2. The initialisation vector. Not allowed with SAMPLE-AES-CTR or AES-256-GCM. |
KEYFORMAT | quoted string | Version 5. How the key is delivered: "identity" (the default) means the URI returns the key itself; other values name a DRM system. |
KEYFORMATVERSIONS | quoted string | Version 5. Versions of the key format, separated by /, such as "1/2"; default "1". |
| Method | Encryption |
|---|---|
NONE | Not encrypted. No other attributes allowed. |
AES-128 | The whole segment is encrypted with AES-128 in CBC mode with PKCS7 padding, restarting at each segment. With the identity format, the key is a 16-byte file. Without an IV, the IV is the segment’s media sequence number as a 128-bit big-endian number. |
SAMPLE-AES | Only the media samples are encrypted, so the container stays readable. In fragmented MP4 this is the cbcs scheme of Common Encryption; other formats follow Apple’s HLS Sample Encryption specification. Version 5. |
SAMPLE-AES-CTR | Fragmented MP4 with the cenc scheme of Common Encryption. Optional for players. |
AES-256-GCM | The whole segment with a 256-bit key in GCM mode; the segment starts with its 16-byte IV, then the ciphertext. Optional for players. |
Worked example
#EXT-X-MEDIA-SEQUENCE:7794
#EXT-X-KEY:METHOD=AES-128,URI="https://example.com/keys/k1"
#EXTINF:6.0,
seg7794.ts
IV, the
IV for seg7794.ts is 7794 as a 16-byte number:
00000000000000000000000000001E72.