Created
March 20, 2017 22:47
-
-
Save birme/14a8e9a949adbbd4f845784035718609 to your computer and use it in GitHub Desktop.
This file contains 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 elastictranscoder = new aws.ElasticTranscoder(); | |
function basename(path) { | |
return path.split('/').reverse()[0].split('.')[0]; | |
} | |
exports.handler = (event, context) => { | |
console.log('Received event:', JSON.stringify(event, null, 2)); | |
var key = event.Records[0].s3.object.key; | |
var params = { | |
Input: { | |
Key: key | |
}, | |
PipelineId: '1490041561796-qwjcof', | |
OutputKeyPrefix: 'mp4/', | |
Outputs: [ | |
{ | |
Key: basename(key) + '-720-1500.mp4', | |
PresetId: '1490042345276-y6d4x4', | |
}, | |
{ | |
Key: basename(key) + '-540-800.mp4', | |
PresetId: '1490042422290-co7emz', | |
}, | |
{ | |
Key: basename(key) + '-360-400.mp4', | |
PresetId: '1490042462549-vigab6', | |
}, | |
] | |
}; | |
elastictranscoder.createJob(params, function(err, data) { | |
if (err){ | |
console.log(err, err.stack); // an error occurred | |
context.fail(); | |
return; | |
} | |
// Write SMIL file | |
var s3 = new aws.S3(); | |
var switches = '<video height="360" src="mp4:' + basename(key) + '-360-400.mp4" width="640"><param name="videoBitrate" value="400000" valuetype="data"></param></video>'; | |
switches += '<video height="540" src="mp4:' + basename(key) + '-540-800.mp4" width="960"><param name="videoBitrate" value="800000" valuetype="data"></param></video>'; | |
switches += '<video height="720" src="mp4:' + basename(key) + '-720-1500.mp4" width="1280"><param name="videoBitrate" value="1500000" valuetype="data"></param></video>'; | |
var smilBody = '<body><switch>' + switches + '</switch></body>' | |
var xml = '<?xml version="1.0" encoding="UTF-8"?><smil title="">' + smilBody + '</smil>'; | |
var params = { | |
Bucket : 'lab-ott-store', | |
Key : 'mp4/' + basename(key) + '.smil', | |
Body : xml | |
} | |
s3.putObject(params, function(err, data) { | |
if (err) console.log(err, err.stack); // an error occurred | |
else console.log(data); // successful response | |
context.succeed(); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment