Combining Transmuxing to HLS with Limit Access Using a Secret Key

To combine MP4 transmuxing to HLS with the Limit Access Using a Secret Key feature, you need to:  

  • Generate the hash of your resource by including the file path from the URI, the secret key, and the values of the cdn_creation_time, and cdn_ttl
  • Update the file path of URI to your resource after the generation of their cdn_hash by prefixing ‘/hls’ at the beginning and appending ‘/index.m3u8’ at the end. 


Step by step guidance


1. Generate the cdn_hash of your resource by following the Limit Access Using a Secret Key article. In the example below, the hash value has been generated by using:

  • the secret key entered in the UCDN Control Panel
  • URI path (e.g ‘/foo/bar/foobar.mp4’)
  • creation time (current Unix timestamp)
  • Time to live (TTL). Note that the TTL can be set through the UCDN Control Panel. If so, it is not necessary to include the TTL parameter in the generation of the cdn_hash value.


Тhe prefix ‘/hls’, suffixes ‘/urlset/master.m3u8, and ‘/index.m3u8’ have to be excluded when generating hash value. 


2. Prefix the URI path with ‘/hls’ and append ‘/index.m3u8’ at the end (e.g. ‘/hls/foo/bar/foobar.mp4/index.m3u8). 


3. Compose the full URL. The transmuxing to HLS requires, after the generation of the cdn_hash, the URI of your MP4 resources to be composed by the pattern shown in the example below:

http(s)://bar.foobar.bar/hls/foo/bar/foobar.mp4/index.m3u8?cdn_hash=63c21767af6896fd305f08f8e9c5d5fb&cdn_creation_time=1615987169


The following script was used to generate the full URL to the file with transmuxing to HLS and by Limit Access Using a Secret Key

<?php
$secret_key = '<your secret key>';

/* URI Path to your mp4 file */
$request_path = '/foo/bar/foobar.mp4';

/* Current Unix timestamp */
$cdn_creation_time = time(); 

/* For how long the generated URL will be active (in seconds) */
$cdn_ttl = 86400;  

/* Generate the cdn_hash as md5 sum */
$hash = md5($request_path . $secret_key . $cdn_creation_time . $cdn_ttl);

/* Generating the URL with a secret key by concatenating domain, path, and parameters */
$access_url  = 'https://bar.foobar.bar' . '/hls' . $request_path.'/index.m3u8'
                         .'?cdn_hash=' . $hash 
                         .'&cdn_creation_time=' . $cdn_creation_time
                         .'&cdn_ttl=' . $cdn_ttl;

echo $access_url . "\n";
?>

The output of the script is the same as the pattern shown above.


Setting up the ‘/bsd’ and ‘/sd’ parameters with Limit Access Using a Secret Key


The same logic applies when including the/bsd and /sdparameters. 

http(s)://bar.foobar.bar/hls/bsd/10000-10000-15000/sd/20000/foo/bar/foobar.mp4/index.m3u8?cdn_hash=63c21767af6896fd305f08f8e9c5d5fb&cdn_creation_time=1615987169

Both parameters ‘/bsd and ‘/sd’ along with their values are part of the URI path (e.g. /bsd/10000-10000-15000/sd/20000/foo/bar/foobar.mp4) and should be included when generating hash value as well. 


URLSET with Limit Access Using a Secret Key


The same logic applies again to build a playlist from multiple files but this time you need to append ‘/urlset/master.m3u8’ instead of ‘/index.m3u8 at the end of the path of the file as shown in the example below:  

http(s)://bar.foobar.bar/hls/foo/bar/foobar_,24,36,48,0p.mp4/urlset/master.m3u8?cdn_hash=63c21767af6896fd305f08f8e9c5d5fb&cdn_creation_time=1615987169

The playlist parameters  24,36,48,0p are part of the URI path and should be included in the generation of the cdn_hash value as well.



Video Streaming Services

Delivering HLS Content

Speeding Up the HLS Delivery

Delivering MPEG-DASH Content

Combining Transmuxing to MPEG-DASH with Limit Access Using a Secret Key