How to implement a video-on-demand workflow on AWS leveraging AWS Step Functions, AWS Elemental MediaConvert, and AWS Elemental MediaPackage. Source code for Video on Demand on AWS solution.
The solution is deployed using a CloudFormation template with a lambda backed custom resource. For details on deploying the solution please see the details on the solution home page: Video on Demand on AWS
Please ensure you test the new template before updating any production deployments.
The workflow configuration is set at deployment and is defined as environment variables for the input-validate lambda function (which is the first step in the ingest process).
If deployed with the workflow trigger parameter set to VideoFile, the CloudFormation template will configure S3 event notifications on the source S3 bucket to trigger the workflow whenever a video file (mpg, mp4, m4v, mov, or m2ts) is uploaded.
If deployed with the workflow trigger parameter set to MetadataFile, the S3 notification is configured to trigger the workflow whenever a JSON file is uploaded. This allows different workflow configuration to be defined for each source video processed by the workflow.
Important: The source video file must be uploaded to S3 before the metadata file is uploaded, and the metadata file must be valid JSON with a .json file extension. With source metadata enabled uploading video files to Amazon S3 will not trigger the workflow.
Example JSON metadata file:
{
"srcVideo": "example.mpg",
"archiveSource": true,
"frameCapture": false,
"jobTemplate": "custom-job-template"
}
The only required field for the metadata file is the srcVideo. The workflow will default to the environment variables settings for the ingest validate lambda function for any settings not defined in the metadata file.
Full list of options:
{
"srcVideo": "string",
"archiveSource": string,
"frameCapture": boolean,
"srcBucket": "string",
"destBucket": "string",
"cloudFront": "string",
"jobTemplate_2160p": "string",
"jobTemplate_1080p": "string",
"jobTemplate_720p": "string",
"jobTemplate": "custom-job-template",
"inputRotate": "DEGREE_0|DEGREES_90|DEGREES_180|DEGREES_270|AUTO",
"captions": {
"srcFile": "string",
"fontSize": integer,
"fontColor": "WHITE|BLACK|YELLOW|RED|GREEN|BLUE"
}
}
The solution also supports adding additional metadata, such as title, genre, or any other information, you want to store in Amazon DynamoDB.
At launch the Solution creates 3 MediaConvert job templates which are used as the default encoding templates for the workflow:
By default, the profiler step in the process step function will check the source video height and set the parameter "jobTemplate" to one of the available templates. This variable is then passed to the encoding step which submits a job to AWS Elemental MediaConvert. To customize the encoding templates used by the solution you can either replace the existing templates or you can use the source metadata version of the workflow and define the jobTemplate as part of the source metadata file.
To replace the templates:
To define the job template using metadata:
AWS MediaConvert Quality-defined Variable Bit-Rate (QVBR) control mode gets the best video quality for a given file size and is recommended for OTT and Video On Demand Content. The solution supports this feature and it will create HLS, MP4 and DASH custom presets with the following QVBR levels and Single Pass HQ encoding:
Resolution | MaxBitrate | QvbrQualityLevel |
---|---|---|
2160p | 15000Kbps | 9 |
1080p | 8500Kbps | 8 |
720p | 6000Kbps | 8 |
720p | 5000Kbps | 8 |
540p | 3500Kbps | 7 |
360p | 1500Kbps | 7 |
270p | 400Kbps | 7 |
For more detail please see QVBR and MediaConvert.
Version 5.1.0 introduces support for accelerated transcoding which is a pro tier feature of AWS Elemental MediaConvert. This feature can be configured when launching the template with one of the following options:
For more detail please see Accelerated Transcoding.
./source/mediainfo/bin/mediainfo must be made executable before deploying to lambda.
The solution can be deployed through the CloudFormation template available on the solution home page: [Video on Demand on AWS][vod-ig]. To make changes to the solution, download or clone this repo, update the source code and then run the deployment/build-s3-dist.sh script to deploy the updated Lambda code to an Amazon S3 bucket in your account.
Run unit tests to make sure added customization passes the tests:
cd ./deployment
chmod +x ./run-unit-tests.sh
./run-unit-tests.sh
The CloudFormation template is configured to pull the Lambda deployment packages
from Amazon S3 bucket in the region the template is being launched in.
Create a bucket in the desired region with the region name appended to the name of the bucket
(e.g. for us-east-1 create a bucket named my-bucket-us-east-1
).
aws s3 mb s3://my-bucket-us-east-1
Build MediaInfo using the following commands on an EC2 instance running an Amazon Linux AMI.
sudo yum update -y
sudo yum groupinstall 'Development Tools' -y
sudo yum install libcurl-devel -y
wget https://mediaarea.net/download/binary/mediainfo/20.09/MediaInfo_CLI_20.09_GNU_FromSource.tar.xz
tar xvf MediaInfo_CLI_20.09_GNU_FromSource.tar.xz
cd MediaInfo_CLI_GNU_FromSource/
./CLI_Compile.sh --with-libcurl
Run these commands to confirm the compilation was successful:
cd MediaInfo/Project/GNU/CLI/
./mediainfo --version
Copy the mediainfo binary into the source/mediainfo/bin
directory of your cloned respository.
If you'd like to use a precompiled MediaInfo binary for Lambda built by the MediaArea team, you can download it here. For more information, check out the MediaInfo site.
First change directory into the deployment directory. Run the following commands to build the distribution.
chmod +x ./build-s3-dist.sh
./build-s3-dist.sh my-bucket video-on-demand-on-aws version
Notes: The build-s3-dist script expects the bucket name as one of its parameters, and this value should not include the region suffix.
Run this command to ensure that you are an owner of the AWS S3 bucket you are uploading files to.
aws s3api head-bucket --bucket my-bucket-us-east-1 --expected-bucket-owner <YOUR-AWS-ACCOUNT-ID>
Deploy the distributable to the Amazon S3 bucket in your account:
aws s3 sync ./regional-s3-assets/ s3://my-bucket-us-east-1/video-on-demand-on-aws/<version>/
aws s3 sync ./global-s3-assets/ s3://my-bucket-us-east-1/video-on-demand-on-aws/<version>/
This solution collects anonymized operational metrics to help AWS improve the quality of features of the solution. For more information, including how to disable this capability, please see the implementation guide.
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied. See the License for the specific language governing permissions and limitations under the License.