Skip to content

Instantly share code, notes, and snippets.

@birme
Last active May 11, 2021 09:10
Show Gist options
  • Save birme/fa0ff9f76735a8fef35dbfcf00d07dd1 to your computer and use it in GitHub Desktop.
Save birme/fa0ff9f76735a8fef35dbfcf00d07dd1 to your computer and use it in GitHub Desktop.
/**
* This NodeJS gist creates a virtual linear channel (VOD2Live) with one ad break (105 sec) and a trailer,
* both on loop.
*
* npm install --save eyevinn-channel-engine
* node server.js
*
* Then play the HLS from:
* http://localhost:8000/live/master.m3u8?channel=1
*
*/
const ChannelEngine = require("eyevinn-channel-engine");
const STITCH_ENDPOINT = process.env.STITCH_ENDPOINT || "http://lambda.eyevinn.technology/stitch/master.m3u8";
class MyAssetManager {
getNextVod(vodRequest) {
return new Promise((resolve, reject) => {
const payload = {
uri: "https://maitv-vod.lab.eyevinn.technology/UNHINGED_Trailer_2020.mp4/master.m3u8",
breaks: [
{
pos: 0,
duration: 105 * 1000,
url: "https://maitv-vod.lab.eyevinn.technology/VINN.mp4/master.m3u8"
}
]
};
const buff = Buffer.from(JSON.stringify(payload));
const encodedPayload = buff.toString("base64");
const vod = {
id: 1,
title: "VINN",
uri: STITCH_ENDPOINT + "?payload=" + encodedPayload,
}
resolve(vod);
});
}
}
class MyChannelManager {
getChannels() {
return [ { id: "1", profile: this._getProfile() }];
}
_getProfile() {
return [
{ bw: 6134000, codecs: 'avc1.4d001f,mp4a.40.2', resolution: [ 1024, 458 ] },
{ bw: 2323000, codecs: 'avc1.4d001f,mp4a.40.2', resolution: [ 640, 286 ] },
{ bw: 1313000, codecs: 'avc1.4d001f,mp4a.40.2', resolution: [ 480, 214 ] }
];
}
}
const myAssetManager = new MyAssetManager();
const myChannelManager = new MyChannelManager();
const engine = new ChannelEngine(myAssetManager, {
heartbeat: "/",
defaultSlateUri: "https://maitv-vod.lab.eyevinn.technology/slate-consuo.mp4/master.m3u8",
averageSegmentDuration: 7200,
channelManager: myChannelManager,
});
engine.start();
engine.listen(process.env.port || 8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment