Tuesday, August 1, 2017

Create HLSv3 videos in AWS from S3 via Lambda and ElasticTranscoder

Working on HTTP Live Streaming I've followed the AWS Mobile Blog article:

https://aws.amazon.com/blogs/mobile/streaming-videos-to-mobile-app-users-via-amazon-cloudfront-cdn/

where a nice serverless architecture is presented:

  1. Upload mp4 file to an s3 bucket
  2. A trigger watching the s3 bucket invokes a Lambda function
  3. Which invokes the Elastic Transcoder to turn the video from mp4 to HLS and saves to another s3 bucket for your usage
  4. Use in your website/mobile app via CloudFront

After I've went through all the steps I've ended up with HLSv4 videos in my Target S3 folder. They are working great in Safari or with the Chrome's Native HLS Playback extension. But, when I tried in:

  • VLC - I've got an error after loading the master-file *.m3u8. I've examined the VLC Messages console and got to the cause of the error, which       

            httplive error: #EXT-X-VERSION should be version 1, 2 or 3 iso 4


         The error means that the HLSv4 is not supported in VLC 2.x. It will be supported in VLC 3.x, which is not yet released.
          AVFoundationErrorDomain -11800 HLS


So I had to modify my Lambda function to produce HLSv3 instead of HLSv4. It's a little bit tweaking of the Presets used when encoding the video. As I've spent some time reading through the ElasticTranscoder SDK documentation and the Presets, I think it's worth sharing the lambda code for HLSv3 encoding to save some time:




Happy transcoding!