Last active
January 5, 2023 11:10
-
-
Save sbarski/93db5c0cd75a01dd86c3 to your computer and use it in GitHub Desktop.
A Lambda function that creates and submits an Elastic Transcoder job after being invoked by an S3 bucket
This file contains hidden or 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
'use strict'; | |
var AWS = require('aws-sdk'); | |
var s3 = new AWS.S3({ | |
apiVersion: '2012-09-25' | |
}); | |
var eltr = new AWS.ElasticTranscoder({ | |
apiVersion: '2012-09-25', | |
region: 'us-east-1' | |
}); | |
exports.handler = function(event, context) { | |
console.log('Executing Elastic Transcoder Orchestrator'); | |
var bucket = event.Records[0].s3.bucket.name; | |
var key = event.Records[0].s3.object.key; | |
var pipelineId = '1446424116409-5pdjj8'; | |
console.log(key); | |
console.log(event.Records[0]); | |
if (bucket !== 'acloud-video-input') { | |
context.fail('Incorrect Video Input Bucket'); | |
return; | |
} | |
var srcKey = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, " ")); //the object may have spaces | |
var newKey = key.split('.')[0]; | |
var params = { | |
PipelineId: pipelineId, | |
OutputKeyPrefix: newKey + '/', | |
Input: { | |
Key: srcKey, | |
FrameRate: 'auto', | |
Resolution: 'auto', | |
AspectRatio: 'auto', | |
Interlaced: 'auto', | |
Container: 'auto' | |
}, | |
Outputs: [{ | |
Key: 'mp4-' + newKey + '.mp4', | |
ThumbnailPattern: 'thumbs-' + newKey + '-{resolution}' + '-{count}', | |
PresetId: '1351620000001-000010', //Generic 720p | |
Watermarks: [{ | |
InputKey: 'watermarks/logo-horiz-large.png', | |
PresetWatermarkId: 'BottomRight' | |
}], | |
}, | |
{ | |
Key: 'webm-' + newKey + '.webm', | |
ThumbnailPattern: '', | |
PresetId: '1351620000001-100240', //Webm 720p | |
Watermarks: [{ | |
InputKey: 'watermarks/logo-horiz-large.png', | |
PresetWatermarkId: 'BottomRight' | |
}], | |
}, | |
{ | |
Key: 'hls-' + newKey + '.ts', | |
ThumbnailPattern: '', | |
PresetId: '1351620000001-200010', //HLS v3 2mb/s | |
Watermarks: [{ | |
InputKey: 'watermarks/logo-horiz-large.png', | |
PresetWatermarkId: 'BottomRight' | |
}], | |
}] | |
}; | |
console.log('Starting Job'); | |
eltr.createJob(params, function(err, data){ | |
if (err){ | |
console.log(err); | |
} else { | |
console.log(data); | |
} | |
context.succeed('Job well done'); | |
}); | |
}; |
TimeSpan :{
StartTime : '00:00:01',
Duration : '00:00:15'
}
how to set intervals between Thumbails?
Can it be added in 'ThumbnailPattern' ?
It is great! Saved me a lot of time.
Now I have a problem create 2 jobs at the same time? How to solve this problem?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to use clip ?