Skip to content

Instantly share code, notes, and snippets.

@armenr
Created April 23, 2021 15:47
Show Gist options
  • Save armenr/38017cf3c316f956dd29b1549e945906 to your computer and use it in GitHub Desktop.
Save armenr/38017cf3c316f956dd29b1549e945906 to your computer and use it in GitHub Desktop.
amplify-video category stuff
{
"Description": "Amplify MediaConvert template for audio-only pipelines",
"Queue": "arn:aws:mediaconvert:us-east-1:REDACTED_ACCOUNT_NUMBER:queues/Default",
"Name": "audio_template",
"Settings": {
"TimecodeConfig": {
"Source": "ZEROBASED"
},
"OutputGroups": [
{
"Name": "Apple HLS",
"Outputs": [
{
"ContainerSettings": {
"Container": "M3U8",
"M3u8Settings": {
"AudioFramesPerPes": 4,
"PcrControl": "PCR_EVERY_PES_PACKET",
"PmtPid": 480,
"PrivateMetadataPid": 503,
"ProgramNumber": 1,
"PatInterval": 0,
"PmtInterval": 0,
"Scte35Source": "NONE",
"NielsenId3": "NONE",
"TimedMetadata": "NONE",
"VideoPid": 481,
"AudioPids": [482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492],
"AudioDuration": "DEFAULT_CODEC_DURATION"
}
},
"AudioDescriptions": [
{
"AudioTypeControl": "FOLLOW_INPUT",
"AudioSourceName": "Audio Selector 1",
"CodecSettings": {
"Codec": "AAC",
"AacSettings": {
"AudioDescriptionBroadcasterMix": "NORMAL",
"Bitrate": 320000,
"RateControlMode": "CBR",
"CodecProfile": "LC",
"CodingMode": "CODING_MODE_2_0",
"RawFormat": "NONE",
"SampleRate": 96000,
"Specification": "MPEG4"
}
},
"LanguageCodeControl": "FOLLOW_INPUT"
}
],
"OutputSettings": {
"HlsSettings": {
"AudioGroupId": "program_audio",
"DescriptiveVideoServiceFlag": "DONT_FLAG",
"AudioOnlyContainer": "AUTOMATIC",
"IFrameOnlyManifest": "EXCLUDE"
}
},
"NameModifier": "_audio"
}
],
"OutputGroupSettings": {
"Type": "HLS_GROUP_SETTINGS",
"HlsGroupSettings": {
"ManifestDurationFormat": "INTEGER",
"SegmentLength": 10,
"TimedMetadataId3Period": 10,
"CaptionLanguageSetting": "OMIT",
"TimedMetadataId3Frame": "PRIV",
"CodecSpecification": "RFC_4281",
"OutputSelection": "MANIFESTS_AND_SEGMENTS",
"ProgramDateTimePeriod": 600,
"MinSegmentLength": 0,
"MinFinalSegmentLength": 0,
"DirectoryStructure": "SINGLE_DIRECTORY",
"ProgramDateTime": "EXCLUDE",
"SegmentControl": "SEGMENTED_FILES",
"ManifestCompression": "NONE",
"ClientCache": "ENABLED",
"AudioOnlyHeader": "INCLUDE",
"StreamInfResolution": "INCLUDE"
}
}
}
],
"AdAvailOffset": 0,
"Inputs": [
{
"AudioSelectors": {
"Audio Selector 1": {
"Offset": 0,
"DefaultSelection": "DEFAULT",
"ProgramSelection": 1
}
},
"FilterEnable": "AUTO",
"PsiControl": "USE_PSI",
"FilterStrength": 0,
"DeblockFilter": "DISABLED",
"DenoiseFilter": "DISABLED",
"InputScanType": "AUTO",
"TimecodeSource": "ZEROBASED"
}
]
},
"AccelerationSettings": {
"Mode": "DISABLED"
},
"StatusUpdateInterval": "SECONDS_60",
"Priority": 0,
"HopDestinations": []
}
/* eslint-disable */
const AWS = require('aws-sdk')
/* eslint-enable */
const s3 = new AWS.S3({})
/* eslint-disable */
exports.handler = function(event, context) {
/* eslint-enable */
const config = event.ResourceProperties
console.log(config)
const responseData = {}
switch (event.RequestType) {
case 'Create':
if (config.BucketFunction === 'Input') {
createInputNotifications(config)
} else {
createOutputNotifications(config)
}
break
case 'Delete':
deleteNotifications(config)
break
default:
console.log('No changes')
}
const response = sendResponse(event, context, 'SUCCESS', responseData)
console.log('CFN STATUS:: ', response)
}
function sendResponse(event, context, responseStatus, responseData) {
const responseBody = JSON.stringify({
Status: responseStatus,
Reason: `See the details in CloudWatch Log Stream: ${context.logStreamName}`,
PhysicalResourceId: context.logStreamName,
StackId: event.StackId,
RequestId: event.RequestId,
LogicalResourceId: event.LogicalResourceId,
Data: responseData
})
console.log('RESPONSE BODY:\n', responseBody)
const https = require('https')
const url = require('url')
const parsedUrl = url.parse(event.ResponseURL)
const options = {
hostname: parsedUrl.hostname,
port: 443,
path: parsedUrl.path,
method: 'PUT',
headers: {
'content-type': '',
'content-length': responseBody.length
}
}
console.log('SENDING RESPONSE...\n')
const request = https.request(options, response => {
console.log(`STATUS: ${response.statusCode}`)
console.log(`HEADERS: ${JSON.stringify(response.headers)}`)
// Tell AWS Lambda that the function execution is done
context.done()
})
request.on('error', error => {
console.log(`sendResponse Error:${error}`)
// Tell AWS Lambda that the function execution is done
context.done()
})
// write data to request body
request.write(responseBody)
request.end()
}
function createOutputNotifications(config) {
const params = {
Bucket: config.BucketName,
NotificationConfiguration: {
LambdaFunctionConfigurations: [
{
Events: ['s3:ObjectCreated:*'],
LambdaFunctionArn: config.IngestArn,
Filter: {
Key: {
FilterRules: [
{
Name: 'suffix',
Value: '.m3u8'
}
]
}
}
},
{
Events: ['s3:ObjectCreated:*'],
LambdaFunctionArn: config.IngestArn,
Filter: {
Key: {
FilterRules: [
{
Name: 'suffix',
Value: '.ts'
}
]
}
}
}
]
}
}
console.log(params)
s3.putBucketNotificationConfiguration(params, (err, data) => {
if (err) console.log(err, err.stack)
else console.log(data)
})
}
function createInputNotifications(config) {
const params = {
Bucket: config.BucketName,
NotificationConfiguration: {
LambdaFunctionConfigurations: [
{
Events: ['s3:ObjectCreated:*'],
LambdaFunctionArn: config.IngestArn,
Filter: {
Key: {
FilterRules: [
{
Name: 'suffix',
Value: '.m4a'
}
]
}
}
},
{
Events: ['s3:ObjectCreated:*'],
LambdaFunctionArn: config.IngestArn,
Filter: {
Key: {
FilterRules: [
{
Name: 'suffix',
Value: '.wav'
}
]
}
}
},
{
Events: ['s3:ObjectCreated:*'],
LambdaFunctionArn: config.IngestArn,
Filter: {
Key: {
FilterRules: [
{
Name: 'suffix',
Value: '.aac'
}
]
}
}
},
{
Events: ['s3:ObjectCreated:*'],
LambdaFunctionArn: config.IngestArn,
Filter: {
Key: {
FilterRules: [
{
Name: 'suffix',
Value: '.wma'
}
]
}
}
},
{
Events: ['s3:ObjectCreated:*'],
LambdaFunctionArn: config.IngestArn,
Filter: {
Key: {
FilterRules: [
{
Name: 'suffix',
Value: '.mp3'
}
]
}
}
},
{
Events: ['s3:ObjectCreated:*'],
LambdaFunctionArn: config.IngestArn,
Filter: {
Key: {
FilterRules: [
{
Name: 'suffix',
Value: '.mpg'
}
]
}
}
},
{
Events: ['s3:ObjectCreated:*'],
LambdaFunctionArn: config.IngestArn,
Filter: {
Key: {
FilterRules: [
{
Name: 'suffix',
Value: '.mp4'
}
]
}
}
},
{
Events: ['s3:ObjectCreated:*'],
LambdaFunctionArn: config.IngestArn,
Filter: {
Key: {
FilterRules: [
{
Name: 'suffix',
Value: '.pcm'
}
]
}
}
},
{
Events: ['s3:ObjectCreated:*'],
LambdaFunctionArn: config.IngestArn,
Filter: {
Key: {
FilterRules: [
{
Name: 'suffix',
Value: '.ogg'
}
]
}
}
},
{
Events: ['s3:ObjectCreated:*'],
LambdaFunctionArn: config.IngestArn,
Filter: {
Key: {
FilterRules: [
{
Name: 'suffix',
Value: '.m2ts'
}
]
}
}
},
{
Events: ['s3:ObjectCreated:*'],
LambdaFunctionArn: config.IngestArn,
Filter: {
Key: {
FilterRules: [
{
Name: 'suffix',
Value: '.mov'
}
]
}
}
}
]
}
}
console.log(params)
s3.putBucketNotificationConfiguration(params, (err, data) => {
if (err) console.log(err, err.stack)
else console.log(data)
})
}
function deleteNotifications(config) {
console.log(config)
// Do nothing for now
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment