ffmpeg wrapper for rtsp streaming via node.js
npm install rtsp-ffmpegdata event. Every data event contains one image Buffer object.1. Download FFmpeg to your local machine.
2. Install package in your project npm install rtsp-ffmpeg
Server:
``javascript`
const app = require('express')(),
server = require('http').Server(app),
io = require('socket.io')(server),
rtsp = require('rtsp-ffmpeg');
server.listen(6147);
var uri = 'rtsp://freja.hiof.no:1935/rtplive/definst/hessdalen03.stream',
stream = new rtsp.FFMpeg({input: uri});
io.on('connection', function(socket) {
var pipeStream = function(data) {
socket.emit('data', data.toString('base64'));
};
stream.on('data', pipeStream);
socket.on('disconnect', function() {
stream.removeListener('data', pipeStream);
});
});
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});
Client (index.html):
html
![]()
`For more detailed example look at /example/server.js
For the large resolution images or IP cameras example check /example/server-canvas.js
FFMpeg
`javascript
var ffmpeg = new FFMpeg({
input: 'rtsp://localhost' // stream uri
, rate: 10 // output framerate (optional)
, resolution: '640x480' // output resolution in WxH format (optional)
, quality: 3 // JPEG compression quality level (optional)
});
`If you have an error
Error: spawn ffmpeg ENOENT, you should first install ffmpeg package.
After that, if the starup command differs from ffmpeg, you can change it in the static property like this, for example:
`js
FFMpeg.cmd = 'C:\\ffmpeg.exe';
``