• About Us
  • Contact Us

How to Leverage AWS Elemental MediaConvert for Scalable Video Processing in the Cloud

Introduction

AWS Elemental MediaConvert is a powerful cloud-based service that enables users to convert and process video files at scale. It provides a streamlined approach to transcoding, encoding, and media processing, which are essential steps in delivering content in multiple formats. By handling these tasks in the cloud, MediaConvert removes the need for dedicated hardware and simplifies the workflow for both large-scale media companies and smaller teams. This article is designed to guide you through setting up AWS Elemental MediaConvert and leveraging it for scalable video processing.

Before starting, you will need an AWS account, a foundational understanding of cloud computing concepts, and some familiarity with video formats like MP4, HLS, and DASH.

Setting Up AWS Environment for MediaConvert

First, either create or log into your AWS account to access MediaConvert. Once logged in, navigate to the AWS Management Console and search for “MediaConvert” to locate the service. Proper permissions are essential, so you’ll need to set up IAM (Identity and Access Management) permissions and roles to ensure secure access to MediaConvert.

Console-based IAM Setup

To set up a new IAM role or user for MediaConvert access, go to the IAM service in your AWS console. Create a new IAM role with permissions such as MediaConvertFullAccess. Attach the policy to this role or user to allow access to MediaConvert.

CLI-based IAM Setup

You can also perform these tasks via the AWS CLI. First, create a new IAM role with the aws iam create-role command and specify the trust policy. Then, attach the MediaConvert policy using aws iam attach-role-policy.

aws iam create-role --role-name MediaConvertRole --assume-role-policy-document file://trust-policy.json 
aws iam attach-role-policy --role-name MediaConvertRole --policy-arn arn:aws:iam::aws:policy/MediaConvertFullAccess

Understanding MediaConvert Job Settings

A MediaConvert job represents the core of the video processing task, containing parameters for the input file, output settings, and formats. When configuring a job, consider input and output file types (e.g., MP4, HLS), bitrates, resolution, codec choice, and destination (e.g., an S3 bucket).

Console-based Job Setup

In the MediaConvert console, start by creating a new job. Select an input file from S3 and configure output settings like format and codec. Adjust resolutions, bitrate, and other details as needed.

CLI-based Job Setup

For a CLI-based approach, create a JSON configuration file with job parameters. To submit the job, use the command:

aws mediaconvert create-job --cli-input-json file://job.json

Uploading Videos to Amazon S3 for Processing

To process a video with MediaConvert, first upload it to an S3 bucket.

Console-based S3 Upload

Go to the S3 service in your AWS console, create or select a bucket, and upload the video file from your local storage.

CLI-based S3 Upload

Alternatively, use the CLI command aws s3 cp to upload the file directly:

aws s3 cp my-video.mp4 s3://your-bucket-name/

After uploading, ensure that MediaConvert has access to the S3 bucket by setting the correct permissions.

Setting Permissions

In the console, go to the S3 bucket’s permissions tab, and configure the bucket policy to allow access. Via CLI, use the following command to set a policy:

aws s3api put-bucket-policy --bucket your-bucket-name --policy file://bucket-policy.json

Creating a MediaConvert Job

Console-based Job Creation

In the MediaConvert console, create a new job. Select the input file from S3, configure output settings (like resolution and codec), and define the destination.

CLI-based Job Creation

For a more programmatic approach, use a job configuration JSON file. Submit this configuration with the CLI command:

aws mediaconvert create-job --cli-input-json file://job.json

Monitoring and Managing Jobs

MediaConvert provides tools for monitoring and managing job statuses.

Console-based Monitoring

In the MediaConvert console, navigate to the “Jobs” tab to see job statuses and progress.

CLI-based Monitoring

Check job status with:

aws mediaconvert get-job --id <job-id>

Handling Failures

If a job fails, review error messages in the console or retrieve logs using CLI.

aws mediaconvert get-job --id <job-id> --query "job.status" --output text

Storing and Accessing Processed Videos

Processed videos can be stored in an S3 bucket.

Setting Permissions

Ensure output files are accessible by configuring permissions in the S3 console. Modify object ACLs via CLI with:

aws s3api put-object-acl --bucket your-bucket-name --key path/to/processed-video.mp4 --acl public-read

Accessing Processed Videos

