All Projects → k-yle → rtsp-relay

k-yle / rtsp-relay

Licence: MIT license
📽 View an RTSP stream in your web browser using an express.js server

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
HTML
75241 projects

Projects that are alternatives of or similar to rtsp-relay

rtsp-samsung-tv
Display RTSP streams from IP Cameras on Samsung Smart TV (Tizen TV)
Stars: ✭ 40 (-73.86%)
Mutual labels:  rtsp, rtsp-stream
node-rtsp-stream-es6
Stream any RTSP stream and output to websocket for consumption by jsmpeg. 📹
Stars: ✭ 91 (-40.52%)
Mutual labels:  jsmpeg, rtsp-stream
camera-live-streaming
Camera Live Streaming with Flask and Open-CV
Stars: ✭ 69 (-54.9%)
Mutual labels:  rtsp, rtsp-stream
GStreamer-Python
Fetch RTSP Stream using GStreamer in Python and get image in Numpy
Stars: ✭ 81 (-47.06%)
Mutual labels:  rtsp, rtsp-stream
node-rtsp-recorder
Records and saves RTSP Video Streams
Stars: ✭ 50 (-67.32%)
Mutual labels:  rtsp, rtsp-stream
plugin-rtsp
rtsp协议实现,接受RTSP推流以及提供拉流转发功能
Stars: ✭ 104 (-32.03%)
Mutual labels:  rtsp
react-native-vlc-media-player
React native media player for video streaming and playing. Supports RTSP, RTMP and other protocols supported by VLC player
Stars: ✭ 221 (+44.44%)
Mutual labels:  rtsp
streamer
Go Package built around spinning up streaming processes
Stars: ✭ 37 (-75.82%)
Mutual labels:  rtsp
mini
OpenSource Mini IP camera streamer
Stars: ✭ 64 (-58.17%)
Mutual labels:  rtsp
Nager.VideoStream
Get images from a network camera stream or webcam
Stars: ✭ 27 (-82.35%)
Mutual labels:  rtsp
v4l2web
V4L2 web interface
Stars: ✭ 20 (-86.93%)
Mutual labels:  rtsp
fapro
Fake Protocol Server
Stars: ✭ 1,338 (+774.51%)
Mutual labels:  rtsp
wyzecam-hls
Converts MP4 files from WyzeCam NFS to HLS stream. Much more stable alternative to RTSP firmware.
Stars: ✭ 58 (-62.09%)
Mutual labels:  rtsp
ArRtspTool
将RTSP或者NV-RTX上的摄像头流转为webrtc可直接观看的流,延迟低至200ms,Web无插件、Native等全平台低延时拉流
Stars: ✭ 38 (-75.16%)
Mutual labels:  rtsp
gstreamer-rtc-streamer
webrtc streamer based on gstreamer
Stars: ✭ 65 (-57.52%)
Mutual labels:  rtsp
retina
High-level RTSP multimedia streaming library, in Rust
Stars: ✭ 80 (-47.71%)
Mutual labels:  rtsp
live555ProxyServerEx
Improved version of the "LIVE555 Proxy Server"
Stars: ✭ 35 (-77.12%)
Mutual labels:  rtsp
docker-wyze-bridge
RTMP/RTSP/LL-HLS bridge for Wyze cams in a docker container
Stars: ✭ 1,146 (+649.02%)
Mutual labels:  rtsp
rtsp-types
RTSP (RFC 7826) types and parsers/serializers
Stars: ✭ 16 (-89.54%)
Mutual labels:  rtsp
RTSPhuzz
RTSPhuzz - An RTSP Fuzzer written using the Boofuzz framework
Stars: ✭ 33 (-78.43%)
Mutual labels:  rtsp

📽 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

npm install -S rtsp-relay express

You don't need to install ffmpeg!

Example

const express = require('express');
const app = express();

const { proxy, scriptUrl } = require('rtsp-relay')(app);

const handler = proxy({
  url: `rtsp://admin:[email protected]:554/feed`,
  // if your RTSP stream need credentials, include them in the URL as above
  verbose: false,
});

// the endpoint our RTSP uses
app.ws('/api/stream', handler);

// this is an example html page to view the stream
app.get('/', (req, res) =>
  res.send(`
  <canvas id='canvas'></canvas>

  <script src='${scriptUrl}'></script>
  <script>
    loadPlayer({
      url: 'ws://' + location.host + '/api/stream',
      canvas: document.getElementById('canvas')
    });
  </script>
`),
);

app.listen(2000);

Open http://localhost:2000 in your web browser.

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.

// client side code
import { loadPlayer } from 'rtsp-relay/browser';

loadPlayer({
  url: `ws://${location.host}/stream`,
  canvas: document.getElementById('canvas'),

  // optional
  onDisconnect: () => console.log('Connection lost!'),
});

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:

app.ws('/api/stream/:cameraIP', (ws, req) =>
  proxy({
    url: `rtsp://${req.params.cameraIP}:554/feed`,
  })(ws),
);

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:

// try this:
app.ws('/api/stream', proxy({ additionalFlags: ['-q', '1'] }));

// or this:
app.ws('/api/stream', proxy({ transport: 'tcp' }));

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:

const rtspRelay = require('rtsp-relay');
const express = require('express');
const https = require('https');
const fs = require('fs');

const key = fs.readFileSync('./privatekey.pem', 'utf8');
const cert = fs.readFileSync('./fullchain.pem', 'utf8');
const ca = fs.readFileSync('./chain.pem', 'utf8'); // required for iOS 15+

const app = express();
const server = https.createServer({ key, cert, ca }, app);

const { proxy, scriptUrl } = rtspRelay(app, server);

app.ws('/api/stream', proxy({ url: 'rtsp://1.2.3.4:554' }));

app.get('/', (req, res) =>
  res.send(`
  <canvas id='canvas'></canvas>

  <script src='${scriptUrl}'></script>
  <script>
    loadPlayer({
      url: 'wss://' + location.host + '/api/stream',
      canvas: document.getElementById('canvas')
    });
  </script>
`),
);

server.listen(443);

Contributing

We have end-to-end tests to ensure that the module actually works. These tests spin up a RTSP server using aler9/rtsp-simple-server and create several different streams for testing. These tests are far from complete.

To make developing easier, run node test/setupTests. This creates two RTSP streams that can be used instead of real IP cameras (rtsp://localhost:8554/sync-test-1 and rtsp://localhost:8554/sync-test-2).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].