Skip to main content

Transcoding larger video files

To transcode large video files that a serverless code function can't handle, you need to use a dedicated transcoding service. This page demonstrates how to do this with AWS.

Transcoding large video files on AWS

There are three main services we'll be making use of here:

  • AWS Elemental MediaConvert: the service that will actually perform the video transcoding

  • AWS EventBridge: the service that will notify us when a transcoding job is completed, so we can automatically update our databases or whatever else we want to do.

  • AWS Lambda: to receive notifications from EventBridge, and update our database with the newly transcoded video URLs.

Technically, you don't need Lambda and EventBridge here if you wanted to run a few videos through MediaConvert manually. However, unlike say the Lambda API, you can't schedule a MediaConvert job and then wait to get a response, so we are using Lambda here to process the response.

Invoking MediaConvert via the AWS SDK

Here's an example of how to start a transcoding job, in Node.js:

import { CreateJobCommand, MediaConvertClient } from "@aws-sdk/client-mediaconvert";

let mediaConvertClient = new MediaConvertClient({
    region: "<the AWS region you want to use>",
    /*
      The endpoint is a unique URL for your account, per region. You can
      find it in the MediaConvert "account" tab.
    */
    endpoint: "<your MediaConvert endpoint for the region>",
    credentials: {
        accessKeyId: "<your user's IAM access key>",
        secretAccessKey: "<your user's IAM secret key>",
    },
});

let params = {
    JobTemplate: "<the name of the JobTemplate> to use",
    Role: "arn:aws:iam::<your AWS account number>:role/service-role/<your IAM role for using MediaConvert>",
    Settings: {
        Inputs: [
          {
            FileInput: "<the S3 URL to the video you want to transcode>",
          },
        ],
    },
};

let command = new CreateJobCommand(params);
let response = await mediaConvertClient.send(command);