I have a IP Camera that supports RTSP, and I need to display this stream to multiple clients using HTML5.
Since HTML Video tag doesn't support RTSP, I'm calling ffmpeg to encode it to a WEBM stream, but the result is very glitchy and distorts the original stream.
The command im using is the following:
ffmpeg -i my_RSTP_URL -vcodec libvpx -f webm -
To distribute the stream I'm using a Node.js instance that calls the rtsp stream via ffpmeg when needed.
The solution looks like such:
Camera --Via RSTP--> ffmpeg --Encodes to WEBM--> Node.js --Via HTML5 Video--> Client
Node.js code:
var request = require('request');
var http = require('http');
var child_process = require("child_process");
var stdouts = {};
http.createServer(function (req, resp) {
switch (params[0])
{
case "LIVE":
resp.writeHead(200, {'Content-Type': 'video/mp4', 'Connection': 'keep-alive'});
// Start ffmpeg
var ffmpeg = child_process.spawn("ffmpeg",[
"-i","my_RSTP_URL", // Capture offset
"-vcodec","libvpx", // vp8 encoding
"-f","webm", // File format
"-" // Output to STDOUT
]);
ffmpeg.on('exit', function()
{
console.log('ffmpeg terminado');
});
ffmpeg.on('error',function(e)
{
console.log(e);
})
ffmpeg.stdout.on('data',function(data)
{
console.log('datos'+data);
});
ffmpeg.stderr.on('data', function(data) {
console.log('stderr'+data);
});
stdouts[params[1]] = ffmpeg.stdout;
// Pipe the video output to the client response
ffmpeg.stdout.pipe(resp);
console.log("Initializing camera");
break;
}
}).listen(8088);
console.log('Server running at port 8088');
Am I using the wrong library codec? Or why Am I getting such a weird result?
It seems to me, this can help for https://github.com/kyriesent/node-rtsp-stream Also I worked with this technology, you can visit repository on bitBucket: https://bitbucket.org/kaleniuk_ihor/neuro_vision/src/db_watch/
Оn the other hand, your code may not work because you did not install ffmpeg at the root of drive C.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With