-
-
Save uiur/6aea9ae576274a71dc62 to your computer and use it in GitHub Desktop.
aws lambda mp4 -> gif
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
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() | |
}) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
download binary http://johnvansickle.com/ffmpeg/