In the S3 console, locate the output file and download or share the link. Alternatively, download via CLI:

aws s3 cp s3://your-bucket-name/processed-video.mp4 ./local-directory/

Automating MediaConvert with AWS Lambda

To automate video processing, use AWS Lambda to trigger MediaConvert jobs upon new uploads to S3.

Setting Up Lambda Trigger

In the Lambda console, create a new function. Set up an S3 trigger, selecting the bucket and specifying “Object Created” events.

CLI-based Lambda Trigger Setup

To set this up via CLI, use commands to create and configure the S3 event source for Lambda.

Lambda Function Example

A sample Lambda function in Python to trigger MediaConvert could look like this:

import boto3

def lambda_handler(event, context):
    # Create a MediaConvert client
    mediaconvert = boto3.client('mediaconvert', region_name='us-west-2')
    
    # Define the job settings
    job_settings = {
        'Role': 'arn:aws:iam::YOUR_ACCOUNT_ID:role/YOUR_ROLE_NAME',  # IAM role that MediaConvert uses
        'Settings': {
            'Inputs': [
                {
                    'FileInput': 's3://YOUR_BUCKET_NAME/YOUR_INPUT_FILE.mp4',
                    'AudioSelectors': {
                        'Audio Selector 1': {
                            'DefaultSelection': 'DEFAULT'
                        }
                    },
                    'VideoSelector': {},
                    'FilterEnable': 'AUTO',
                    'PsiControl': 'USE_PSI',
                    'FilterStrength': 0,
                    'DeblockFilter': 'DISABLED',
                    'DenoiseFilter': 'DISABLED',
                    'TimecodeSource': 'ZEROBASED'
                }
            ],
            'OutputGroups': [
                {
                    'OutputGroupSettings': {
                        'Type': 'HLS_GROUP',
                        'HlsGroupSettings': {
                            'Destination': 's3://YOUR_BUCKET_NAME/YOUR_OUTPUT_PATH/',
                            'SegmentLength': 10,
                            'MinSegmentLength': 0
                        }
                    },
                    'Outputs': [
                        {
                            'Preset': 'System-Ott_Hls_High',
                            'ContainerSettings': {
                                'Container': 'M3U8',
                            },
                            'VideoDescription': {
                                'Width': 1920,
                                'Height': 1080,
                                'ScalingBehavior': 'DEFAULT',
                                'CodecSettings': {
                                    'Codec': 'H_264',
                                    'H264Settings': {
                                        'RateControlMode': 'CBR',
                                        'MaxBitrate': 5000000,
                                        'GopSize': 60,
                                        'NumRefFrames': 3,
                                        'EntropyEncoding': 'CABAC',
                                    }
                                }
                            },
                            'AudioDescriptions': [
                                {
                                    'AudioTypeControl': 'FOLLOW_INPUT',
                                    'AudioSourceName': 'Audio Selector 1',
                                    'CodecSettings': {
                                        'Codec': 'AAC',
                                        'AacSettings': {
                                            'Bitrate': 96000,
                                            'CodingMode': 'CODING_MODE_2_0',
                                            'SampleRate': 48000,
                                        }
                                    }
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    }

    # Create the MediaConvert job
    try:
        response = mediaconvert.create_job(**job_settings)
        print(f"MediaConvert Job Created: {response['Job']['Id']}")
        return {
            'statusCode': 200,
            'body': f"Job created successfully: {response['Job']['Id']}"
        }
    except Exception as e:
        print(f"Error creating MediaConvert job: {e}")
        return {
            'statusCode': 500,
            'body': f"Error creating job: {str(e)}"
        }

Cost Optimization Tips

AWS MediaConvert pricing is based on output format and resolution. Select efficient codecs and resolutions to manage costs. You can also set up cost alerts in the AWS console to monitor usage.

Advanced Configurations (Optional)

MediaConvert supports advanced features like closed captioning, multi-format outputs, and custom thumbnails. Experiment with configurations to enhance media quality and usability.

Conclusion

In summary, AWS Elemental MediaConvert offers scalable, efficient video processing in the cloud. By uploading videos to S3, configuring MediaConvert jobs, and automating workflows with Lambda, you can streamline video processing. AWS documentation and online tutorials provide additional resources to explore the service’s full potential. Experiment with various settings to understand the flexibility and capabilities MediaConvert offers for media processing in the cloud.