So I'm playing around with Elastic transcoder to convert an uploaded video from my S3 bucket to a GIF.
At the moment, when I upload to S3, I have a basic lambda which triggers a pipeline to do the converting to gif.
Now whats happening here is I upload a 7mb mp4 and when its transcoded the output gif is 80+ MB's??
I've looked through the docs and I cant find anything that helps me. Can anyone shed some light...
Below is my presets in elastic transcoding
Codec -- gif
Codec Options:
LoopCount: 5
Bit Rate -- auto
Frame Rate -- auto
Video Max Frame Rate -- 10
Max Width -- auto
Max Height -- auto
Sizing Policy -- ShrinkToFit
Padding Policy -- NoPad
Display Aspect Ratio -- auto
Any my lamdba looks like so:
'use strict';
var AWS = require('aws-sdk'),
transcoder = new AWS.ElasticTranscoder({
apiVersion: '2012-09-25',
region: 'eu-west-1'
});
exports.handler = (event, context, callback) => {
let fileName = event.Records[0].s3.object.key;
var srcKey = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, " "));
var newKey = fileName.split('.')[0];
console.log('New video has been uploaded:', fileName);
transcoder.createJob({
PipelineId: process.env.PIPELINE_ID,
Input: {
Key: srcKey,
FrameRate: 'auto',
Resolution: 'auto',
AspectRatio: 'auto',
Interlaced: 'auto',
Container: 'auto'
},
Output: {
Key: getOutputName(fileName),
ThumbnailPattern: '',
PresetId: 'XXXXXXXXXXX',
Rotate: 'auto'
}
}, function(err, data){
if(err){
console.log('Something went wrong:',err)
}else{
console.log('Converting is done');
}
callback(err, data);
});
};
function getOutputName(srcKey){
let baseName = srcKey.replace('videos/','');
let withOutExtension = removeExtension(baseName);
return 'gifs/' + withOutExtension + '.gif';
}
function removeExtension(srcKey){
let lastDotPosition = srcKey.lastIndexOf(".");
if (lastDotPosition === -1) return srcKey;
else return srcKey.substr(0, lastDotPosition);
}