Create AES-128 encrypted HLS package

Create a Master playlist profile that will list all sub-streams into one file.

Then create a profile for each sub-stream of your Master Playlist. Each profile sub-stream (EXT-X-STREAM-INF) contains RESOLUTION, BANDWIDTH tags to help the client to choose an appropriate stream.

iOS devices will stream the best variant depending on the quality of the network connection.

## Sub streams
TelestreamCloud::Profile.create!(
  :name => "hls.iphone.400k",
  :preset_name => "hls.variant",
  :video_bitrate => 400,
  :segment_time => 5
)
TelestreamCloud::Profile.create!(
  :name => "hls.iphone.600k",
  :preset_name => "hls.variant",
  :video_bitrate => 600,
  :segment_time => 5
)
TelestreamCloud::Profile.create!(
  :name => "hls.ipad.1200k",
  :preset_name => "hls.variant",
  :video_bitrate => 1200,
  :segment_time => 5
)
TelestreamCloud::Profile.create!(
  :name => "hls.audio",
  :preset_name => "hls.variant.audio",
  :segment_time => 5
)

## iPhone and iPad Playlist
TelestreamCloud::Profile.create!(
  :name => "iphone",
  :preset_name => "hls.variant.playlist",
  :variants => "hls.iphone*,hls.audio",
  :extname => ".tar"
)
TelestreamCloud::Profile.create!(
  :name => "ipad",
  :preset_name => "hls.variant.playlist",
  :variants => "hls.iphone*,hls.ipad*,hls.audio",
  :extname => ".tar"
)

Adding Encryption

To use AES-128 HLS encryption, Telestream Cloud will require a 128 bit key, key url and 128 bit initialization vector. If you are willing to use your own key or initialization vector (IV), you can create them yourself.

cipher = OpenSSL::Cipher::AES.new(128, :CBC)
cipher.encrypt
key = cipher.random_key
iv = cipher.random_iv

There are two ways to create encrypted output using Telestream Cloud:

  • add encryption_key and encryption_key_url to profile(s) and send the videos with encryption_iv only
  • send each video with encryption_key, encryption_key_url and encryption_iv

Please note that if you decide to use the second option while the encryption_key and encryption_key_url are set for profile(s), we will use those specified for the video object.

In order to use your generated key in the profile settings or for the video, you will have to first base64 encode it. Make sure to remove any newline characters at the end.

encoded_key = Base64.encode64(key).chomp
encoded_iv = Base64.encode64(iv).chomp

Here's a code example on how to pass the encryption key and initialization vector data when creating a video:

TelestreamCloud::Video.create!(
   :source_url => "https://storage.googleapis.com/debug_videos/panda.mp4",
   :encryption_key => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
   :encryption_key_url => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
   :encryption_iv => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
   )