### EXT-X-KEY Example for Streaming Services Source: https://developer.apple.com/documentation/http-live-streaming/using-content-protection-systems-with-hls Demonstrates the use of EXT-X-KEY tags in HLS streams for different digital rights management (DRM) systems. Includes examples for FairPlay Streaming, Widevine, and PlayReady, specifying methods, URIs, key formats, and versions. ```mpeg-url-text #EXT-X-KEY:METHOD=SAMPLE-AES,URI="skd://test",KEYFORMAT="com.apple.streamingkeydelivery",KEYFORMATVERSIONS="1" #EXT-X-KEY:METHOD=SAMPLE-AES,URI="data:text/plain;base64,AAAAOHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAABgSEAQUJDREVGR0hJSktMTU5PRI88aJmwY=",KEYFORMAT="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed",KEYFORMATVERSIONS="1" #EXT-X-KEY:METHOD=SAMPLE-AES,URI="data:text/plain;charset=UTF-16;base64,vgEAAAEAAQC0ATwAVwBSAE0ASABFAEEARABFAFIAIAB4AG0A...AQAvAEQAQQBUAEEAPgA8AC8AVwBSAE0ASABFAEEARABFAFIAPgA=",KEYFORMAT="com.microsoft.playready",KEYFORMATVERSIONS="1" ``` -------------------------------- ### HLS Playlist Delta Update Example Source: https://developer.apple.com/documentation/http-live-streaming/enabling-low-latency-http-live-streaming-hls Demonstrates a playlist delta update for Low-Latency HLS. This example utilizes the EXT-X-SKIP tag, indicating a need for a later HLS version. It shows how to provide updated media segments and part information, including server control attributes for reload and skipping. ```plaintext #EXTM3U #// Following the example above, this Playlist is a response to: #// GET https://example.com/2M/waitForMSN.php?_HLS_msn=273&_HLS_part=3&_HLS_skip=YES #EXT-X-TARGETDURATION:4 #EXT-X-VERSION:10 #EXT-X-SERVER-CONTROL:CAN-BLOCK-RELOAD=YES,PART-HOLD-BACK=1.0,CAN-SKIP-UNTIL=24.0 #EXT-X-PART-INF:PART-TARGET=0.33334 #EXT-X-MEDIA-SEQUENCE:264 #EXT-X-SKIP:SKIPPED-SEGMENTS=3 #EXTINF:4.00008, fileSequence267.mp4 #EXTINF:4.00008, fileSequence268.mp4 #EXTINF:4.00008, fileSequence269.mp4 #EXTINF:4.00008, fileSequence270.mp4 #EXT-X-PART:DURATION=0.33334,URI="filePart271.0.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.1.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.2.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.3.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.4.mp4",INDEPENDENT=YES #EXT-X-PART:DURATION=0.33334,URI="filePart271.5.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.6.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.7.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.8.mp4",INDEPENDENT=YES #EXT-X-PART:DURATION=0.33334,URI="filePart271.9.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.10.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.11.mp4" #EXTINF:4.00008, fileSequence271.mp4 #EXT-X-PROGRAM-DATE-TIME:2019-02-14T02:14:00.106Z #EXT-X-PART:DURATION=0.33334,URI="filePart272.a.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.b.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.c.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.d.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.e.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.f.mp4",INDEPENDENT=YES #EXT-X-PART:DURATION=0.33334,URI="filePart272.g.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.h.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.i.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.j.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.k.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.l.mp4" #EXTINF:4.00008, fileSequence272.mp4 #EXT-X-PART:DURATION=0.33334,URI="filePart273.0.mp4",INDEPENDENT=YES #EXT-X-PART:DURATION=0.33334,URI="filePart273.1.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart273.2.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart273.3.mp4" #EXT-X-PRELOAD-HINT:TYPE=PART,URI="filePart273.4.mp4" #EXT-X-RENDITION-REPORT:URI="../1M/waitForMSN.php",LAST-MSN=273,LAST-PART=3 #EXT-X-RENDITION-REPORT:URI="../4M/waitForMSN.php",LAST-MSN=273,LAST-PART=3 ``` -------------------------------- ### Initial Event Playlist Example - HLS Source: https://developer.apple.com/documentation/http-live-streaming/event-playlist-construction An example of an event playlist at the beginning of a session. It uses the EXT-X-PLAYLIST-TYPE:EVENT tag and does not initially contain EXT-X-ENDLIST. ```hls-playlist #EXTM3U #EXT-X-PLAYLIST-TYPE:EVENT #EXT-X-TARGETDURATION:10 #EXT-X-VERSION:4 #EXT-X-MEDIA-SEQUENCE:0 #EXTINF:10.00, fileSequence0.ts #EXTINF:10.0, fileSequence1.ts #EXTINF:10.0, fileSequence2.ts #EXTINF:10.0, fileSequence3.ts #EXTINF:10.0, fileSequence4.ts ``` -------------------------------- ### HLS Multivariant Playlist Example Source: https://developer.apple.com/documentation/http-live-streaming/creating-a-multivariant-playlist This example demonstrates a Multivariant Playlist for HTTP Live Streaming. It defines five different stream variants, each with specified bandwidth, resolution, and codec information, pointing to individual stream playlist URLs. Clients use this information to select the best stream. ```m3u8 #EXTM3U #EXT-X-STREAM-INF:BANDWIDTH=150000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2" http://example.com/low/index.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=240000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2" http://example.com/lo_mid/index.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=440000,RESOLUTION=416x234,CODECS="avc1.42e00a,mp4a.40.2" http://example.com/hi_mid/index.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=640000,RESOLUTION=640x360,CODECS="avc1.42e00a,mp4a.40.2" http://example.com/high/index.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=64000,CODECS="mp4a.40.5" http://example.com/audio/index.m3u8 ``` -------------------------------- ### HLS Byterange-Addressed Parts Example Source: https://developer.apple.com/documentation/http-live-streaming/enabling-low-latency-http-live-streaming-hls Illustrates byterange-addressed parts in an HLS playlist, showing how specific byte ranges within a media file can be referenced. This is useful for partial segment fetching and updates. Note that INDEPENDENT attributes are omitted for clarity. ```plaintext #// In these examples only the end of the Playlist is shown. #// This is Playlist update 1 #EXTINF:4.08, fs270.mp4 #EXT-X-PART:DURATION=1.02,URI="fs271.mp4",BYTERANGE="20000@0" #EXT-X-PART:DURATION=1.02,URI="fs271.mp4",BYTERANGE="23000@20000" #EXT-X-PART:DURATION=1.02,URI="fs271.mp4",BYTERANGE="18000@43000" #EXT-X-PRELOAD-HINT:TYPE=PART,URI="fs271.mp4",BYTERANGE-START=61000 #// This is Playlist update 2 #EXTINF:4.08, fs270.mp4 #EXT-X-PART:DURATION=1.02,URI="fs271.mp4",BYTERANGE="20000@0" #EXT-X-PART:DURATION=1.02,URI="fs271.mp4",BYTERANGE="23000@20000" #EXT-X-PART:DURATION=1.02,URI="fs271.mp4",BYTERANGE="18000@43000" #EXT-X-PART:DURATION=1.02,URI="fs271.mp4",BYTERANGE="19000@61000" #EXTINF:4.08, fs271.mp4 #EXT-X-PRELOAD-HINT:TYPE=PART,URI="fs272.mp4",BYTERANGE-START=0 #// This is Playlist update 3 #EXTINF:4.08, fs270.mp4 #EXT-X-PART:DURATION=1.02,URI="fs271.mp4",BYTERANGE="20000@0" #EXT-X-PART:DURATION=1.02,URI="fs271.mp4",BYTERANGE="23000@20000" #EXT-X-PART:DURATION=1.02,URI="fs271.mp4",BYTERANGE="18000@43000" #EXT-X-PART:DURATION=1.02,URI="fs271.mp4",BYTERANGE="19000@61000" #EXTINF:4.08, fs271.mp4 #EXT-X-PART:DURATION=1.02,URI="fs272.mp4",BYTERANGE="21000@0" #EXT-X-PRELOAD-HINT:TYPE=PART,URI="fs272.mp4",BYTERANGE-START=21000 ``` -------------------------------- ### HLS Live Playlist Example (Updated State) Source: https://developer.apple.com/documentation/http-live-streaming/live-playlist-sliding-window-construction This example shows an updated HLS live playlist where older media segments have been removed and new ones added, reflecting the sliding window approach. The EXT-X-MEDIA-SEQUENCE tag is incremented to maintain the correct order. ```text #EXTM3U #EXT-X-TARGETDURATION:10 #EXT-X-VERSION:4 #EXT-X-MEDIA-SEQUENCE:2 #EXTINF:10.0, fileSequence2.ts #EXTINF:10.0, fileSequence3.ts #EXTINF:10.00, fileSequence4.ts #EXTINF:10.00, fileSequence5.ts #EXTINF:10.0, fileSequence6.ts ``` -------------------------------- ### Video on Demand Playlist Example (Relative Paths) Source: https://developer.apple.com/documentation/http-live-streaming/video-on-demand-playlist-construction This code snippet shows a Video on Demand (VOD) playlist utilizing relative pathnames for media files, which is a preferred and more portable approach. It uses the same HLS tags as the absolute path example, but specifies media files using relative paths from the playlist's URL. ```text #EXTM3U #EXT-X-PLAYLIST-TYPE:VOD #EXT-X-TARGETDURATION:10 #EXT-X-VERSION:4 #EXT-X-MEDIA-SEQUENCE:0 #EXTINF:10.0, fileSequenceA.ts #EXTINF:10.0, fileSequenceB.ts #EXTINF:10.0, fileSequenceC.ts #EXTINF:9.0, fileSequenceD.ts #EXT-X-ENDLIST ``` -------------------------------- ### Examine a Low-Latency HLS Playlist Source: https://developer.apple.com/documentation/http-live-streaming/enabling-low-latency-http-live-streaming-hls This code snippet displays an example of a low-latency HLS playlist. It uses version 6 and includes tags like EXT-X-SERVER-CONTROL, EXT-X-PART-INF, and EXT-X-PART, which are specific to low-latency streaming. Clients that do not understand these new tags will ignore them, ensuring backward compatibility. ```plaintext #EXTM3U #// This Playlist is a response to: #// GET https://example.com/2M/waitForMSN.php?_HLS_msn=273&_HLS_part=2 #EXT-X-TARGETDURATION:4 #EXT-X-VERSION:6 #EXT-X-SERVER-CONTROL:CAN-BLOCK-RELOAD=YES,PART-HOLD-BACK=1.0,CAN-SKIP-UNTIL=24.0 #EXT-X-PART-INF:PART-TARGET=0.33334 #EXT-X-MEDIA-SEQUENCE:264 #EXT-X-PROGRAM-DATE-TIME:2019-02-14T02:13:28.106Z #EXT-X-MAP:URI="init.mp4" #EXTINF:4.00008, fileSequence264.mp4 #EXTINF:4.00008, fileSequence265.mp4 #EXTINF:4.00008, fileSequence266.mp4 #EXTINF:4.00008, fileSequence267.mp4 #EXTINF:4.00008, fileSequence268.mp4 #EXTINF:4.00008, fileSequence269.mp4 #EXTINF:4.00008, fileSequence270.mp4 #EXT-X-PART:DURATION=0.33334,URI="filePart271.0.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.1.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.2.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.3.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.4.mp4",INDEPENDENT=YES #EXT-X-PART:DURATION=0.33334,URI="filePart271.5.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.6.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.7.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.8.mp4",INDEPENDENT=YES #EXT-X-PART:DURATION=0.33334,URI="filePart271.9.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.10.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart271.11.mp4" #EXTINF:4.00008, fileSequence271.mp4 #EXT-X-PROGRAM-DATE-TIME:2019-02-14T02:14:00.106Z #EXT-X-PART:DURATION=0.33334,URI="filePart272.0.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.b.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.c.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.d.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.e.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.f.mp4",INDEPENDENT=YES #EXT-X-PART:DURATION=0.33334,URI="filePart272.g.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.h.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.i.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.j.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.k.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart272.l.mp4" #EXTINF:4.00008, fileSequence272.mp4 #EXT-X-PART:DURATION=0.33334,URI="filePart273.0.mp4",INDEPENDENT=YES #EXT-X-PART:DURATION=0.33334,URI="filePart273.1.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart273.2.mp4" #EXT-X-PART:DURATION=0.33334,URI="filePart273.3.mp4" #EXT-X-PRELOAD-HINT:TYPE=PART,URI="filePart273.3.mp4" #EXT-X-RENDITION-REPORT:URI="../1M/waitForMSN.php",LAST-MSN=273,LAST-PART=2 #EXT-X-RENDITION-REPORT:URI="../4M/waitForMSN.php",LAST-MSN=273,LAST-PART=1 ``` -------------------------------- ### HLS Media Playlist Example (video.m3u8) Source: https://developer.apple.com/documentation/http-live-streaming/about-the-common-media-application-format-with-http-live-streaming-hls This HLS Media Playlist is for a regular video track. It specifies the target duration, version, playlist type (VOD), media initialization segment (MAP), and individual media segments with their durations. It is generated from CMAF segments. ```text #EXTM3U #EXT-X-TARGETDURATION:4 #EXT-X-VERSION:6 #EXT-X-PLAYLIST-TYPE:VOD #EXT-X-MAP:URI="VH" #EXTINF:4.004, V1andV2 #EXTINF:4.004, V3andV4 #EXTINF:2.002, V5 #EXT-X-ENDLIST ``` -------------------------------- ### HLS Media Playlist Example (english.m3u8) Source: https://developer.apple.com/documentation/http-live-streaming/about-the-common-media-application-format-with-http-live-streaming-hls This HLS Media Playlist is for an English audio track. It includes the target duration, version, playlist type (VOD), media initialization segment (MAP), and audio segments with their durations. It's derived from CMAF audio segments. ```text #EXTM3U #EXT-X-TARGETDURATION:4 #EXT-X-VERSION:6 #EXT-X-PLAYLIST-TYPE:VOD #EXT-X-MAP:URI="EH" #EXTINF:3.9938, E1andE2 #EXTINF:3.9938, E3andE4 #EXTINF:2.0201, E5 #EXT-X-ENDLIST ``` -------------------------------- ### Updated Event Playlist Example (Event Concluded) - HLS Source: https://developer.apple.com/documentation/http-live-streaming/event-playlist-construction An example of an event playlist after new media URIs have been added and the event has concluded, indicated by the EXT-X-ENDLIST tag. ```hls-playlist #EXTM3U #EXT-X-PLAYLIST-TYPE:EVENT #EXT-X-TARGETDURATION:10 #EXT-X-VERSION:4 #EXT-X-MEDIA-SEQUENCE:0 #EXTINF:10.0, fileSequence0.ts #EXTINF:10.0, fileSequence1.ts #EXTINF:10.0, fileSequence2.ts #EXTINF:10.0, fileSequence3.ts #EXTINF:10.0, fileSequence4.ts // List of files between 4 and 120 go here. #EXTINF:10.0, fileSequence120.ts #EXTINF:10.0, fileSequence121.ts #EXT-X-ENDLIST ``` -------------------------------- ### HLS Live Playlist Example (Initial State) Source: https://developer.apple.com/documentation/http-live-streaming/live-playlist-sliding-window-construction This code snippet demonstrates the structure of an HLS live playlist at the beginning of a streaming session. It includes essential tags like EXTM3U, EXT-X-TARGETDURATION, EXT-X-VERSION, EXT-X-MEDIA-SEQUENCE, and EXTINF, followed by media file URIs. ```text #EXTM3U #EXT-X-TARGETDURATION:10 #EXT-X-VERSION:4 #EXT-X-MEDIA-SEQUENCE:1 #EXTINF:10.0, fileSequence1.ts #EXTINF:10.0, fileSequence2.ts #EXTINF:10.0, fileSequence3.ts #EXTINF:10.0, fileSequence4.ts #EXTINF:10.0, fileSequence5.ts ``` -------------------------------- ### HLS Basic Multivariant Playlist Example Source: https://developer.apple.com/documentation/http-live-streaming/about-the-common-media-application-format-with-http-live-streaming-hls This HLS Multivariant Playlist aggregates different media renditions. It defines audio renditions (English, French) using EXT-X-MEDIA tags and video renditions using EXT-X-STREAM-INF tags, specifying bandwidth, codecs, and resolution. It enables client-side selection between different quality levels and audio tracks. ```text #EXTM3U #EXT-X-VERSION:6 #EXT-X-INDEPENDENT-SEGMENTS #EXT-X-MEDIA:NAME="English",TYPE=AUDIO,GROUP-ID="audio-stereo-64",LANGUAGE="en",DEFAULT=YES,AUTOSELECT=YES,URI="english.m3u8" #EXT-X-MEDIA:NAME="Français",TYPE=AUDIO,GROUP-ID="audio-stereo-64",LANGUAGE="fr",DEFAULT=NO,AUTOSELECT=YES,URI="french.m3u8" #EXT-X-STREAM-INF:BANDWIDTH=1123000,CODECS="avc1.64001f,mp4a.40.2",AUDIO="audio-stereo-64",RESOLUTION=620x334 video.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=8123000,CODECS="avc1.640028,mp4a.40.2",AUDIO="audio-stereo-64",RESOLUTION=1916x1032 video-hq.m3u8 ``` -------------------------------- ### Add Low-Latency HLS Delivery Directives Source: https://developer.apple.com/documentation/http-live-streaming/enabling-low-latency-http-live-streaming-hls Learn how to add special query parameters to a GET request for a Playlist to control HLS delivery, ensuring segments are held until specific sequence numbers are met. ```APIDOC ## GET /playlist ### Description This endpoint allows clients to request a media playlist with specific delivery directives to enable low-latency HLS. ### Method GET ### Endpoint /playlist ### Query Parameters - **_HLS_msn** (integer) - Required - Indicates the minimum Media Sequence Number the server must hold the request until. - **_HLS_part** (integer) - Optional - In combination with `_HLS_msn`, indicates the minimum Partial Segment number for a given Media Sequence Number. - **_HLS_skip** (string: "YES"|"v2") - Optional - Requests a Playlist Delta Update, replacing earlier portions with an `EXT-X-SKIP` tag. ``` -------------------------------- ### HLS Multivariant Playlist with Alternate Audio Renditions (M3U8) Source: https://developer.apple.com/documentation/http-live-streaming/adding-alternate-media-to-a-playlist This M3U8 playlist defines multiple audio renditions for different languages (English, French, Spanish) and two video streams with varying bandwidths. It utilizes EXT-X-MEDIA tags to specify audio groups and EXT-X-STREAM-INF tags to link to rendition playlists, enabling clients to select preferred audio tracks based on user preference or available bandwidth. Dependencies: None. Inputs: None. Outputs: A structured HLS playlist file. ```m3u8 #EXTM3U #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",LANGUAGE="eng",NAME="English",AUTOSELECT=YES,DEFAULT=YES,URI="eng/prog_index.m3u8" #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",LANGUAGE="fre",NAME="Français",AUTOSELECT=YES,DEFAULT=NO,URI="fre/prog_index.m3u8" #EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",LANGUAGE="sp",NAME="Espanol",AUTOSELECT=YES,DEFAULT=NO,URI="sp/prog_index.m3u8" #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=195023,CODECS="avc1.42e00a,mp4a.40.2",AUDIO="audio" lo/prog_index.m3u8 #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=591680,CODECS="avc1.42e01e,mp4a.40.2",AUDIO="audio" hi/prog_index.m3u8 ```