Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/agsh/rtsp-ffmpeg
Node.js FFMpeg wrapper for streaming RTSP into MotionJPEG
https://github.com/agsh/rtsp-ffmpeg
ffmpeg-wrapper hacktoberfest nodejs rtsp rtsp-stream
Last synced: 11 days ago
JSON representation
Node.js FFMpeg wrapper for streaming RTSP into MotionJPEG
- Host: GitHub
- URL: https://github.com/agsh/rtsp-ffmpeg
- Owner: agsh
- License: mit
- Created: 2015-03-27T10:02:55.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-07-16T13:39:21.000Z (4 months ago)
- Last Synced: 2024-09-17T06:27:30.441Z (about 2 months ago)
- Topics: ffmpeg-wrapper, hacktoberfest, nodejs, rtsp, rtsp-stream
- Language: JavaScript
- Homepage:
- Size: 65.4 KB
- Stars: 248
- Watchers: 15
- Forks: 84
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rtsp-ffmpeg
Lazy Node.js FFMpeg wrapper for streaming RTSP into MotionJPEG. It runs FFMpeg process only when someone is subscribed to
its `data` event. Every `data` event contains one image `Buffer` object.## Installation
1. Download [FFmpeg](http://www.ffmpeg.org/) to your local machine.
2. Install package in your project `npm install rtsp-ffmpeg`
## Sample
With [socket.io](http://socket.io/) library.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):
### NB!
this is not efficient example, but simple. For drawing images on canvas please look at this [example](https://github.com/agsh/rtsp-ffmpeg/blob/master/example/index-canvas.html) by [Seikon](https://github.com/Seikon):
```htmlvar img = document.getElementById('img'),
socket = io('');
socket.on('data', function(data) {
img.src = 'data:image/jpeg;base64,' + data;
});```
For more detailed example look at [/example/server.js](/example/server.js)
For the large resolution images or IP cameras example check [/example/server-canvas.js](/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';
```