Skip to content

Instantly share code, notes, and snippets.

@blewert
Created September 28, 2021 21:47
Show Gist options
  • Save blewert/f92395d576d6ed477a548a18b71ee5f8 to your computer and use it in GitHub Desktop.
Save blewert/f92395d576d6ed477a548a18b71ee5f8 to your computer and use it in GitHub Desktop.
const config = require('./cfg/streams.json');
const { spawn } = require('child_process');
var streamProcs = [];
for(let stream of config.streams)
{
let streamProc = spawn("node", ["stream.js", stream.port, stream.url ]);
console.log(`> Started stream ${stream.key} on port ${stream.port}: ${stream.url}`);
streamProc.on('exit', (code) =>
{
console.log(`Stream process exited with code ${code}`);
})
streamProcs.push(streamProc);
}
if(process.argv.length <= 3)
{
console.log("not enough args: port & url");
process.exit(1);
}
let port = process.argv[2];
let url = process.argv[3];
Stream = require('node-rtsp-stream');
stream = new Stream
({
name: `stream (${url})`,
streamUrl: url,
wsPort: port,
ffmpegOptions: { // options ffmpeg flags
'-stats': '', // an option with no neccessary value uses a blank string
'-r': 30 // options with required values specify the value after the key
}
});
{
"streams": [
{
"port": 6969,
"key": "test1",
"url": "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"
},
{
"port": 6970,
"key": "test2",
"url": "rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov"
}
]
}
<html>
<body>
<canvas id="canvas"></canvas>
<canvas id="canvas2"></canvas>
</body>
<script type="text/javascript" src="jsmpeg.min.js"></script>
<script type="text/javascript">
player = new JSMpeg.Player('ws://localhost:6969', {
canvas: document.getElementById('canvas') // Canvas should be a canvas DOM element
})
player = new JSMpeg.Player('ws://localhost:6970', {
canvas: document.getElementById('canvas2') // Canvas should be a canvas DOM element
})
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment