Skip to content

Instantly share code, notes, and snippets.

@mmcc
Created January 24, 2014 21:35
Show Gist options
  • Save mmcc/8606999 to your computer and use it in GitHub Desktop.
Save mmcc/8606999 to your computer and use it in GitHub Desktop.
Convert some BC Play videos.
var zc = require('zencoder')()
, request = require('request')
, options = {};
function initialize(output_location) {
var timestamp = new Date();
options.folder = timestamp.toISOString() + '/';
options.base_url = "s3://zencoder-jobs/"
console.log("Files will be placed in " + options.folder);
getRenditions();
}
function getRenditions() {
request.get('https://play-brightcove-com.herokuapp.com/temp-video-data', function(err, res) {
if (err) return console.log(err);
console.log('Grabbed renditions. Parsing...');
parseRenditions(res.body);
});
};
function parseRenditions(renditions) {
var parsedRenditions = JSON.parse(renditions);
parsedRenditions.forEach(function(value) {
submitRequest(value.referenceId, value.rendition.url);
});
};
function submitRequest(referenceId, location) {
var url = options.base_url + options.folder + referenceId;
zc.Job.create({
input: location,
region: 'us-west',
outputs: [
{
label: 'mp4-high',
url: url + '-high.mp4',
height: '720',
h264_profile: 'main'
},
{
label: 'mp4-low',
url: url + '-low.mp4',
height: '480'
},
{
label: 'webm',
url: url + '.webm',
height: '720'
}
]
}, function(err, data) {
if (err) return console.log(err.message);
console.log('Submitted ' + referenceId + '. Job ID: ' + data.id);
});
};
initialize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment