Git Product home page Git Product logo

rtsp-streaming-server's Introduction

rtsp-streaming-server

Lightweight RTSP/RTP streaming media server written in Javascript.

First things first, credit to @revmischa for their work on the perl-based server. This is basically a blatant rip-off of that but ported to Javascript (and now typescript!). See the original here revmischa/rtsp-server

Use this module to run an RTSP server in javascript. Common use case is for load balancing

Running

npm install --save rtsp-streaming-server

Add the following to your script where you want to run the server:

import RtspServer from 'rtsp-streaming-server'

const server = new RtspServer({
	serverPort: 5554,
	clientPort: 6554,
	rtpPortStart: 10000,
	rtpPortCount: 10000
});


async function run (): void {
	try {
		await server.start();
	} catch (e) {
		console.error(e);
	}
}

run();

If you're using javascript, you'll have to require the default export:

const RtspServer = require('rtsp-streaming-server').default;

Use an RTSP producer that supports ANNOUNCE (such as ffmpeg):

ffmpeg -i <your_input>.mp4 -c:v copy -f rtsp rtsp://127.0.0.1:5554/stream1

Consume that stream from your favourite RTSP Client (note that you have to use the client port, not the publish port):

ffplay -i rtsp://127.0.0.1:6554/stream1

stream1 can be whatever you want, this server supports many producers and consumers on different mount points

Options

  • serverPort: port to listen to incoming RTSP/RTP streams from producers on
  • clientPort: port to listen to incoming RTSP requests from clients on
  • rtpPortStart: UDP port to start at for requests
  • rtpPortCount: Number of UDP Ports to use for requests. This needs to be a multiple of 2 as pairs of ports are assigned for RTP sessions. If this is set too low and it runs out then no more streams will work
  • publishServerHooks: object of hooks for the publishing server
  • clientServerHooks: object of hooks for the client server

Hooks

Hooks are ways to allow / disallow connections to the server based on certain conditions. These need to be placed in the publishServerHooks or clientServerHooks objects

Authentication is to authenticate users connecting. A failed authentication sends a 401.

async function authentication (username: string, password: string): Promise<boolean> {
	if (username === 'test' && password === 'test') return true;
	
	return false;
}

Check mount is to allow / deny publishing or consuming depending on the uri of the stream being requested:

async function checkMount (req: RtspRequest): Promise<boolean | number> {
  const url = new URL(req.uri);
  if (url.pathname === '/test/1') {
    return true;
  }

	// If you want to reject the client side consuming with a specific code, return a number:
	if (somereason) {
		return 503; //Bad Gateway
	}

  return false;
}

Client Close is to do some tidy up when a client leaves (i.e you might want to signal to your publisher it can stop the stream). This is only valid in clientServerHooks

async function clientClose (mount: Mount): Promise<void> {
  console.log(`A client has disconnected from ${mount.path}`);
}

Typescript information

If you're wanting to access any of the internal server components that reference the rtsp-server module, you'll have to add the types for this module types/rtsp-server.d.ts to your own project. These types are not in the server module itself.

