{"id":13565545,"url":"https://github.com/k-yle/rtsp-relay","last_synced_at":"2025-05-15T03:07:06.223Z","repository":{"id":41530521,"uuid":"236266798","full_name":"k-yle/rtsp-relay","owner":"k-yle","description":"📽 View an RTSP stream in your web browser using an express.js server","archived":false,"fork":false,"pushed_at":"2025-05-14T08:36:53.000Z","size":26083,"stargazers_count":362,"open_issues_count":59,"forks_count":63,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-14T09:45:42.262Z","etag":null,"topics":["express","ffmpeg","jsmpeg","rtsp","rtsp-stream","websocket"],"latest_commit_sha":null,"homepage":"https://npm.im/rtsp-relay","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/k-yle.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"ko_fi":"kylenz"}},"created_at":"2020-01-26T04:31:26.000Z","updated_at":"2025-05-13T19:53:01.000Z","dependencies_parsed_at":"2023-02-18T09:01:25.140Z","dependency_job_id":"25767bed-bde0-495d-8be7-d29703d29ba9","html_url":"https://github.com/k-yle/rtsp-relay","commit_stats":{"total_commits":145,"total_committers":7,"mean_commits":"20.714285714285715","dds":0.5931034482758621,"last_synced_commit":"60fe38199550164fe2b544d8678f20b04c68a83d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k-yle%2Frtsp-relay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k-yle%2Frtsp-relay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k-yle%2Frtsp-relay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k-yle%2Frtsp-relay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/k-yle","download_url":"https://codeload.github.com/k-yle/rtsp-relay/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254138882,"owners_count":22021078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","ffmpeg","jsmpeg","rtsp","rtsp-stream","websocket"],"created_at":"2024-08-01T13:01:49.742Z","updated_at":"2025-05-15T03:07:01.208Z","avatar_url":"https://github.com/k-yle.png","language":"JavaScript","funding_links":["https://ko-fi.com/kylenz"],"categories":["JavaScript"],"sub_categories":[],"readme":"# 📽 RTSP Relay\n\n[![Build Status](https://github.com/k-yle/rtsp-relay/workflows/build/badge.svg)](https://github.com/k-yle/rtsp-relay/actions)\n[![Coverage Status](https://coveralls.io/repos/github/k-yle/rtsp-relay/badge.svg?branch=main)](https://coveralls.io/github/k-yle/rtsp-relay?branch=main)\n[![npm version](https://badge.fury.io/js/rtsp-relay.svg)](https://badge.fury.io/js/rtsp-relay)\n![npm bundle size](https://img.shields.io/bundlephobia/minzip/rtsp-relay)\n\nThis module allows you to view an RTSP stream in your web browser using an existing express.js server.\n\nInternally, 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.\n\nThe module handles all the complications that unreliable connections introduce:\n\n- if the connection between `server` \u003c=\u003e `RTSP stream` is disconnected, it will automatically be reconnected when available\n- if the connection between `client` \u003c=\u003e `server` is disconnected, the client will keep trying to reconnect\n- if multiple clients connect, only one instance of the RTSP stream is consumed to improve performance (one-to-many)\n\n## Install\n\n```sh\nnpm install -S rtsp-relay express\n```\n\nYou don't need to install ffmpeg!\n\n## Example\n\n```js\nconst express = require('express');\nconst app = express();\n\nconst { proxy, scriptUrl } = require('rtsp-relay')(app);\n\nconst handler = proxy({\n  url: `rtsp://admin:admin@10.0.1.2:554/feed`,\n  // if your RTSP stream need credentials, include them in the URL as above\n  verbose: false,\n});\n\n// the endpoint our RTSP uses\napp.ws('/api/stream', handler);\n\n// this is an example html page to view the stream\napp.get('/', (req, res) =\u003e\n  res.send(`\n  \u003ccanvas id='canvas'\u003e\u003c/canvas\u003e\n\n  \u003cscript src='${scriptUrl}'\u003e\u003c/script\u003e\n  \u003cscript\u003e\n    loadPlayer({\n      url: 'ws://' + location.host + '/api/stream',\n      canvas: document.getElementById('canvas')\n    });\n  \u003c/script\u003e\n`),\n);\n\napp.listen(2000);\n```\n\nOpen [http://localhost:2000](http://localhost:2000) in your web browser.\n\n## Example using ES6 Imports (e.g. React, Vue)\n\nIf you have babel/webpack set up, you can import the `loadPlayer` instead of using a `\u003cscript\u003e` tag.\n\nExample code is available [for react](examples/react.md) and [for angular](examples/angular.md).\n\n```js\n// client side code\nimport { loadPlayer } from 'rtsp-relay/browser';\n\nloadPlayer({\n  url: `ws://${location.host}/stream`,\n  canvas: document.getElementById('canvas'),\n\n  // optional\n  onDisconnect: () =\u003e console.log('Connection lost!'),\n});\n```\n\n### Usage with many cameras\n\nIf you have hundreds of cameras and don't want to define a seperate route for each one, you can use a dynamic URL:\n\n```js\napp.ws('/api/stream/:cameraIP', (ws, req) =\u003e\n  proxy({\n    url: `rtsp://${req.params.cameraIP}:554/feed`,\n  })(ws),\n);\n```\n\n### Usage with many clients\n\nYou may see a `MaxListenersExceededWarning` if the relay is re-transmitting 10+ streams at once, or if 10+ clients are watching.\n\nThis is expected, and you can silence the warning by adding `process.setMaxListeners(0);` to your code.\n\n### Improving the video quality\n\nDepending on your network configuration, you can try the following options to improve the stream quality:\n\n```js\n// try this:\napp.ws('/api/stream', proxy({ additionalFlags: ['-q', '1'] }));\n\n// or this:\napp.ws('/api/stream', proxy({ transport: 'tcp' }));\n```\n\nNote that both these methods will use more bandwidth.\n\n### SSL\n\nIf you want to use HTTPS, you will need to change the stream URL to `wss://`, like the following example:\n\n```js\nconst rtspRelay = require('rtsp-relay');\nconst express = require('express');\nconst https = require('https');\nconst fs = require('fs');\n\nconst key = fs.readFileSync('./privatekey.pem', 'utf8');\nconst cert = fs.readFileSync('./fullchain.pem', 'utf8');\nconst ca = fs.readFileSync('./chain.pem', 'utf8'); // required for iOS 15+\n\nconst app = express();\nconst server = https.createServer({ key, cert, ca }, app);\n\nconst { proxy, scriptUrl } = rtspRelay(app, server);\n\napp.ws('/api/stream', proxy({ url: 'rtsp://1.2.3.4:554' }));\n\napp.get('/', (req, res) =\u003e\n  res.send(`\n  \u003ccanvas id='canvas'\u003e\u003c/canvas\u003e\n\n  \u003cscript src='${scriptUrl}'\u003e\u003c/script\u003e\n  \u003cscript\u003e\n    loadPlayer({\n      url: 'wss://' + location.host + '/api/stream',\n      canvas: document.getElementById('canvas')\n    });\n  \u003c/script\u003e\n`),\n);\n\nserver.listen(443);\n```\n\n## Contributing\n\nWe have end-to-end tests to ensure that the module actually works. These tests spin up a RTSP server using [aler9/rtsp-simple-server](https://github.com/aler9/rtsp-simple-server) and create several different streams for testing. These tests are far from complete.\n\nTo 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`).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fk-yle%2Frtsp-relay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fk-yle%2Frtsp-relay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fk-yle%2Frtsp-relay/lists"}