AWS elastic transcoder -- Gif output is massive

Viewed 247

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);
}
1 Answers

There is absolutely no error here, GIFs are BIG.

A 10 second mp4 at 24 frames/sec at a resolution of 1024x768 and a color space of 3 bytes (1 for each of red green and blue) contains 540 MB of data.

Video compression is AMAZING and it can really squeeze that into something small, but GIFs are notoriously inefficient at doing the same. Also, their quality is abysmal. For more information on this, please check out this amazing answer: https://superuser.com/questions/53600/jpeg-vs-png-vs-bmp-vs-gif-vs-svg

For the solution to your problem: Use WebP

It is universally supported, much more efficient, and looks a lot better.

Also, be careful with hosting costs in AWS, as only data IN is free, data going OUT can get very expensive!

Related