Skip to content

Instantly share code, notes, and snippets.

@sbarski
Last active January 5, 2023 11:10
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save sbarski/93db5c0cd75a01dd86c3 to your computer and use it in GitHub Desktop.
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
'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');
});
};
@umesh0492
Copy link

how to use clip ?

@umesh0492
Copy link

TimeSpan :{
			StartTime : '00:00:01',
			Duration : '00:00:15'
		}

@umertauheedkhan
Copy link

umertauheedkhan commented Aug 13, 2019

how to set intervals between Thumbails?
Can it be added in 'ThumbnailPattern' ?

@jacksun0124
Copy link

It is great! Saved me a lot of time.

@vongpharim
Copy link

Now I have a problem create 2 jobs at the same time? How to solve this problem?

@vongpharim
Copy link

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment