Created
July 26, 2023 17:29
-
-
Save sanju2/da8ec14e709fd1705d8e947e4954e68a to your computer and use it in GitHub Desktop.
AWS Elemental MediaConvert Service - Article
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Queue": "arn:aws:mediaconvert:region:account_id:queues/Default", | |
"UserMetadata": {}, | |
"Role": "arn:aws:iam::account_id:role/MediaConvert_Default_Role", | |
"Settings": { | |
"TimecodeConfig": { | |
"Source": "ZEROBASED" | |
}, | |
"OutputGroups": [ | |
{ | |
"Name": "File Group", | |
"Outputs": [ | |
{ | |
"ContainerSettings": { | |
"Container": "MP4", | |
"Mp4Settings": {} | |
}, | |
"VideoDescription": { | |
"CodecSettings": { | |
"Codec": "H_265", | |
"H265Settings": { | |
"MaxBitrate": 5000000, | |
"RateControlMode": "QVBR", | |
"SceneChangeDetect": "TRANSITION_DETECTION" | |
} | |
} | |
}, | |
"AudioDescriptions": [ | |
{ | |
"AudioSourceName": "Audio Selector 1", | |
"CodecSettings": { | |
"Codec": "AAC", | |
"AacSettings": { | |
"Bitrate": 96000, | |
"CodingMode": "CODING_MODE_2_0", | |
"SampleRate": 48000 | |
} | |
} | |
} | |
], | |
"NameModifier": "-hd" | |
}, | |
{ | |
"ContainerSettings": { | |
"Container": "MP4", | |
"Mp4Settings": {} | |
}, | |
"VideoDescription": { | |
"Width": 256, | |
"Height": 144, | |
"CodecSettings": { | |
"Codec": "AV1", | |
"Av1Settings": { | |
"RateControlMode": "QVBR", | |
"QvbrSettings": {}, | |
"MaxBitrate": 100000 | |
} | |
} | |
}, | |
"AudioDescriptions": [ | |
{ | |
"CodecSettings": { | |
"Codec": "AAC", | |
"AacSettings": { | |
"Bitrate": 96000, | |
"CodingMode": "CODING_MODE_2_0", | |
"SampleRate": 48000 | |
} | |
} | |
} | |
], | |
"NameModifier": "-sd" | |
} | |
], | |
"OutputGroupSettings": { | |
"Type": "FILE_GROUP_SETTINGS", | |
"FileGroupSettings": { | |
"Destination": "s3://destination_bucket/" | |
} | |
} | |
} | |
], | |
"Inputs": [ | |
{ | |
"AudioSelectors": { | |
"Audio Selector 1": { | |
"DefaultSelection": "DEFAULT" | |
} | |
}, | |
"VideoSelector": {}, | |
"TimecodeSource": "ZEROBASED", | |
"FileInput": "s3://source_bucket/object.mp4" | |
} | |
] | |
}, | |
"AccelerationSettings": { | |
"Mode": "DISABLED" | |
}, | |
"StatusUpdateInterval": "SECONDS_60", | |
"Priority": 0 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import boto3 | |
def lambda_handler(event, context): | |
mediaconvert = boto3.client('mediaconvert') | |
mediaconvert_endpoint = mediaconvert.describe_endpoints(MaxResults=1) | |
mediaconvert = boto3.client('mediaconvert', endpoint_url=f"{mediaconvert_endpoint['Endpoints'][0]['Url']}") | |
for message in event['Records']: | |
# REPLACE ME # | |
destination_bucket = 'cattube-destination' | |
############## | |
source_bucket = message['s3']['bucket']['name'] | |
object = message['s3']['object']['key'] | |
accountid = context.invoked_function_arn.split(":")[4] | |
region = context.invoked_function_arn.split(":")[3] | |
with open("job.json", "r") as jsonfile: | |
job_config = json.load(jsonfile) | |
job_config['Queue'] = f"arn:aws:mediaconvert:{region}:{accountid}:queues/catqueue" | |
job_config['Role'] = f"arn:aws:iam::{accountid}:role/MediaConvert_Default_Role" | |
job_config['Settings']['Inputs'][0]['FileInput'] = f"s3://{source_bucket}/{object}" | |
job_config['Settings']['OutputGroups'][0]['OutputGroupSettings']['FileGroupSettings']['Destination'] = f"s3://{destination_bucket}/" | |
response = mediaconvert.create_job(**job_config) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment