HTTP Live Streaming (HLS) is an HTTP-based adaptive bitrate streaming communications protocol developed by Apple Inc.
Adaptive bitrate streaming means that the client media software dynamically detects the Internet speed of the user, and then adjusts video quality in response.
Support for this protocol is widespread in media players, web browsers, mobile devices, and streaming media servers.
Technical Overview Of HLS Streaming
With normal HTTP streaming the HLS protocol separates the video file into smaller segments with the “.ts” file extension (MPEG2 Transport Stream).
Since the HLS is an adaptive bitrate protocol, the bitrates must accommodate and adapt to the channel bandwidth and other parameters of the media player.
The video delivery starts by delivering a single file called Manifest File (master.m3u8) that contains links to the index files. The index files contain a playlist with references to the actual video segments.
Based on the bandwidth of the currently available connection of the user, the HLS allows the media player to adjust the video to the best possible quality.
HLS streaming format
The video files need to be encoded with H.264(AVC) or with the H.265(HEVC) compression algorithms.
The implementation of the HLS requires creating a CDN zone for big objects (they are such by default) and generating a .m3u8 index file that contains links to the corresponding .ts segments of the file.
This is done by prefixing ‘/hls’ to the path and appending ‘/index.m3u8’ at the end. Please note that you need to upload only your full .mp4 files and segmentation is done by the CDN.
The returned .m3u8 index file contains the corresponding segments for the .mp4 file. The default values set up for the first segment and the other segments are 5 and 10 seconds respectively. You can change them by using parameters bsd (first few segments) and sd (other segments) in the URL.
In the example above the value set up for the bsd parameter of the initial segment is 10 seconds, the second is set up again to 10 seconds, and the third is set up to be 15 seconds. The rest of the segments are set up with the sd parameter to be 20 seconds. Note that the values should be in milliseconds.
It is important to specify the relative paths of a segment as per the specifications on the documentation at https://tools.ietf.org/html/draft-pantos-http-live-streaming-17. Meaning that the absolute path for segment ‘seg-5-v1-a1.ts’ is /hls/video/012345.mp4/seg-5-v1-a1.ts, not /seg-5-v1-a1.ts
You can purge cached segments related to an index.m3u8 file, by following the instructions from Purge Through The CP.
Furthermore, there is functionality to build a playlist from multiple files. It is used usually when for a given video source there are multiple resolutions and you would like the users to be able to switch between them without changing the page.
Let’s say that we have the previous file /video/012345.mp4 in 3 resolutions 240p, 360p and 480p and we have named them /012345_240p.mp4/012345_360p.mp4 and /012345_480p.mp4 respectively.
The URI must be set up as shown below:
Where the two common parts are “012345_” and “0p.mp4” and the bitrates – 24,36,48 are divided by commas:
#EXTM3U #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=368981,RESOLUTION=426x240,FRAME-RATE=24.000,CODECS="avc1.4d4015,mp4a.40.2" /hls/012345_240p.mp4/index.m3u8 #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=460061,RESOLUTION=640x360,FRAME-RATE=24.000,CODECS="avc1.4d401e,mp4a.40.2" /hls/012345_360p.mp4/index.m3u8 #EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=789049,RESOLUTION=854x480,FRAME-RATE=24.000,CODECS="avc1.4d401e,mp4a.40.2" /hls/012345_480p.mp4/index.m3u8
The Manifest File (master.m3u8) contains playlists (index.m3u8) for each of the provided files along with additional information for each stream included in playlists.
The Manifest File ends with master.m3u8, not with index.m3u8 as it is with the playlist for a single file.
It should be also noted that the playlist inside the master playlist has the same URI as the one that can be used for the individual URIs.
Universal CDN supports multi-language subtitles in VTT format for HLS streaming.
To demonstrate the feature, we will use the same example /video/012345.mp4 and we assume that the subtitles are in the same folder /video or in subfolder /video/subs/.
/hls/video/, lang/eng/012345_eng.vtt, lang/ger/012345_ger.vtt, 012345.mp4, /urlset/master.m3u8
/hls/video/, subs/lang/eng/012345_eng.vtt, subs/lang/ger/012345_ger.vtt, 012345.mp4, /urlset/master.m3u8
There should be noted several things for the above request path:
1. We use urlset and master.m3u8 to load the subtitles in the playlist, not the standard playlist index.m3u8
2. We specify the common path first, which in the example is /video
3. Required part for the URL is lang/ISO 639-2, which is a three-letter country code. You can find all codes on this page: https://www.loc.gov/standards/iso639-2/php/code_list.php
4. If the subtitles are in the subfolder, the folder should be before the required part.
5. All commas are intentional.
Limit access using a secret key
The HLS functionality can be combined with our security token feature to block any hotlinking attempts. For detailed information, please go to Combining Transmuxing to HLS with Limit Access Using a Secret Key Feature.
To combine all features of the secret key that limit access, you must include the following part:
/video/bsd/10000-10000-15000/sd/20000/lang/eng/012345_eng.vtt, lang/ger/012345_ger.vtt, 012345_,24,36,48, 0p.mp4
Note that the prefix /hls and suffixes /urlset/master.m3u8 and /index.m3u8 are excluded.
All the segments have security tokens attached to them when returned inside the .m3u8 file. For this reason, there is no need to recalculate it for each of them before requesting it.
Since the security token is the same (including all parameters) for the .m3u8 file, it’s important to note that for longer videos it’s possible that the security token can expire before a request for the given segment is made.
Combining Transmuxing to HLS with Limit Access Using a Secret Key
Combining Transmuxing to MPEG-DASH with Limit Access Using a Secret Key