Skip to content

Instantly share code, notes, and snippets.

@uiur
Created September 22, 2015 12:45
Show Gist options
  • Save uiur/6aea9ae576274a71dc62 to your computer and use it in GitHub Desktop.
Save uiur/6aea9ae576274a71dc62 to your computer and use it in GitHub Desktop.
aws lambda mp4 -> gif
var aws = require('aws-sdk')
var s3 = new aws.S3()
var exec = require('child_process').exec
var fs = require('fs')
exports.handler = function (event, context) {
console.log(JSON.stringify(event, null, 2))
var bucket = event.Records[0].s3.bucket.name;
var key = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, " ")) ;
var file = fs.createWriteStream('/tmp/data.mp4')
var stream = s3.getObject({Bucket: bucket, Key: key}).createReadStream()
stream.pipe(file)
stream.on('end', function () {
exec('./ffmpeg -i /tmp/data.mp4 -r 10 /tmp/out.gif', function (err) {
var body = fs.createReadStream('/tmp/out.gif')
new aws.S3({params: {Bucket: 'lambda-ffmpeg', Key: 'data.gif'}}).upload({ Body: body }, function (err) {
context.succeed()
})
})
})
}
@uiur
Copy link
Author

uiur commented Sep 22, 2015

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