Created
February 23, 2015 18:30
-
-
Save grvhi/fbda7c0afed03ae1ef8c to your computer and use it in GitHub Desktop.
Revisions
-
George Irwin created this gist
Feb 23, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,100 @@ console.log('Checking newly uploaded file'); var AWS = require('aws-sdk'); var s3 = new AWS.S3({apiVersion: '2006-03-01'}); var eltr = new AWS.ElasticTranscoder({ apiVersion: '2012-09-25', region: 'us-east-1' }); // ID of pipeline var pipelineId = 'myID'; // ID of ET's web output preset var webMP4Preset = 'webMP4Preset'; // Our custom WebM format var webMPresetCustom = 'webMPreset'; // Our custom ogg format var oggPresetCustom = 'oggPreset'; exports.handler = function(event, context) { // Get the object from the event and show its content type var bucket = event.Records[0].s3.bucket.name; var key = event.Records[0].s3.object.key; if (bucket != 'my-bucket') { console.log('Not my-bucket') } s3.headObject({ Bucket:bucket, Key:key }, function(err, data) { if (err) { console.log('error getting object ' + key + ' from bucket ' + bucket + '. Make sure they exist and your bucket is in the same region as this function.'); context.done('ERROR', 'error getting file' + err); } else { if (data.Metadata.type == 'video') { console.log('Found new video: ' + key + ', sending to ET'); var today = new Date(); var dd = today.getDate(); var mm = today.getMonth() + 1; var yyyy = today.getFullYear(); if (dd < 10) { dd = '0' + dd; }; if (mm < 10) { mm = '0' + mm; }; today = dd + '-' + mm + '-' + yyyy + '/'; var newKey = key.split('.')[0]; var params = { PipelineId: pipelineId, OutputKeyPrefix: today, Input: { Key: key, FrameRate: 'auto', Resolution: 'auto', AspectRatio: 'auto', Interlaced: 'auto', Container: 'auto' }, Outputs: [ { Key: 'mp4-' + newKey, ThumbnailPattern: 'thumbs-' + newKey + '-{count}', PresetId: webMP4Preset, Rotate: 'auto', UserMetadata: { uuid: data.Metadata.uuid, video_type: 'mp4' } }, { Key: 'webm-' + newKey, ThumbnailPattern: '', PresetId: webMPresetCustom, Rotate: 'auto', UserMetadata: { uuid: data.Metadata.uuid, video_type: 'webm' } } ] }; eltr.createJob(params, function (error, data) { if (error) { console.log('Failed to send new video ' + key + ' to ET'); console.log(error); } else { console.log(data); } context.done(null,''); }); } else { console.log('Upload ' + key + 'was not video'); console.log(JSON.stringify(data.Metadata)); } } } ); };