Node.js FFMPEG Project to View RTSP Live Video Stream in Browser Using Express.js Server & rtsp-relay Library in Javascript

 

 RTSP Relay

Build Status Coverage Status npm version npm bundle size

This module allows you to view an RTSP stream in your web browser using an existing express.js server.

Internally, this module uses websockets to create an endpoint in your web server (e.g. /api/stream) which relays the RTSP stream using ffmpeg. On the client side, JS-MPEG is used to decode the websocket stream.

The module handles all the complications that unreliable connections introduce:

  • if the connection between server <=> RTSP stream is disconnected, it will automatically be reconnected when available
  • if the connection between client <=> server is disconnected, the client will keep trying to reconnect
  • if multiple clients connect, only one instance of the RTSP stream is consumed to improve performance (one-to-many)

Install

You don’t need to install ffmpeg!

 

 

Example using ES6 Imports (e.g. React, Vue)

If you have babel/webpack set up, you can import the loadPlayer instead of using a <script> tag.

Example code is available for react and for angular.

 

 

Usage with many cameras

 

 

If you have hundreds of cameras and don’t want to define a seperate route for each one, you can use a dynamic URL:

Usage with many clients

You may see a MaxListenersExceededWarning if the relay is re-transmitting 10+ streams at once, or if 10+ clients are watching.

This is expected, and you can silence the warning by adding process.setMaxListeners(0); to your code.

Improving the video quality

Depending on your network configuration, you can try the following options to improve the stream quality:

Note that both these methods will use more bandwidth.

SSL

If you want to use HTTPS, you will need to change the stream URL to wss://, like the following example:

 

Leave a Reply