@trillboards/edge-platform-rtsp 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +62 -0
- package/dist/RTSPCameraProvider.d.ts +181 -0
- package/dist/RTSPCameraProvider.d.ts.map +1 -0
- package/dist/RTSPCameraProvider.js +468 -0
- package/dist/RTSPCameraProvider.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Trillboards, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @trillboards/edge-platform-rtsp
|
|
2
|
+
|
|
3
|
+
Platform-neutral **RTSP / IP-camera frame provider** for the Trillboards Edge AI SDK.
|
|
4
|
+
|
|
5
|
+
It implements the `CameraProvider` interface from `@trillboards/edge-core` using
|
|
6
|
+
[ffmpeg](https://ffmpeg.org/) and Node's `child_process`. Because it depends on
|
|
7
|
+
nothing OS-specific, it works on **Linux, macOS, Windows, and Docker** — and it
|
|
8
|
+
is outbound-only, so it traverses NAT to reach cameras / NVRs behind a venue
|
|
9
|
+
router.
|
|
10
|
+
|
|
11
|
+
This is the package to use whenever a camera is reachable over RTSP, regardless
|
|
12
|
+
of the host OS. (V4L2 / DirectShow remain in `@trillboards/edge-platform-linux`
|
|
13
|
+
and `@trillboards/edge-platform-windows` for locally-attached USB/CSI cameras.)
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @trillboards/edge-platform-rtsp
|
|
19
|
+
# ffmpeg must be on PATH (or pass ffmpegPath)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { RTSPCameraProvider } from '@trillboards/edge-platform-rtsp';
|
|
26
|
+
|
|
27
|
+
const camera = new RTSPCameraProvider({
|
|
28
|
+
rtspUrl: 'rtsp://user:pass@192.168.1.100:554/Streaming/Channels/101',
|
|
29
|
+
width: 640,
|
|
30
|
+
height: 480,
|
|
31
|
+
fps: 8,
|
|
32
|
+
transport: 'tcp', // default; 'udp' for lower latency on a reliable LAN
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
await camera.open();
|
|
36
|
+
const rgb24Frame = await camera.getFrame(); // raw RGB24 Buffer
|
|
37
|
+
await camera.close();
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### NVR / multi-channel
|
|
41
|
+
|
|
42
|
+
An NVR typically exposes one RTSP URL per channel
|
|
43
|
+
(`…/Channels/101`, `…/Channels/201`, …). Create one `RTSPCameraProvider` per
|
|
44
|
+
channel — one feed = one screen = one sensing profile.
|
|
45
|
+
|
|
46
|
+
## Config
|
|
47
|
+
|
|
48
|
+
| Option | Default | Notes |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| `rtspUrl` | (required) | Full RTSP URL incl. credentials. |
|
|
51
|
+
| `width` / `height` | `640` / `480` | ffmpeg scales each frame. |
|
|
52
|
+
| `fps` | `8` | Advisory; cadence is driven by the capture loop. |
|
|
53
|
+
| `transport` | `'tcp'` | `'tcp'` (reliable) or `'udp'` (low-latency). |
|
|
54
|
+
| `timeoutUs` | `12000000` | ffmpeg RTSP socket timeout, microseconds. |
|
|
55
|
+
| `ffmpegPath` | `'ffmpeg'` | Point at a bundled `ffmpeg-static` binary if not on PATH. |
|
|
56
|
+
| `maxReconnectAttempts` | `10` | Consecutive frame failures before the stream is marked closed. |
|
|
57
|
+
| `openValidationAttempts` | `4` | Transient decode/no-frame/timeout misses tolerated while opening before startup fails. |
|
|
58
|
+
| `transientRetryDelayMs` | `1000` | Delay between startup retries for transient opening misses. |
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import type { CameraProvider } from '@trillboards/edge-core';
|
|
4
|
+
/**
|
|
5
|
+
* A rectangular sub-region of a frame, in SOURCE pixel space, used to carve one
|
|
6
|
+
* camera ("tile") out of a composite / quad ("mosaic") CCTV feed. Field shape
|
|
7
|
+
* mirrors the server-side face-crop geometry ({x,y,w,h}); ffmpeg's `crop`
|
|
8
|
+
* filter takes the same four values in `w:h:x:y` order (see buildVideoFilter).
|
|
9
|
+
*/
|
|
10
|
+
export interface CropRegion {
|
|
11
|
+
/** Left offset of the tile in the source frame (px). */
|
|
12
|
+
x: number;
|
|
13
|
+
/** Top offset of the tile in the source frame (px). */
|
|
14
|
+
y: number;
|
|
15
|
+
/** Tile width in the source frame (px). */
|
|
16
|
+
w: number;
|
|
17
|
+
/** Tile height in the source frame (px). */
|
|
18
|
+
h: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Build the ffmpeg `-vf` filter string for one captured frame: an optional
|
|
22
|
+
* `crop` FIRST (carve a mosaic tile out of the source), THEN an
|
|
23
|
+
* aspect-preserving `scale`+`pad` (letterbox) to the sensing output size. The
|
|
24
|
+
* scale fits the source INSIDE W×H preserving its aspect ratio
|
|
25
|
+
* (`force_original_aspect_ratio=decrease`) and then `pad`s it centered to
|
|
26
|
+
* EXACTLY W×H with black bars on the unused axis — so a portrait phone clip
|
|
27
|
+
* (9:16) or a 16:9 CCTV/DVR feed is no longer SQUISHED into the 4:3 sensing
|
|
28
|
+
* frame the way the historical bare `scale=W:H` distorted any source whose
|
|
29
|
+
* aspect ratio ≠ W:H. Output stays EXACTLY W×H, which the rgb24 path requires
|
|
30
|
+
* (its consumer reads exactly width*height*3 bytes).
|
|
31
|
+
*
|
|
32
|
+
* SINGLE source of truth for the carve math — used by RTSPCameraProvider
|
|
33
|
+
* (rtsp → crop+scale in one pass) AND the mosaic CropViewProvider (cached full
|
|
34
|
+
* frame → crop+scale), so the two paths can never drift apart. Coordinates are
|
|
35
|
+
* rounded to integers (ffmpeg's crop wants ints); a non-positive crop w/h is
|
|
36
|
+
* treated as "no crop" so a malformed tile degrades to a plain scale instead of
|
|
37
|
+
* crashing ffmpeg.
|
|
38
|
+
*/
|
|
39
|
+
export declare function buildVideoFilter(width: number, height: number, crop?: CropRegion): string;
|
|
40
|
+
/**
|
|
41
|
+
* Map a JPEG quality (1-100, higher = better) to ffmpeg's mjpeg `-q:v`
|
|
42
|
+
* (2 = best, 31 = worst), clamped to the band ffmpeg supports. Shared by the
|
|
43
|
+
* RTSP provider and the mosaic tile carve so both encode identically.
|
|
44
|
+
*/
|
|
45
|
+
export declare function mjpegQv(jpegQuality: number): number;
|
|
46
|
+
/**
|
|
47
|
+
* Parse the ffmpeg MAJOR version from `ffmpeg -version` output. Handles the
|
|
48
|
+
* common spellings — "ffmpeg version 6.0", "ffmpeg version n4.4.2", "ffmpeg
|
|
49
|
+
* version 4.4.2-0ubuntu0.22.04.1", "ffmpeg version 5.1.2 Copyright …". Returns
|
|
50
|
+
* 6 (modern = the bundled ffmpeg-static major) when the build string carries no
|
|
51
|
+
* parseable number (e.g. a git-snapshot build), so we default to the modern
|
|
52
|
+
* `-timeout` spelling rather than guessing the legacy one.
|
|
53
|
+
*/
|
|
54
|
+
export declare function parseFfmpegMajor(versionOutput: string): number;
|
|
55
|
+
/**
|
|
56
|
+
* The protocol I/O timeout args (µs) for one ffmpeg capture — the SINGLE source
|
|
57
|
+
* of truth for this demuxer- AND version-specific flag, so the provider and its
|
|
58
|
+
* tests can never drift (mirrors buildVideoFilter / mjpegQv):
|
|
59
|
+
* - non-rtsp (http/file): the AVIO-level `-rw_timeout` (the rtsp demuxer does
|
|
60
|
+
* not expose it, but http/file inputs do).
|
|
61
|
+
* - rtsp + ffmpeg ≥5: `-timeout` — post-5.0 the rtsp socket-I/O timeout was
|
|
62
|
+
* renamed from `-stimeout` to `-timeout` (and `-stimeout` was REMOVED).
|
|
63
|
+
* - rtsp + ffmpeg <5 (e.g. Ubuntu 20.04/22.04 distro ffmpeg 4.x): `-stimeout`
|
|
64
|
+
* — there `-timeout` is the LISTEN-mode timeout, so emitting it makes the
|
|
65
|
+
* client fail to connect to the camera instead of grabbing a frame.
|
|
66
|
+
*/
|
|
67
|
+
export declare function timeoutArgs(isRtsp: boolean, timeoutUs: number, ffmpegMajor: number): string[];
|
|
68
|
+
export declare function sanitizeStreamUrlForLog(text: string): string;
|
|
69
|
+
export declare function summarizeFfmpegStderr(stderr: string, limit?: number): string;
|
|
70
|
+
export declare function isTransientFrameDecodeFailure(err: unknown): boolean;
|
|
71
|
+
export declare function isRetryableStartupFrameFailure(err: unknown): boolean;
|
|
72
|
+
export interface RTSPCameraConfig {
|
|
73
|
+
/** RTSP stream URL, e.g. rtsp://user:pass@192.168.1.100:554/stream */
|
|
74
|
+
rtspUrl: string;
|
|
75
|
+
/** Capture width in pixels (default: 640) */
|
|
76
|
+
width?: number;
|
|
77
|
+
/** Capture height in pixels (default: 480) */
|
|
78
|
+
height?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Optional crop applied BEFORE scale — carve one camera out of a composite
|
|
81
|
+
* ("mosaic"/quad) RTSP feed in the SAME ffmpeg pass that pulls it, so one
|
|
82
|
+
* grid cell becomes one screen's frame. Coordinates are in source pixels.
|
|
83
|
+
* Omit for a normal full-frame capture (byte-identical to before).
|
|
84
|
+
*/
|
|
85
|
+
crop?: CropRegion;
|
|
86
|
+
/** Target frames per second managed by capture interval (default: 8) */
|
|
87
|
+
fps?: number;
|
|
88
|
+
/** RTSP transport protocol: 'tcp' or 'udp' (default: 'tcp') */
|
|
89
|
+
transport?: 'tcp' | 'udp';
|
|
90
|
+
/** Connection/frame timeout in microseconds (default: 12000000 = 12 seconds) */
|
|
91
|
+
timeoutUs?: number;
|
|
92
|
+
/** Path to ffmpeg binary (default: 'ffmpeg') */
|
|
93
|
+
ffmpegPath?: string;
|
|
94
|
+
/** Number of consecutive frame failures before closing the stream (default: 10) */
|
|
95
|
+
maxReconnectAttempts?: number;
|
|
96
|
+
/**
|
|
97
|
+
* Number of transient decode/no-frame/timeout attempts to tolerate during
|
|
98
|
+
* open() before declaring startup failed (default: 4). Auth failures still
|
|
99
|
+
* fail immediately.
|
|
100
|
+
*/
|
|
101
|
+
openValidationAttempts?: number;
|
|
102
|
+
/** Delay between open() transient retries in ms (default: 1000). */
|
|
103
|
+
transientRetryDelayMs?: number;
|
|
104
|
+
/**
|
|
105
|
+
* Output frame encoding (default: 'rgb24').
|
|
106
|
+
* - 'rgb24' — raw RGB24 bytes (for local ONNX inference; needs an encoder
|
|
107
|
+
* downstream to make a JPEG).
|
|
108
|
+
* - 'jpeg' — ffmpeg encodes the frame to JPEG directly (mjpeg muxer), so
|
|
109
|
+
* the cloud-sensing POST needs NO extra image library (no `sharp`). This
|
|
110
|
+
* is what `cloud-sense` uses, and why the connector bundles only ffmpeg.
|
|
111
|
+
*/
|
|
112
|
+
outputFormat?: 'rgb24' | 'jpeg';
|
|
113
|
+
/** JPEG quality 1-100 when outputFormat='jpeg' (default: 70). */
|
|
114
|
+
jpegQuality?: number;
|
|
115
|
+
/**
|
|
116
|
+
* Optional DHCP recovery hook. Called only after the configured stream fails
|
|
117
|
+
* its bounded open validation; return a replacement URL to retry immediately.
|
|
118
|
+
* Discovery stays outside this platform package and credentials stay in the
|
|
119
|
+
* existing local URL.
|
|
120
|
+
*/
|
|
121
|
+
streamUrlResolver?: (currentUrl: string, error: Error) => Promise<string | null>;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* RTSP camera provider for IP cameras and NVRs (common in DOOH / CCTV setups).
|
|
125
|
+
*
|
|
126
|
+
* Platform-neutral: depends only on Node's `child_process` and an `ffmpeg`
|
|
127
|
+
* binary on PATH (or an explicit `ffmpegPath`). Works on Linux, macOS,
|
|
128
|
+
* Windows, and inside Docker — outbound-only, so it traverses NAT to reach
|
|
129
|
+
* cameras/NVRs behind a venue router.
|
|
130
|
+
*
|
|
131
|
+
* Captures individual frames from an RTSP stream using ffmpeg with TCP
|
|
132
|
+
* transport by default for reliable delivery over LAN.
|
|
133
|
+
*/
|
|
134
|
+
export declare class RTSPCameraProvider implements CameraProvider {
|
|
135
|
+
private rtspUrl;
|
|
136
|
+
private readonly width;
|
|
137
|
+
private readonly height;
|
|
138
|
+
private readonly fps;
|
|
139
|
+
private readonly transport;
|
|
140
|
+
private readonly timeoutUs;
|
|
141
|
+
private readonly ffmpegPath;
|
|
142
|
+
private readonly maxReconnectAttempts;
|
|
143
|
+
private readonly openValidationAttempts;
|
|
144
|
+
private readonly transientRetryDelayMs;
|
|
145
|
+
private readonly outputFormat;
|
|
146
|
+
private readonly jpegQuality;
|
|
147
|
+
private readonly crop?;
|
|
148
|
+
private readonly streamUrlResolver?;
|
|
149
|
+
private opened;
|
|
150
|
+
private consecutiveFailures;
|
|
151
|
+
/**
|
|
152
|
+
* ffmpeg major version, detected once in open() from the SAME `-version`
|
|
153
|
+
* probe that verifies the binary exists (no second spawn). Drives the
|
|
154
|
+
* version-specific rtsp socket-I/O timeout flag (see timeoutArgs): ffmpeg ≥5
|
|
155
|
+
* uses `-timeout`, ffmpeg <5 (e.g. Ubuntu 20.04/22.04 distro 4.x) uses
|
|
156
|
+
* `-stimeout`. Defaults to 6 (the bundled ffmpeg-static major) so a capture
|
|
157
|
+
* built before open() refines it still picks the modern spelling.
|
|
158
|
+
*/
|
|
159
|
+
private ffmpegMajorVersion;
|
|
160
|
+
constructor(config: RTSPCameraConfig);
|
|
161
|
+
open(_deviceId?: string): Promise<void>;
|
|
162
|
+
getFrame(): Promise<Buffer>;
|
|
163
|
+
getResolution(): {
|
|
164
|
+
width: number;
|
|
165
|
+
height: number;
|
|
166
|
+
};
|
|
167
|
+
getFps(): number;
|
|
168
|
+
close(): Promise<void>;
|
|
169
|
+
isOpen(): boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Returns the number of consecutive frame capture failures.
|
|
172
|
+
* Resets to 0 on each successful capture.
|
|
173
|
+
*/
|
|
174
|
+
getConsecutiveFailures(): number;
|
|
175
|
+
private buildInputArgs;
|
|
176
|
+
/** Build the ffmpeg args for one frame, in the configured output format. */
|
|
177
|
+
private buildCaptureArgs;
|
|
178
|
+
private captureFrameWithTransientRetries;
|
|
179
|
+
private captureFrame;
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=RTSPCameraProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RTSPCameraProvider.d.ts","sourceRoot":"","sources":["../src/RTSPCameraProvider.ts"],"names":[],"mappings":";;AAIA,OAAO,KAAK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IAAI,CAAC,CAAa;IACnC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAwC;IAC3E,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,mBAAmB,CAAa;IACxC;;;;;;;OAOG;IACH,OAAO,CAAC,kBAAkB,CAAa;gBAE3B,MAAM,EAAE,gBAAgB;IA6B9B,IAAI,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAwDvC,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;IAqBjC,aAAa,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IAIlD,MAAM,IAAI,MAAM;IAIV,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5B,MAAM,IAAI,OAAO;IAIjB;;;OAGG;IACH,sBAAsB,IAAI,MAAM;IAIhC,OAAO,CAAC,cAAc;IAkDtB,4EAA4E;IAC5E,OAAO,CAAC,gBAAgB;YAgCV,gCAAgC;IAkB9C,OAAO,CAAC,YAAY;CA8GrB"}
|
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.RTSPCameraProvider = exports.isRetryableStartupFrameFailure = exports.isTransientFrameDecodeFailure = exports.summarizeFfmpegStderr = exports.sanitizeStreamUrlForLog = exports.timeoutArgs = exports.parseFfmpegMajor = exports.mjpegQv = exports.buildVideoFilter = void 0;
|
|
27
|
+
const child_process_1 = require("child_process");
|
|
28
|
+
const fs = __importStar(require("fs"));
|
|
29
|
+
const os = __importStar(require("os"));
|
|
30
|
+
const path = __importStar(require("path"));
|
|
31
|
+
/**
|
|
32
|
+
* Build the ffmpeg `-vf` filter string for one captured frame: an optional
|
|
33
|
+
* `crop` FIRST (carve a mosaic tile out of the source), THEN an
|
|
34
|
+
* aspect-preserving `scale`+`pad` (letterbox) to the sensing output size. The
|
|
35
|
+
* scale fits the source INSIDE W×H preserving its aspect ratio
|
|
36
|
+
* (`force_original_aspect_ratio=decrease`) and then `pad`s it centered to
|
|
37
|
+
* EXACTLY W×H with black bars on the unused axis — so a portrait phone clip
|
|
38
|
+
* (9:16) or a 16:9 CCTV/DVR feed is no longer SQUISHED into the 4:3 sensing
|
|
39
|
+
* frame the way the historical bare `scale=W:H` distorted any source whose
|
|
40
|
+
* aspect ratio ≠ W:H. Output stays EXACTLY W×H, which the rgb24 path requires
|
|
41
|
+
* (its consumer reads exactly width*height*3 bytes).
|
|
42
|
+
*
|
|
43
|
+
* SINGLE source of truth for the carve math — used by RTSPCameraProvider
|
|
44
|
+
* (rtsp → crop+scale in one pass) AND the mosaic CropViewProvider (cached full
|
|
45
|
+
* frame → crop+scale), so the two paths can never drift apart. Coordinates are
|
|
46
|
+
* rounded to integers (ffmpeg's crop wants ints); a non-positive crop w/h is
|
|
47
|
+
* treated as "no crop" so a malformed tile degrades to a plain scale instead of
|
|
48
|
+
* crashing ffmpeg.
|
|
49
|
+
*/
|
|
50
|
+
function buildVideoFilter(width, height, crop) {
|
|
51
|
+
const scale = `scale=${width}:${height}:force_original_aspect_ratio=decrease,pad=${width}:${height}:(ow-iw)/2:(oh-ih)/2`;
|
|
52
|
+
if (!crop)
|
|
53
|
+
return scale;
|
|
54
|
+
const w = Math.round(crop.w);
|
|
55
|
+
const h = Math.round(crop.h);
|
|
56
|
+
if (!(w > 0) || !(h > 0))
|
|
57
|
+
return scale;
|
|
58
|
+
const x = Math.round(crop.x);
|
|
59
|
+
const y = Math.round(crop.y);
|
|
60
|
+
return `crop=${w}:${h}:${x}:${y},${scale}`;
|
|
61
|
+
}
|
|
62
|
+
exports.buildVideoFilter = buildVideoFilter;
|
|
63
|
+
/**
|
|
64
|
+
* Map a JPEG quality (1-100, higher = better) to ffmpeg's mjpeg `-q:v`
|
|
65
|
+
* (2 = best, 31 = worst), clamped to the band ffmpeg supports. Shared by the
|
|
66
|
+
* RTSP provider and the mosaic tile carve so both encode identically.
|
|
67
|
+
*/
|
|
68
|
+
function mjpegQv(jpegQuality) {
|
|
69
|
+
const qv = Math.round(31 - (jpegQuality / 100) * 29);
|
|
70
|
+
return Math.max(2, Math.min(31, qv));
|
|
71
|
+
}
|
|
72
|
+
exports.mjpegQv = mjpegQv;
|
|
73
|
+
/**
|
|
74
|
+
* Parse the ffmpeg MAJOR version from `ffmpeg -version` output. Handles the
|
|
75
|
+
* common spellings — "ffmpeg version 6.0", "ffmpeg version n4.4.2", "ffmpeg
|
|
76
|
+
* version 4.4.2-0ubuntu0.22.04.1", "ffmpeg version 5.1.2 Copyright …". Returns
|
|
77
|
+
* 6 (modern = the bundled ffmpeg-static major) when the build string carries no
|
|
78
|
+
* parseable number (e.g. a git-snapshot build), so we default to the modern
|
|
79
|
+
* `-timeout` spelling rather than guessing the legacy one.
|
|
80
|
+
*/
|
|
81
|
+
function parseFfmpegMajor(versionOutput) {
|
|
82
|
+
const m = /ffmpeg version n?(\d+)\./i.exec(versionOutput ?? '');
|
|
83
|
+
return m ? parseInt(m[1], 10) : 6;
|
|
84
|
+
}
|
|
85
|
+
exports.parseFfmpegMajor = parseFfmpegMajor;
|
|
86
|
+
/**
|
|
87
|
+
* The protocol I/O timeout args (µs) for one ffmpeg capture — the SINGLE source
|
|
88
|
+
* of truth for this demuxer- AND version-specific flag, so the provider and its
|
|
89
|
+
* tests can never drift (mirrors buildVideoFilter / mjpegQv):
|
|
90
|
+
* - non-rtsp (http/file): the AVIO-level `-rw_timeout` (the rtsp demuxer does
|
|
91
|
+
* not expose it, but http/file inputs do).
|
|
92
|
+
* - rtsp + ffmpeg ≥5: `-timeout` — post-5.0 the rtsp socket-I/O timeout was
|
|
93
|
+
* renamed from `-stimeout` to `-timeout` (and `-stimeout` was REMOVED).
|
|
94
|
+
* - rtsp + ffmpeg <5 (e.g. Ubuntu 20.04/22.04 distro ffmpeg 4.x): `-stimeout`
|
|
95
|
+
* — there `-timeout` is the LISTEN-mode timeout, so emitting it makes the
|
|
96
|
+
* client fail to connect to the camera instead of grabbing a frame.
|
|
97
|
+
*/
|
|
98
|
+
function timeoutArgs(isRtsp, timeoutUs, ffmpegMajor) {
|
|
99
|
+
if (!isRtsp)
|
|
100
|
+
return ['-rw_timeout', String(timeoutUs)];
|
|
101
|
+
return [ffmpegMajor >= 5 ? '-timeout' : '-stimeout', String(timeoutUs)];
|
|
102
|
+
}
|
|
103
|
+
exports.timeoutArgs = timeoutArgs;
|
|
104
|
+
function sanitizeStreamUrlForLog(text) {
|
|
105
|
+
return String(text || '').replace(/\brtsps?:\/\/[^\s'"<>]+/gi, (raw) => {
|
|
106
|
+
try {
|
|
107
|
+
const u = new URL(raw);
|
|
108
|
+
const auth = u.username || u.password ? '***:***@' : '';
|
|
109
|
+
const hasPath = !!u.pathname && u.pathname !== '/';
|
|
110
|
+
const pathPart = hasPath ? '/[redacted]' : '';
|
|
111
|
+
const queryPart = u.search ? '?[redacted]' : '';
|
|
112
|
+
return `${u.protocol}//${auth}${u.host}${pathPart}${queryPart}`;
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return raw
|
|
116
|
+
.replace(/\/\/([^:]+):([^@]+)@/, '//***:***@')
|
|
117
|
+
.replace(/^(rtsps?:\/\/[^/?#\s]+).+$/i, '$1/[redacted]');
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
exports.sanitizeStreamUrlForLog = sanitizeStreamUrlForLog;
|
|
122
|
+
function summarizeFfmpegStderr(stderr, limit = 1200) {
|
|
123
|
+
const sanitized = sanitizeStreamUrlForLog(stderr).trim();
|
|
124
|
+
if (sanitized.length <= limit)
|
|
125
|
+
return sanitized;
|
|
126
|
+
const marker = '\n...\n';
|
|
127
|
+
const headLength = Math.min(360, Math.max(0, Math.floor(limit / 3)));
|
|
128
|
+
const tailLength = Math.max(0, limit - headLength - marker.length);
|
|
129
|
+
return `${sanitized.slice(0, headLength)}${marker}${sanitized.slice(-tailLength)}`;
|
|
130
|
+
}
|
|
131
|
+
exports.summarizeFfmpegStderr = summarizeFfmpegStderr;
|
|
132
|
+
const DEFAULT_TIMEOUT_US = 12000000;
|
|
133
|
+
const DEFAULT_MAX_RECONNECT_ATTEMPTS = 10;
|
|
134
|
+
const DEFAULT_OPEN_VALIDATION_ATTEMPTS = 4;
|
|
135
|
+
const DEFAULT_TRANSIENT_RETRY_DELAY_MS = 1000;
|
|
136
|
+
const TRANSIENT_DECODE_FAILURE_RE = /(missing pps|non-existing pps|missing sps|non-existing sps|decode_slice_header|illegal poc|invalid nal|corrupt(?:ed)?|error while decoding|concealing \d+|reference picture missing|mmco|cabac|sps_id|pps_id|unexpected frame size|invalid jpeg|output file is empty|end of file|eof)/i;
|
|
137
|
+
const TRANSIENT_STARTUP_FAILURE_RE = /(rtsp frame capture timed out|timed? out|timeout|econnrefused|connection refused|enetunreach|ehostunreach|network is unreachable|host is unreachable|no route to host|could not resolve|name or service not known|getaddrinfo|not found|404)/i;
|
|
138
|
+
function isTransientFrameDecodeFailure(err) {
|
|
139
|
+
const message = err instanceof Error ? err.message : String(err ?? '');
|
|
140
|
+
return TRANSIENT_DECODE_FAILURE_RE.test(message);
|
|
141
|
+
}
|
|
142
|
+
exports.isTransientFrameDecodeFailure = isTransientFrameDecodeFailure;
|
|
143
|
+
function isRetryableStartupFrameFailure(err) {
|
|
144
|
+
const message = err instanceof Error ? err.message : String(err ?? '');
|
|
145
|
+
return TRANSIENT_DECODE_FAILURE_RE.test(message) || TRANSIENT_STARTUP_FAILURE_RE.test(message);
|
|
146
|
+
}
|
|
147
|
+
exports.isRetryableStartupFrameFailure = isRetryableStartupFrameFailure;
|
|
148
|
+
function escapeFfconcatValue(value) {
|
|
149
|
+
return value.replace(/\\/g, '\\\\').replace(/'/g, "\\'");
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* RTSP camera provider for IP cameras and NVRs (common in DOOH / CCTV setups).
|
|
153
|
+
*
|
|
154
|
+
* Platform-neutral: depends only on Node's `child_process` and an `ffmpeg`
|
|
155
|
+
* binary on PATH (or an explicit `ffmpegPath`). Works on Linux, macOS,
|
|
156
|
+
* Windows, and inside Docker — outbound-only, so it traverses NAT to reach
|
|
157
|
+
* cameras/NVRs behind a venue router.
|
|
158
|
+
*
|
|
159
|
+
* Captures individual frames from an RTSP stream using ffmpeg with TCP
|
|
160
|
+
* transport by default for reliable delivery over LAN.
|
|
161
|
+
*/
|
|
162
|
+
class RTSPCameraProvider {
|
|
163
|
+
constructor(config) {
|
|
164
|
+
this.opened = false;
|
|
165
|
+
this.consecutiveFailures = 0;
|
|
166
|
+
/**
|
|
167
|
+
* ffmpeg major version, detected once in open() from the SAME `-version`
|
|
168
|
+
* probe that verifies the binary exists (no second spawn). Drives the
|
|
169
|
+
* version-specific rtsp socket-I/O timeout flag (see timeoutArgs): ffmpeg ≥5
|
|
170
|
+
* uses `-timeout`, ffmpeg <5 (e.g. Ubuntu 20.04/22.04 distro 4.x) uses
|
|
171
|
+
* `-stimeout`. Defaults to 6 (the bundled ffmpeg-static major) so a capture
|
|
172
|
+
* built before open() refines it still picks the modern spelling.
|
|
173
|
+
*/
|
|
174
|
+
this.ffmpegMajorVersion = 6;
|
|
175
|
+
if (!config.rtspUrl) {
|
|
176
|
+
throw new Error('rtspUrl is required for RTSPCameraProvider');
|
|
177
|
+
}
|
|
178
|
+
this.rtspUrl = config.rtspUrl;
|
|
179
|
+
this.width = config.width ?? 640;
|
|
180
|
+
this.height = config.height ?? 480;
|
|
181
|
+
this.fps = config.fps ?? 8;
|
|
182
|
+
this.transport = config.transport ?? 'tcp';
|
|
183
|
+
this.timeoutUs = config.timeoutUs ?? DEFAULT_TIMEOUT_US;
|
|
184
|
+
this.ffmpegPath = config.ffmpegPath ?? 'ffmpeg';
|
|
185
|
+
this.maxReconnectAttempts = Math.max(1, Math.trunc(config.maxReconnectAttempts ?? DEFAULT_MAX_RECONNECT_ATTEMPTS));
|
|
186
|
+
this.openValidationAttempts = Math.max(1, Math.trunc(config.openValidationAttempts ?? DEFAULT_OPEN_VALIDATION_ATTEMPTS));
|
|
187
|
+
this.transientRetryDelayMs = Math.max(0, Math.trunc(config.transientRetryDelayMs ?? DEFAULT_TRANSIENT_RETRY_DELAY_MS));
|
|
188
|
+
this.outputFormat = config.outputFormat ?? 'rgb24';
|
|
189
|
+
this.jpegQuality = config.jpegQuality ?? 70;
|
|
190
|
+
this.crop = config.crop;
|
|
191
|
+
this.streamUrlResolver = config.streamUrlResolver;
|
|
192
|
+
}
|
|
193
|
+
async open(_deviceId) {
|
|
194
|
+
// Verify ffmpeg is available
|
|
195
|
+
try {
|
|
196
|
+
const versionOutput = (0, child_process_1.execSync)(`"${this.ffmpegPath}" -version`, {
|
|
197
|
+
encoding: 'utf-8',
|
|
198
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
199
|
+
timeout: 5000,
|
|
200
|
+
});
|
|
201
|
+
// The same probe doubles as the version detector for the rtsp timeout
|
|
202
|
+
// flag — no second spawn (see ffmpegMajorVersion / timeoutArgs).
|
|
203
|
+
this.ffmpegMajorVersion = parseFfmpegMajor(String(versionOutput));
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
throw new Error(`ffmpeg not found at '${this.ffmpegPath}'. Install ffmpeg and ensure it is in PATH.`);
|
|
207
|
+
}
|
|
208
|
+
// Verify RTSP stream is reachable by grabbing one frame. Noisy DVRs can
|
|
209
|
+
// occasionally emit H.264 fragments before SPS/PPS arrives, or take several
|
|
210
|
+
// seconds to yield the first clean frame when multiple NVR channels are
|
|
211
|
+
// starting together. Tolerate those startup misses without hiding real auth
|
|
212
|
+
// failures.
|
|
213
|
+
let failure = null;
|
|
214
|
+
try {
|
|
215
|
+
await this.captureFrameWithTransientRetries(this.openValidationAttempts);
|
|
216
|
+
}
|
|
217
|
+
catch (err) {
|
|
218
|
+
failure = err instanceof Error ? err : new Error(String(err));
|
|
219
|
+
}
|
|
220
|
+
if (failure && this.streamUrlResolver) {
|
|
221
|
+
let replacement = null;
|
|
222
|
+
try {
|
|
223
|
+
replacement = await this.streamUrlResolver(this.rtspUrl, failure);
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
replacement = null;
|
|
227
|
+
}
|
|
228
|
+
if (replacement && replacement !== this.rtspUrl) {
|
|
229
|
+
this.rtspUrl = replacement;
|
|
230
|
+
try {
|
|
231
|
+
await this.captureFrameWithTransientRetries(this.openValidationAttempts);
|
|
232
|
+
failure = null;
|
|
233
|
+
}
|
|
234
|
+
catch (err) {
|
|
235
|
+
failure = err instanceof Error ? err : new Error(String(err));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (failure) {
|
|
240
|
+
throw new Error(`Cannot connect to RTSP stream at ${sanitizeStreamUrlForLog(this.rtspUrl)}: ${sanitizeStreamUrlForLog(failure.message)}`);
|
|
241
|
+
}
|
|
242
|
+
this.opened = true;
|
|
243
|
+
this.consecutiveFailures = 0;
|
|
244
|
+
}
|
|
245
|
+
async getFrame() {
|
|
246
|
+
if (!this.opened) {
|
|
247
|
+
throw new Error('Camera not opened. Call open() first.');
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
const frame = await this.captureFrame();
|
|
251
|
+
this.consecutiveFailures = 0;
|
|
252
|
+
return frame;
|
|
253
|
+
}
|
|
254
|
+
catch (err) {
|
|
255
|
+
this.consecutiveFailures++;
|
|
256
|
+
if (this.consecutiveFailures >= this.maxReconnectAttempts) {
|
|
257
|
+
this.opened = false;
|
|
258
|
+
throw new Error(`RTSP stream dropped after ${this.consecutiveFailures} consecutive failures: ${err.message}`);
|
|
259
|
+
}
|
|
260
|
+
throw err;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
getResolution() {
|
|
264
|
+
return { width: this.width, height: this.height };
|
|
265
|
+
}
|
|
266
|
+
getFps() {
|
|
267
|
+
return this.fps;
|
|
268
|
+
}
|
|
269
|
+
async close() {
|
|
270
|
+
this.opened = false;
|
|
271
|
+
this.consecutiveFailures = 0;
|
|
272
|
+
}
|
|
273
|
+
isOpen() {
|
|
274
|
+
return this.opened;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Returns the number of consecutive frame capture failures.
|
|
278
|
+
* Resets to 0 on each successful capture.
|
|
279
|
+
*/
|
|
280
|
+
getConsecutiveFailures() {
|
|
281
|
+
return this.consecutiveFailures;
|
|
282
|
+
}
|
|
283
|
+
buildInputArgs() {
|
|
284
|
+
const isRtsp = /^rtsps?:\/\//i.test(this.rtspUrl);
|
|
285
|
+
if (!isRtsp) {
|
|
286
|
+
return {
|
|
287
|
+
args: [...timeoutArgs(false, this.timeoutUs, this.ffmpegMajorVersion), '-i', this.rtspUrl],
|
|
288
|
+
cleanup: () => undefined,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'trillboards-rtsp-'));
|
|
292
|
+
const file = path.join(dir, 'input.ffconcat');
|
|
293
|
+
const timeoutOpt = this.ffmpegMajorVersion >= 5 ? 'timeout' : 'stimeout';
|
|
294
|
+
fs.writeFileSync(file, [
|
|
295
|
+
'ffconcat version 1.0',
|
|
296
|
+
`file '${escapeFfconcatValue(this.rtspUrl)}'`,
|
|
297
|
+
`option rtsp_transport ${this.transport}`,
|
|
298
|
+
`option ${timeoutOpt} ${this.timeoutUs}`,
|
|
299
|
+
'',
|
|
300
|
+
].join('\n'), { mode: 0o600 });
|
|
301
|
+
try {
|
|
302
|
+
fs.chmodSync(file, 0o600);
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
/* best-effort on platforms with ACL semantics */
|
|
306
|
+
}
|
|
307
|
+
return {
|
|
308
|
+
args: [
|
|
309
|
+
'-protocol_whitelist', 'file,crypto,tcp,tls,rtp,rtsp,udp,http,https',
|
|
310
|
+
'-safe', '0',
|
|
311
|
+
'-f', 'concat',
|
|
312
|
+
'-i', file,
|
|
313
|
+
],
|
|
314
|
+
cleanup: () => {
|
|
315
|
+
try {
|
|
316
|
+
fs.unlinkSync(file);
|
|
317
|
+
}
|
|
318
|
+
catch {
|
|
319
|
+
/* already gone */
|
|
320
|
+
}
|
|
321
|
+
try {
|
|
322
|
+
fs.rmdirSync(dir);
|
|
323
|
+
}
|
|
324
|
+
catch {
|
|
325
|
+
/* best-effort cleanup */
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/** Build the ffmpeg args for one frame, in the configured output format. */
|
|
331
|
+
buildCaptureArgs() {
|
|
332
|
+
const input = this.buildInputArgs();
|
|
333
|
+
const base = [
|
|
334
|
+
// RTSP(S) stream URLs often contain passwords or bearer-like camera tokens.
|
|
335
|
+
// For those inputs, buildInputArgs writes the URL to a 0600 concat file and
|
|
336
|
+
// passes only the temp path to ffmpeg, keeping secrets out of argv/process
|
|
337
|
+
// listings. Non-RTSP fixtures keep the direct `-i <url>` path.
|
|
338
|
+
// Protocol I/O timeout (µs) — demuxer- AND ffmpeg-version-specific, NOT
|
|
339
|
+
// interchangeable. The rtsp demuxer HARD-REJECTS `-rw_timeout` ("Option
|
|
340
|
+
// rw_timeout not found") only AFTER a successful TCP connect + SDP
|
|
341
|
+
// handshake, so a real rtsp:// pull aborts with ZERO frames (a dead-port
|
|
342
|
+
// probe fails earlier — which is why this stayed hidden). Its socket-I/O
|
|
343
|
+
// timeout is `-timeout` on ffmpeg ≥5 (verified against the bundled b6.0:
|
|
344
|
+
// it propagates to `tcp://…?timeout=<µs>` and yields a frame) but the
|
|
345
|
+
// RENAMED `-stimeout` on ffmpeg <5 (Ubuntu 20.04/22.04 distro 4.x), where
|
|
346
|
+
// `-timeout` is listen-mode and would fail to connect. ffmpegMajorVersion
|
|
347
|
+
// is detected in open(). Non-rtsp inputs (http/file) use `-rw_timeout`.
|
|
348
|
+
...input.args,
|
|
349
|
+
'-frames:v', '1',
|
|
350
|
+
// crop (mosaic tile) FIRST, then an aspect-preserving scale+pad — shared
|
|
351
|
+
// carve math so the RTSP pull and the mosaic CropViewProvider can never
|
|
352
|
+
// disagree. No crop ⇒ the letterboxed scale to EXACTLY W×H (no stretch).
|
|
353
|
+
'-vf', buildVideoFilter(this.width, this.height, this.crop),
|
|
354
|
+
];
|
|
355
|
+
if (this.outputFormat === 'jpeg') {
|
|
356
|
+
// mjpeg muxer + one frame → a single standalone JPEG on stdout, so no
|
|
357
|
+
// downstream image library (e.g. `sharp`) is needed for the cloud POST.
|
|
358
|
+
return { args: [...base, '-f', 'mjpeg', '-q:v', String(mjpegQv(this.jpegQuality)), 'pipe:1'], cleanup: input.cleanup };
|
|
359
|
+
}
|
|
360
|
+
return { args: [...base, '-f', 'rawvideo', '-pix_fmt', 'rgb24', 'pipe:1'], cleanup: input.cleanup };
|
|
361
|
+
}
|
|
362
|
+
async captureFrameWithTransientRetries(attempts) {
|
|
363
|
+
let lastError;
|
|
364
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
365
|
+
try {
|
|
366
|
+
return await this.captureFrame();
|
|
367
|
+
}
|
|
368
|
+
catch (err) {
|
|
369
|
+
lastError = err;
|
|
370
|
+
if (attempt >= attempts || !isRetryableStartupFrameFailure(err)) {
|
|
371
|
+
throw err;
|
|
372
|
+
}
|
|
373
|
+
if (this.transientRetryDelayMs > 0) {
|
|
374
|
+
await new Promise((resolve) => setTimeout(resolve, this.transientRetryDelayMs));
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
throw lastError instanceof Error ? lastError : new Error(String(lastError ?? 'RTSP frame capture failed'));
|
|
379
|
+
}
|
|
380
|
+
captureFrame() {
|
|
381
|
+
return new Promise((resolve, reject) => {
|
|
382
|
+
const chunks = [];
|
|
383
|
+
let stderr = '';
|
|
384
|
+
const capture = this.buildCaptureArgs();
|
|
385
|
+
let cleaned = false;
|
|
386
|
+
const cleanup = () => {
|
|
387
|
+
if (cleaned)
|
|
388
|
+
return;
|
|
389
|
+
cleaned = true;
|
|
390
|
+
capture.cleanup();
|
|
391
|
+
};
|
|
392
|
+
let proc;
|
|
393
|
+
try {
|
|
394
|
+
proc = (0, child_process_1.spawn)(this.ffmpegPath, capture.args, {
|
|
395
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
catch (err) {
|
|
399
|
+
cleanup();
|
|
400
|
+
reject(new Error(`Failed to spawn ffmpeg: ${err.message}`));
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
proc.stdout.on('data', (chunk) => {
|
|
404
|
+
chunks.push(chunk);
|
|
405
|
+
});
|
|
406
|
+
proc.stderr.on('data', (chunk) => {
|
|
407
|
+
stderr += chunk.toString('utf-8');
|
|
408
|
+
});
|
|
409
|
+
let settled = false;
|
|
410
|
+
const rejectOnce = (err) => {
|
|
411
|
+
if (settled)
|
|
412
|
+
return;
|
|
413
|
+
settled = true;
|
|
414
|
+
cleanup();
|
|
415
|
+
reject(err);
|
|
416
|
+
};
|
|
417
|
+
const resolveOnce = (frame) => {
|
|
418
|
+
if (settled)
|
|
419
|
+
return;
|
|
420
|
+
settled = true;
|
|
421
|
+
cleanup();
|
|
422
|
+
resolve(frame);
|
|
423
|
+
};
|
|
424
|
+
proc.on('error', (err) => {
|
|
425
|
+
rejectOnce(new Error(`Failed to spawn ffmpeg: ${err.message}`));
|
|
426
|
+
});
|
|
427
|
+
proc.on('close', (code) => {
|
|
428
|
+
const frame = Buffer.concat(chunks);
|
|
429
|
+
if (this.outputFormat === 'jpeg') {
|
|
430
|
+
// A real JPEG starts with the SOI marker (0xFFD8). Validate that
|
|
431
|
+
// rather than a fixed size (JPEG is variable-length).
|
|
432
|
+
if (frame.length >= 3 && frame[0] === 0xff && frame[1] === 0xd8) {
|
|
433
|
+
resolveOnce(frame);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
if (code !== 0) {
|
|
437
|
+
rejectOnce(new Error(`ffmpeg RTSP capture exited with code ${code}: ${summarizeFfmpegStderr(stderr)}`));
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
rejectOnce(new Error(`ffmpeg produced an invalid JPEG frame (${frame.length} bytes)`));
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
const expectedSize = this.width * this.height * 3; // RGB24
|
|
444
|
+
if (frame.length === expectedSize) {
|
|
445
|
+
resolveOnce(frame);
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
if (code !== 0) {
|
|
449
|
+
rejectOnce(new Error(`ffmpeg RTSP capture exited with code ${code}: ${summarizeFfmpegStderr(stderr)}`));
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
rejectOnce(new Error(`Unexpected frame size: got ${frame.length} bytes, expected ${expectedSize}`));
|
|
453
|
+
});
|
|
454
|
+
// Kill ffmpeg if it takes too long (stream timeout + 5s buffer). Some
|
|
455
|
+
// consumer NVRs yield their first decodable frame slowly under multi-feed
|
|
456
|
+
// startup, but a hung ffmpeg must still be reclaimed.
|
|
457
|
+
const wallTimeoutMs = this.timeoutUs / 1000 + 5000;
|
|
458
|
+
const killTimer = setTimeout(() => {
|
|
459
|
+
proc.kill('SIGKILL');
|
|
460
|
+
const detail = summarizeFfmpegStderr(stderr);
|
|
461
|
+
rejectOnce(new Error(`RTSP frame capture timed out after ${wallTimeoutMs}ms${detail ? `: ${detail}` : ''}`));
|
|
462
|
+
}, wallTimeoutMs);
|
|
463
|
+
proc.on('close', () => clearTimeout(killTimer));
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
exports.RTSPCameraProvider = RTSPCameraProvider;
|
|
468
|
+
//# sourceMappingURL=RTSPCameraProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RTSPCameraProvider.js","sourceRoot":"","sources":["../src/RTSPCameraProvider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA8D;AAC9D,uCAAyB;AACzB,uCAAyB;AACzB,2CAA6B;AAoB7B;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,gBAAgB,CAAC,KAAa,EAAE,MAAc,EAAE,IAAiB;IAC/E,MAAM,KAAK,GAAG,SAAS,KAAK,IAAI,MAAM,6CAA6C,KAAK,IAAI,MAAM,sBAAsB,CAAC;IACzH,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC;IACxB,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7B,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC7B,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,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C,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC,CAAC,EAC3B,EAAE,CACH,CACF,CAAC;YACJ,CAAC,EAAE,aAAa,CAAC,CAAC;YAElB,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAjXD,gDAiXC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACrF,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @trillboards/edge-platform-rtsp — Platform-neutral RTSP/IP-camera frame provider
|
|
3
|
+
//
|
|
4
|
+
// Depends only on Node's child_process + an ffmpeg binary, so it runs on
|
|
5
|
+
// Linux, macOS, Windows, and Docker. Use it whenever a camera is reachable
|
|
6
|
+
// over RTSP (IP cameras, NVR channels) regardless of host OS.
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.mjpegQv = exports.buildVideoFilter = exports.RTSPCameraProvider = void 0;
|
|
9
|
+
var RTSPCameraProvider_1 = require("./RTSPCameraProvider");
|
|
10
|
+
Object.defineProperty(exports, "RTSPCameraProvider", { enumerable: true, get: function () { return RTSPCameraProvider_1.RTSPCameraProvider; } });
|
|
11
|
+
Object.defineProperty(exports, "buildVideoFilter", { enumerable: true, get: function () { return RTSPCameraProvider_1.buildVideoFilter; } });
|
|
12
|
+
Object.defineProperty(exports, "mjpegQv", { enumerable: true, get: function () { return RTSPCameraProvider_1.mjpegQv; } });
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,mFAAmF;AACnF,EAAE;AACF,yEAAyE;AACzE,2EAA2E;AAC3E,8DAA8D;;;AAE9D,2DAAqF;AAA5E,wHAAA,kBAAkB,OAAA;AAAE,sHAAA,gBAAgB,OAAA;AAAE,6GAAA,OAAO,OAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trillboards/edge-platform-rtsp",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Platform-neutral RTSP/IP-camera frame provider (ffmpeg) for the Trillboards Edge AI SDK — works on Linux, macOS, Windows, and Docker. v0.2.0 adds outputFormat:'jpeg' (ffmpeg mjpeg muxer) so cloud-sense needs no downstream image library.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"test": "jest --passWithNoTests",
|
|
10
|
+
"clean": "rm -rf dist",
|
|
11
|
+
"prepublishOnly": "npm run build"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@trillboards/edge-core": "^0.4.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@types/jest": "^29.5.0",
|
|
18
|
+
"@types/node": "^20.0.0",
|
|
19
|
+
"jest": "^29.7.0",
|
|
20
|
+
"ts-jest": "^29.1.0",
|
|
21
|
+
"typescript": "~5.3.0"
|
|
22
|
+
},
|
|
23
|
+
"files": ["dist", "LICENSE", "README.md"],
|
|
24
|
+
"author": "Trillboards <engineering@trillboards.com>",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/trillboards/packages.git",
|
|
32
|
+
"directory": "trillboards-edge-sdk/packages/edge-platform-rtsp"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"edge-ai",
|
|
36
|
+
"dooh",
|
|
37
|
+
"rtsp",
|
|
38
|
+
"ip-camera",
|
|
39
|
+
"nvr",
|
|
40
|
+
"cctv",
|
|
41
|
+
"ffmpeg",
|
|
42
|
+
"camera",
|
|
43
|
+
"frame-capture",
|
|
44
|
+
"trillboards",
|
|
45
|
+
"ai-agent"
|
|
46
|
+
],
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18.0.0"
|
|
49
|
+
}
|
|
50
|
+
}
|