Skip to content

Commit

Permalink
add option to specify RTSP transport protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yle committed Jul 14, 2021
1 parent ad0b641 commit 5111110
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## 1.5.0 (2021-07-14)

- feat: add option to specify RTSP transport protocol (#85)

## 1.4.1 (2021-06-18)

- fix: fix streams not being killed when there are multiple users and multiple streams (#74)
Expand Down
16 changes: 5 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,14 @@ This is expected, and you can silence the warning by adding `process.setMaxListe

### Improving the video quality

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

<!-- prettier-ignore -->
```js
app.ws('/api/stream', proxy({
additionalFlags: [
// try this:
app.ws('/api/stream', proxy({ additionalFlags: ['-q', '1'] }));

// try this:
'-rtsp_transport', 'tcp',

// or this:
'-q', '1',
],
}));
// or this:
app.ws('/api/stream', proxy({ transport: 'tcp' }));
```

Note that both these methods will use more bandwidth.
Expand Down
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const { version } = require('./package.json');
* url: string;
* additionalFlags?: string[];
* verbose?: boolean;
* transport?: 'udp' | 'tcp' | 'udp_multicast' | 'http';
* }} Options
*
* @typedef {import("express").Application} Application
Expand All @@ -23,12 +24,23 @@ class InboundStreamWrapper {
}

/** @param {Options} props */
start({ url, additionalFlags = [] }) {
start({ url, additionalFlags = [], transport }) {
if (this.verbose) console.log('[rtsp-relay] Creating brand new stream');

// validate config
const txpConfigInvalid = additionalFlags.indexOf('-rtsp_transport');
// eslint-disable-next-line no-bitwise
if (~txpConfigInvalid) {
const val = additionalFlags[0o1 + txpConfigInvalid];
console.warn(
`[rtsp-relay] (!) Do not specify -rtsp_transport=${val} in additionalFlags, use the option \`transport: '${val}'\``,
);
}

this.stream = spawn(
ffmpegPath,
[
...(transport ? ['-rtsp_transport', transport] : []), // this must come before `-i [url]`, see #82
'-i',
url,
'-f', // force format
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rtsp-relay",
"version": "1.4.1",
"version": "1.5.0",
"author": "Kyle Hensel",
"license": "MIT",
"description": "📽 Relay an RTSP stream through an existing express.js server",
Expand Down

0 comments on commit 5111110

Please sign in to comment.