Improvements coming soon (or PR's welcome!)

  • RTP interleaved in RTSP (RTP over RTSP)
  • Check RTP is being received by the server and tear down the connection / mount if not

rtsp-streaming-server's People

Contributors

cdebost avatar chriswiggins avatar louis49 avatar slyoldfox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rtsp-streaming-server's Issues

Unable to read from VLC - experience server crash

Hi,

On a basic server implementation, I can't get a VLC client to connect to the server, and the server crashes (Windows).
Server code:

const RtspServer = require('rtsp-streaming-server').default;

const server = new RtspServer({
	serverPort: 5554,
	clientPort: 6554,
	rtpPortStart: 10000,
	rtpPortCount: 10000
});
 
 
async function run () {
   try { 
     await server.start();
   } catch (e) { 
     console.error(e);
   }
}
 
run();

The stream comes from FFMPEG - only Video H264 encoding - here is my app streaming on rtsp://localhost:5554/stream1:
video-stream
When connecting VLC on address: 'rtsp://localhost:6554/stream1'
rtsp_vlc I get rejected - and the server crashes:
rtsp-server-crash

Not sure where I should look at,
thanks !

Production installation

When importing from an other package, I can't install my project with a NODE_ENV="production" (aka not installing dev deps)

Log :
npm ERR! code 1
npm ERR! git dep preparation failed
npm ERR! command /opt/homebrew/Cellar/node/17.5.0/bin/node /opt/homebrew/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/Users/XXX/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm ERR! code 1
npm ERR! npm ERR! path /Users/XXX/.npm/_cacache/tmp/git-clone7jwn10
npm ERR! npm ERR! command failed
npm ERR! npm ERR! command sh -c npm run build
npm ERR! npm ERR! > [email protected] build
npm ERR! npm ERR! > npm run type-check && npm run build:js
npm ERR! npm ERR!
npm ERR! npm ERR!
npm ERR! npm ERR! > [email protected] type-check
npm ERR! npm ERR! > tsc --emitDeclarationOnly
npm ERR! npm ERR!
npm ERR! npm ERR! src/lib/Client.ts(1,38): error TS2307: Cannot find module 'dgram' or its corresponding type declarations.
npm ERR! npm ERR! src/lib/Client.ts(3,28): error TS2307: Cannot find module 'uuid' or its corresponding type declarations.
npm ERR! npm ERR! src/lib/Client.ts(73,9): error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.
npm ERR! npm ERR! src/lib/Client.ts(81,11): error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.
npm ERR! npm ERR! src/lib/Client.ts(139,17): error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try npm i @types/node.
npm ERR! npm ERR! src/lib/Client.ts(139,17): error TS4073: Parameter 'buf' of public method from exported class has or is using private name 'Buffer'.
npm ERR! npm ERR! src/lib/Client.ts(149,18): error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try npm i @types/node.
npm ERR! npm ERR! src/lib/Client.ts(149,18): error TS4073: Parameter 'buf' of public method from exported class has or is using private name 'Buffer'.
npm ERR! npm ERR! src/lib/ClientServer.ts(1,23): error TS2307: Cannot find module 'basic-auth' or its corresponding type declarations.
npm ERR! npm ERR! src/lib/ClientServer.ts(57,11): error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.
npm ERR! npm ERR! src/lib/ClientServer.ts(130,37): error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try npm i @types/node.
npm ERR! npm ERR! src/lib/ClientServer.ts(170,7): error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.
npm ERR! npm ERR! src/lib/ClientWrapper.ts(2,28): error TS2307: Cannot find module 'uuid' or its corresponding type declarations.
npm ERR! npm ERR! src/lib/ClientWrapper.ts(20,22): error TS2503: Cannot find namespace 'NodeJS'.
npm ERR! npm ERR! src/lib/ClientWrapper.ts(20,22): error TS4031: Public property 'keepaliveTimeout' of exported class has or is using private name 'NodeJS'.
npm ERR! npm ERR! src/lib/ClientWrapper.ts(55,44): error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try npm i @types/node.
npm ERR! npm ERR! src/lib/ClientWrapper.ts(80,7): error TS2304: Cannot find name 'clearTimeout'.
npm ERR! npm ERR! src/lib/ClientWrapper.ts(95,7): error TS2304: Cannot find name 'clearTimeout'.
npm ERR! npm ERR! src/lib/ClientWrapper.ts(98,29): error TS2304: Cannot find name 'setTimeout'.
npm ERR! npm ERR! src/lib/Mount.ts(1,28): error TS2307: Cannot find module 'uuid' or its corresponding type declarations.
npm ERR! npm ERR! src/lib/Mount.ts(85,11): error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.
npm ERR! npm ERR! src/lib/Mount.ts(93,13): error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.
npm ERR! npm ERR! src/lib/Mount.ts(124,11): error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.
npm ERR! npm ERR! src/lib/PublishServer.ts(1,23): error TS2307: Cannot find module 'basic-auth' or its corresponding type declarations.
npm ERR! npm ERR! src/lib/PublishServer.ts(53,11): error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.
npm ERR! npm ERR! src/lib/PublishServer.ts(208,7): error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.
npm ERR! npm ERR! src/lib/RtpUdp.ts(1,38): error TS2307: Cannot find module 'dgram' or its corresponding type declarations.
npm ERR! npm ERR! src/lib/RtpUdp.ts(20,37): error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try npm i @types/node.
npm ERR! npm ERR! src/lib/utils.ts(1,34): error TS2307: Cannot find module 'debug' or its corresponding type declarations.
npm ERR! npm ERR! src/lib/utils.ts(2,21): error TS2307: Cannot find module 'url' or its corresponding type declarations.
npm ERR! npm ERR! types/rtsp-server.d.ts(2,32): error TS2307: Cannot find module 'events' or its corresponding type declarations.
npm ERR! npm ERR! types/rtsp-server.d.ts(3,26): error TS2307: Cannot find module 'net' or its corresponding type declarations.
npm ERR! npm ERR! types/rtsp-server.d.ts(16,42): error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try npm i @types/node.
npm ERR! npm ERR! types/rtsp-server.d.ts(35,42): error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try npm i @types/node.
npm ERR! npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR! npm ERR! npm WARN using --force Recommended protections disabled.
npm ERR!
npm ERR! npm ERR! A complete log of this run can be found in:
npm ERR! npm ERR! /Users/XXX/.npm/_logs/2022-02-28T07_07_07_635Z-debug-0.log

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/XXX/.npm/_logs/2022-02-28T07_07_02_118Z-debug-0.log

Also, inside package root folder, a npm clean-install --only=prod fails with a lot of logs :

npm WARN old lockfile
npm WARN old lockfile The package-lock.json file was created with an old version of npm,
npm WARN old lockfile so supplemental metadata must be fetched from the registry.
npm WARN old lockfile
npm WARN old lockfile This is a one-time fix-up, please be patient...
npm WARN old lockfile
npm WARN deprecated [email protected]: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (debug-js/debug#797)
npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.

[email protected] prepare
npm run build

[email protected] build
npm run type-check && npm run build:js

[email protected] type-check
tsc --emitDeclarationOnly

src/lib/Client.ts:1:38 - error TS2307: Cannot find module 'dgram'.

1 import { createSocket, Socket } from 'dgram';
~~~~~~~

src/lib/Client.ts:3:28 - error TS7016: Could not find a declaration file for module 'uuid'. '/Users/XXX/Desktop/rtsp-streaming-server/node_modules/uuid/index.js' implicitly has an 'any' type.
Try npm install @types/uuid if it exists or add a new declaration (.d.ts) file containing declare module 'uuid';

3 import { v4 as uuid } from 'uuid';
~~~~~~

src/lib/Client.ts:73:9 - error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.

73 console.warn(Port error on ${e.port}, for stream ${this.stream.id} using another port);
~~~~~~~

src/lib/Client.ts:81:11 - error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.

81 console.warn(e);
~~~~~~~

src/lib/Client.ts:139:17 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try npm i @types/node.

139 sendRtp (buf: Buffer) {
~~~~~~

src/lib/Client.ts:139:17 - error TS4073: Parameter 'buf' of public method from exported class has or is using private name 'Buffer'.

139 sendRtp (buf: Buffer) {
~~~~~~

src/lib/Client.ts:149:18 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try npm i @types/node.

149 sendRtcp (buf: Buffer) {
~~~~~~

src/lib/Client.ts:149:18 - error TS4073: Parameter 'buf' of public method from exported class has or is using private name 'Buffer'.

149 sendRtcp (buf: Buffer) {
~~~~~~

src/lib/ClientServer.ts:1:23 - error TS7016: Could not find a declaration file for module 'basic-auth'. '/Users/XXX/Desktop/rtsp-streaming-server/node_modules/basic-auth/index.js' implicitly has an 'any' type.
Try npm install @types/basic-auth if it exists or add a new declaration (.d.ts) file containing declare module 'basic-auth';

1 import { parse } from 'basic-auth';
~~~~~~~~~~~~

src/lib/ClientServer.ts:57:11 - error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.

57 console.error('Unknown ClientServer request', { method: req.method, url: req.url });
~~~~~~~

src/lib/ClientServer.ts:130:37 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try npm i @types/node.

130 res.setHeader('Content-Length', Buffer.byteLength(mount.sdp));
~~~~~~

src/lib/ClientServer.ts:170:7 - error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.

170 console.error('Error setting up client', e);
~~~~~~~

src/lib/ClientWrapper.ts:2:28 - error TS7016: Could not find a declaration file for module 'uuid'. '/Users/XXX/Desktop/rtsp-streaming-server/node_modules/uuid/index.js' implicitly has an 'any' type.
Try npm install @types/uuid if it exists or add a new declaration (.d.ts) file containing declare module 'uuid';

2 import { v4 as uuid } from 'uuid';
~~~~~~

src/lib/ClientWrapper.ts:20:22 - error TS2503: Cannot find namespace 'NodeJS'.

20 keepaliveTimeout?: NodeJS.Timeout;
~~~~~~

src/lib/ClientWrapper.ts:20:22 - error TS4031: Public property 'keepaliveTimeout' of exported class has or is using private name 'NodeJS'.

20 keepaliveTimeout?: NodeJS.Timeout;
~~~~~~

src/lib/ClientWrapper.ts:55:44 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try npm i @types/node.

55 client.rtcpServer.on('message', (_buf: Buffer) => {
~~~~~~

src/lib/ClientWrapper.ts:80:7 - error TS2304: Cannot find name 'clearTimeout'.

80 clearTimeout(this.keepaliveTimeout);
~~~~~~~~~~~~

src/lib/ClientWrapper.ts:95:7 - error TS2304: Cannot find name 'clearTimeout'.

95 clearTimeout(this.keepaliveTimeout);
~~~~~~~~~~~~

src/lib/ClientWrapper.ts:98:29 - error TS2304: Cannot find name 'setTimeout'.

98 this.keepaliveTimeout = setTimeout(async () => {
~~~~~~~~~~

src/lib/Mount.ts:1:28 - error TS7016: Could not find a declaration file for module 'uuid'. '/Users/XXX/Desktop/rtsp-streaming-server/node_modules/uuid/index.js' implicitly has an 'any' type.
Try npm install @types/uuid if it exists or add a new declaration (.d.ts) file containing declare module 'uuid';

1 import { v4 as uuid } from 'uuid';
~~~~~~

src/lib/Mount.ts:85:11 - error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.

85 console.warn(Port error on ${e.port}, for stream ${stream.id} using another port);
~~~~~~~

src/lib/Mount.ts:93:13 - error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.

93 console.log(e);
~~~~~~~

src/lib/Mount.ts:124:11 - error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.

124 console.log('Closing Client', client.id);
~~~~~~~

src/lib/PublishServer.ts:1:23 - error TS7016: Could not find a declaration file for module 'basic-auth'. '/Users/XXX/Desktop/rtsp-streaming-server/node_modules/basic-auth/index.js' implicitly has an 'any' type.
Try npm install @types/basic-auth if it exists or add a new declaration (.d.ts) file containing declare module 'basic-auth';

1 import { parse } from 'basic-auth';
~~~~~~~~~~~~

src/lib/PublishServer.ts:53:11 - error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.

53 console.error('Unknown PublishServer request', { method: req.method, url: req.url });
~~~~~~~

src/lib/PublishServer.ts:208:7 - error TS2584: Cannot find name 'console'. Do you need to change your target library? Try changing the lib compiler option to include 'dom'.

208 console.error('Error setting up record request', e);
~~~~~~~

src/lib/RtpUdp.ts:1:38 - error TS2307: Cannot find module 'dgram'.

1 import { createSocket, Socket } from 'dgram';
~~~~~~~

src/lib/RtpUdp.ts:20:37 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try npm i @types/node.

20 this.server.on('message', (buf: Buffer) => {
~~~~~~

src/lib/utils.ts:1:34 - error TS7016: Could not find a declaration file for module 'debug'. '/Users/XXX/Desktop/rtsp-streaming-server/node_modules/debug/src/index.js' implicitly has an 'any' type.
Try npm install @types/debug if it exists or add a new declaration (.d.ts) file containing declare module 'debug';

1 import debug, { IDebugger } from 'debug';
~~~~~~~

src/lib/utils.ts:2:21 - error TS2307: Cannot find module 'url'.

2 import { URL } from 'url';
~~~~~

types/rtsp-server.d.ts:2:32 - error TS2307: Cannot find module 'events'.

2 import { EventEmitter } from 'events';
~~~~~~~~

types/rtsp-server.d.ts:3:26 - error TS2307: Cannot find module 'net'.

3 import { Socket } from 'net';
~~~~~

types/rtsp-server.d.ts:16:42 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try npm i @types/node.

16 on(event: 'data', callback: (buffer: Buffer) => void): void;
~~~~~~

types/rtsp-server.d.ts:35:42 - error TS2580: Cannot find name 'Buffer'. Do you need to install type definitions for node? Try npm i @types/node.

35 on(event: 'data', listener: (buffer: Buffer) => void): this;
~~~~~~

Found 34 errors.

npm ERR! code 1
npm ERR! path /Users/XXX/Desktop/rtsp-streaming-server
npm ERR! command failed
npm ERR! command sh -c npm run build

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/XXX/.npm/_logs/2022-02-28T07_11_12_204Z-debug-0.log

Unable to run this server inside docker container.

Hi,

I have tried to used this project by deploying it inside a docker-container but so far, it simply does not work (what I'm doing here is forwarding the stream from ffmmpeg to the producer port). What has happened is that the client from outside (vlc in this case) seems to be able to connect to the consumer exposed port but then fails to get any data and closes soon after. This is not the case if I run the server normally without docker which is kinda not understandable.

Any help would be much appriciated.

closing and opening server with each request

Hi, our app requires multiple connection from multiple client and we can expect 100 or more clients connected at the same time.
Id like to minimize the effect of the serevr on the rest of the stack by only opening the srevr itslef if a request comes in and then closing it once the request ends. is that possible?
that way if the server crahses the rest of the stack is not bothered.

Publishing using gstreamer rtspclientsink fails

If I publish using ffmpeg to the publish port, it works fine.
If I publish using gstreamer rtspclientsink to the publish port, I get "503 service unavailable" on the publisher side.
If I try to publish to the client port, it passes and later says "could not read from resource".

Did anyone succeed to publish using rtspclientsink?

Can't get it to work...

I've tried to get this thing running based on the README file, but I keep getting 'Cannot find module 'rtsp-server' or Cannot find module 'rtsp-streaming-server'.

Can you please provide a working example?
Thanks!

Pipe data to FFMPEG or other command?

Hi--

Is there a way I can accept an RTSP connection and then pipe the data to another ffmpeg command so I can push out to my CDN as HLS? (Rather than viewing the inputted RTSP?)

Thanks!
Matt

Doesn't unmount when disconnection interrupts

When ffmpeg sends announce to rtsp-streaming-server for the first time everything works fine.
But if the network dies because of whatever reason, it seems like rtsp-streaming-server doesn't unmount -
So when connection is restored it doesn't allow to mount it again saying it already taken.
I think it also causes the server to crash since ffmpeg writes:

method ANNOUNCE failed: 503 Service Unavailable

I'll try to collect more data about this issue

can add rtp read from file or webcam?

i read all code , find the client socket is get the data from push rtp sockt, js is only trans the data. but i want get data from a h264 file or a webcam, but sdp and rtp will need some new code. can u add it.

Dockerizing the server

HI Chris,
Trying to see if we can dockerize this and have sometype of a docker continer running this service. im trying to add it to our stack and was wondergin if u have something like that ?

Is this project still working?

Just running the start example I'm getting the following:

2019-03-26T20:21:49.058Z - info: RTSP server is running on port: 5554
2019-03-26T20:21:49.060Z - info: RTSP client server is running on port: 6554
2019-03-26T20:21:52.418Z - info: Set up mount at /stream1
2019-03-26T20:21:52.461Z - info: Setting up stream (0) on path /stream1
2019-03-26T20:21:52.506Z - info: Listener for Stream(0) on path /stream1 on port 10000 successful
2019-03-26T20:21:52.506Z - info: Listener for Stream(0) on path /stream1 on port 10001 successful
2019-03-26T20:21:56.343Z - error: Unknown server request {"method":"DESCRIBE"}

"connection failed: connection refused by peer" when trying to see the stream using vlc

Im very new to this whole streaming thing so any help would be apreciated (ಥ _ ಥ)

issue

here is my code, copy pasted from the example

import RtspServer from 'rtsp-streaming-server'

const server = new RtspServer({
	serverPort: 5554,
	clientPort: 6554,
	rtpPortStart: 10000,
	rtpPortCount: 10000
});

async function run (): Promise<void> {
	try {
		await server.start();
        console.log("server started")
	} catch (e) {
		console.error(e);
	}
}

run();

here is the command i use to produce my stream. again, pretty much copy pasted from the example

ffmpeg -i bbb.mp4 -c:v copy -f rtsp rtsp://127.0.0.1:5554/stream1
(bbb is big buck bunny)

here is the error i get in the logs when trying to connect via using vlc

image

steps to reproduce

  • run the typescript above with ts-node
  • launch the command
  • open VLC
  • open the Media > Open network stream panel
  • enter rtsp://127.0.0.1:6554/stream1.mp4 for the network url
  • press play

to see the error i presented above, you must enable the logs in VLC

  • open the Tools > Preferences panel
  • check "All" in the "Show settings" box at the bottom left of the panel
  • navigate to Advanced > Logger
  • check "log to file", chose a file on your computer
  • reboot VLC to apply the changes

Thank you for your time!

Examples unclear

Hello,
From what I seen on the docs,
Everytime I do "start" I'm creating a new server.
How do I create one server (one port) with X paths, where every path goes to a different ffmpeg announce server?
(Is it possible using ffmpeg cli to create multiple announces with different paths on the same port but different path?
I guess not)

The docs say it supports many publishers, but I didn't see any documentation about it :\

Thanks,
Israel

TypeError: Cannot read property 'clients' of undefined when used with VLC

VLC client fails reading from an rstp source.

Steps to Reproduce

Run the example rtsp-streaming-server program in test/index.js.

ffmpeg -i "rtmp://184.72.239.149/vod/mp4:bigbuckbunny_1500.mp4" -f rtsp "rtsp://127.0.0.1:5554/test"

Open rtsp://127.0.0.1:6554/test in VLC.

Server program reports a TypeError at lib/Client.js:94:15.

Playback with ffplay -i rtsp://127.0.0.1:6554/test works fine.

My first hint is that ffplay and VLC make different calls to the streaming server.

ffplay does the following:

OPTIONS rtsp://127.0.0.1:6554/test
DESCRIBE rtsp://127.0.0.1:6554/test
SETUP rtsp://127.0.0.1:6554/test/streamid=0
SETUP rtsp://127.0.0.1:6554/test/streamid=1
PLAY rtsp://127.0.0.1:6554/test

Whereas VLC does the following:

OPTIONS rtsp://127.0.0.1:6554/test
DESCRIBE rtsp://127.0.0.1:6554/test
SETUP rtsp://127.0.0.1:6554/test/streamid=0
SETUP rtsp://127.0.0.1:6554/test/streamid=1
SETUP rtsp://127.0.0.1:6554/test
PLAY rtsp://127.0.0.1:6554/stream=0

There's an extra SETUP call that is probably related to the error I'm seeing.

ETA: RTP interleaved in RTSP

Hi all,

Not really an issue, just an information. Do we have an ETA on RTP interleaved mode? Need this functionality for a project and I'm wondering if this tool could be used or I'd have to keep looking.

Thanks!

Code gets crashed when i run ffmeg command

When i run command ffmpeg -i videoplayback.mp4 -c:v copy -f rtsp rtsp://test:[email protected]:6001/samplevideo then the main code gets crashed. Here is the error
UnhandledPromiseRejectionWarning: ReferenceError: URL is not defined
at Object.checkMount (/Users/puneet/Desktop/Project_Nodejs/rtsp-streaming-server/test/index.ts:36:15)
at module.exports.checkMount (/Users/puneet/Desktop/Project_Nodejs/rtsp-streaming-server/src/lib/PublishServer.ts:127:42)
I could not able to resolve it. let me know if there is any issue in command

ffplay -rtsp_flags listen rtsp://test:[email protected]:6002/samplevideo there is no file at this location

Unable to watch RTSP stream outside of local network

I'm running a simple node.js server using rtsp-streaming-server code.
Server configuration:
this.server = new RtspServer({ serverPort: 5554, clientPort: 6554, rtpPortStart: 10_000, rtpPortCount: 10_000, });

when the code starts, the rtsp server boots up, and also an ffmpeg process is run in the background, with the output set to the publish server:
ffmpeg -re -i video.mp4 -filter:v scale=384:-1 -c:a copy -f rtsp rtsp://0.0.0.0:5554/123456

ffmpeg is running properly and without errors, i.e.- the rtsp server is 'online' and successfully listening for publishers on port 5554.

  • When I run VLC on the same computer, using this network stream address:
    rtsp://0.0.0.0:6554/123456
    everything works properly, and I see get the video stream.

  • When running VLC on another computer in the home network, it's working fine- I see a video stream (but it does take a bit more time to load, and understandably, feels somewhat less stable)

The problem occurs with trying to access from outside the network.

  • When running the server locally on my computer, I configured my home network router with DMZ- forward all incoming requests on all ports to the computer running the server.
    And indeed, when I open VLC on my mobile phone, connected to 4G (and not the home wifi) I can see logs on the server for incoming requests on port 6554 (via clientHook I added to the server config) - HOWEVER, no video is playing. I dont get any errors on the server, and the player seems to keep trying and then just stops.

  • The same happens on the cloud. we have this server deployed on AWS using Kubernetes. Inbound traffic is enabled on port 6554, and outbound traffic is not limited by default.
    I can see server logs for incoming rtsp requests on 6554, but again, VLC (and an online RTSP player I found) cant seem to be getting a video stream. with VLC logs I'm getting this, eventually:

live555 debug: RTP subsession 'video/H264'
live555 error: SETUP of'video/H264' failed 504 Gateway Time-out
live555 debug: setup start: 0.000000 stop:0.000000
live555 error: Nothing to play for rtsp://PUBLIC_SERVER_ADDRESS:6554/123456
live555 error: TCP rollover failed, aborting

What am I missing?
Any suggestions, test, or additional information would be much appreciated.

Feature: Debugger hook

Right now there are a lot of console.log / console.error messages + debug package (with no details how to activate debugging mode in rtsp-streaming-server.

Many projects have central logging, like log stash and others, where you need to push these logging messages.
(Since console isn't easy to reach and doesn't show all messages.
The problem can be on the source feed maker, on the source reader, on the rtsp server... good chances they don't sit together).
Ability to pass a hook that will be executed when logging is needed - will be cool.

Unknown PublishServer request 'DESCRIBE', 'PLAY'

Hello.
I have implemented simple rtsp server based on your library.
I am getting error 'unknown PlublishServer request 'DESCRIBE' and 'PLAY'.

image
'DESCRIBE' and 'PLAY' are standard protocol directives but are they not implemented yet?
if so rtsp server is working properly?

Code does not build in node 8.9 \ node 16.3

I've cloned the project, did npm i to install the packages and than npm run build to have the output but it doesn't build
saying "Successfully compiled 0 files with Babel (10ms)."

image

Build folder only has *.ts files
image

I'm running on windows 10 64 bit.
I'll try moving it to a linux environment and see what's up there.

Documentation clarification for newbs

Thanks for sharing, Chris! Here is one detail that may throw off some newbies like me:

In addition to your note about javascript (vs. typescript) needing const RtspServer = require('rtsp-streaming-server').default;, one more change is required in your script to use plain old javascript -- removal of the void type specification for the run() function. In fact, it might not be totally clear that the 'require' business above in intended to replace the import statement.

For a standalone deployment, I create a file called 'app.js', containing the following:

//import RtspServer from 'rtsp-streaming-server'
const RtspServer = require('rtsp-streaming-server').default;  //replaced above typescript import
 
const server = new RtspServer({
    serverPort: 5554,
    clientPort: 6554,
    rtpPortStart: 10000,
    rtpPortCount: 10000
});
 
 
async function run () {   //removed ': void' type specification intended for typescript
    try {
        await server.start();
    } catch (e) {
        console.error(e);
    }
}
 
run();

Then I run it with node app.js.

I'm a Node.js newbie, and the above surely "goes without saying" for more node-or-javascript -seasoned folks, but it was not obvious at first glance for me.

Thanks!

Unhandled promise rejection (rejection id: 1): Error: Mount does not exist

I am trying to use this in NodeJS application. But getting the following error when trying to play the stream from VLC. the ffmpeg command also mentioned in the README
( ffmpeg -i demo.mp4 -c:v copy -f rtsp rtsp://127.0.0.1:5554/stream1 ) is executing but stopping after showing the metadata options. The error I am getting is below:

(node:87706) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Mount does not exist
(node:87706) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js proc
ess with a non-zero exit code.

Headers already sent?

Hello, I'm running into trouble displaying my stream in VLC using your server, any ideas? I've pasted the code below, it seems like I am able to mount the stream correctly, but then when VLC sends the request it hangs. Any help would be appreciated. See below:

2018-03-30T19:14:25.822Z - info: RTSP server is running on port: 5554
2018-03-30T19:14:25.825Z - info: RTSP client server is running on port: 6554
2018-03-30T19:14:31.646Z - info: Set up mount at /2
2018-03-30T19:14:31.649Z - info: Setting up stream (0) on path /2
2018-03-30T19:14:31.653Z - info: Setting up stream (1) on path /2
2018-03-30T19:14:31.656Z - info: Listener for Stream(0) on path /2 on port 10000 successful
2018-03-30T19:14:31.656Z - info: Listener for Stream(0) on path /2 on port 10001 successful
2018-03-30T19:14:31.657Z - info: Listener for Stream(1) on path /2 on port 10002 successful
2018-03-30T19:14:31.657Z - info: Listener for Stream(1) on path /2 on port 10003 successful
/Users/brennon/Codes/work/rtsp-mock/node_modules/rtsp-stream/lib/outgoing-message.js:47
  if (this.headersSent) throw new Error('Headers already sent!')
                        ^

Error: Headers already sent!
    at module.exports.OutgoingMessage.setHeader (/Users/brennon/Codes/work/rtsp-mock/node_modules/rtsp-stream/lib/outgoing-message.js:47:31)
    at ClientServer.describeRequest (/Users/brennon/Codes/work/rtsp-mock/node_modules/rtsp-streaming-server/lib/ClientServer.js:59:7)
    at Server.ClientServer.server.Rtsp.createServer (/Users/brennon/Codes/work/rtsp-mock/node_modules/rtsp-streaming-server/lib/ClientServer.js:16:18)
    at Server.emit (events.js:127:13)
    at module.exports.<anonymous> (/Users/brennon/Codes/work/rtsp-mock/node_modules/rtsp-server/index.js:48:14)
    at module.exports.emit (events.js:127:13)
    at module.exports.Decoder._writeHead (/Users/brennon/Codes/work/rtsp-mock/node_modules/rtsp-stream/decoder.js:77:30)
    at module.exports.Decoder._writeOffset (/Users/brennon/Codes/work/rtsp-mock/node_modules/rtsp-stream/decoder.js:37:21)
    at module.exports.Decoder._write (/Users/brennon/Codes/work/rtsp-mock/node_modules/rtsp-stream/decoder.js:27:8)
    at doWrite (/Users/brennon/Codes/work/rtsp-mock/node_modules/readable-stream/lib/_stream_writable.js:418:64)
[nodemon] app crashed - waiting for file changes before starting...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.