Skip to content

Instantly share code, notes, and snippets.

@mmcc
Last active January 2, 2016 14:48
Show Gist options
  • Save mmcc/8318780 to your computer and use it in GitHub Desktop.
Save mmcc/8318780 to your computer and use it in GitHub Desktop.
Live stream to Zencoder CDN. Requires cdn feature flag to be enabled on the account.
// require Zencoder integration library
var zencoder = require('zencoder')()
, colors = require('colors');
console.log('Sending API request...'.blue);
// send a request
zencoder.Job.create({
"live_stream": true,
"event_length": 600,
"reconnect_time": 45,
"outputs": [
{
"label": "rtmp300",
"size": "480x270",
"video_bitrate": 300,
"live_stream": true
},
{
"label": "rtmp600",
"size": "640x360",
"video_bitrate": 600,
"live_stream": true
},
{
"label": "rtmp1200",
"size": "1280x720",
"video_bitrate": 1200,
"live_stream": true
},
{
"label": "hls300",
"size": "480x270",
"type": "segmented",
"video_bitrate": 300,
"live_stream": true
},
{
"label": "hls600",
"size": "640x360",
"type": "segmented",
"video_bitrate": 600,
"live_stream": true
},
{
"label": "hls1200",
"size": "1280x720",
"type": "segmented",
"video_bitrate": 1200,
"live_stream": true
},
{
"label": "hlsmaster",
"live_stream": true,
"type": "playlist",
"streams": [
{
"bandwidth": 300,
"path": "hls300/index.m3u8"
},
{
"bandwidth": 600,
"path": "hls600/index.m3u8"
},
{
"bandwidth": 1200,
"path": "hls1200/index.m3u8"
}
]
}
]
}, function(err, data) {
// check for an error response
if (err) { console.log('There was an error.'.red); console.log(err); return; }
// We don't get the Stream ID initially, so make a
// details request to grab that just in case it's needed
zencoder.Job.details(data.id, function(err, data){
console.log('Stream ID: ' + data.job.stream.id);
});
// otherwise everything's cool
// Output the stream name and url first
console.log('Stream Information'.underline.green);
console.log('Stream URL: ' + data.stream_url.green);
console.log('Stream Name: ' + data.stream_name.green);
console.log('');
// Output information to watch the stream
console.log('Outputs'.underline.cyan);
for (var url in data.outputs) {
var output = data.outputs[url]
console.log(output.label + ' \t' + output.url.cyan);
}
console.log('');
// All done
console.log('------ Enjoy! --------'.white);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment