Skip to content

Instantly share code, notes, and snippets.

@mmcc
Last active December 17, 2015 16:38
Show Gist options
  • Save mmcc/5639753 to your computer and use it in GitHub Desktop.
Save mmcc/5639753 to your computer and use it in GitHub Desktop.
Live CDN example
{
"live_stream": true,
"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"
}
]
}
]
}
// require Zencoder integration library
var Zencoder = require('zencoder')
, colors = require('colors');
// create a new client
var client = new Zencoder();
console.log('Sending API request...'.blue);
// send a request
client.Job.create({
"live_stream": true,
"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; }
// otherwise everything's cool
// Output the stream name and url first
client.Job.details(data.id, function(err, data){
console.log('Stream ID: ' + data.job.stream.id);
});
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