iobroker.agent-dvr 0.9.0 → 0.9.1
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/README.de.md +16 -3
- package/README.md +16 -13
- package/build/lib/recording.js +206 -2
- package/build/lib/recording.js.map +2 -2
- package/build/main.js +86 -3
- package/build/main.js.map +2 -2
- package/io-package.json +14 -14
- package/package.json +1 -1
package/README.de.md
CHANGED
|
@@ -528,7 +528,7 @@ sendTo('agent-dvr.0', 'sendRecording', {
|
|
|
528
528
|
});
|
|
529
529
|
```
|
|
530
530
|
|
|
531
|
-
Die Nachricht an das Ziel ist `{ text: 'iobfile://agent-dvr.0/<cam>/<datei>', type: 'video', fileName: '<name>.mp4', caption, user, chatId }` — Telegram ab Version 6 liest die Datei selbst aus dem Dateispeicher. Andere Ziele bekommen stattdessen den absoluten Dateipfad (bzw. die URI, wenn der Dateispeicher nicht auf der lokalen Platte liegt). Die Antwort ist `{ ok, error?, fileName, format, mime, size, uri, url, file }`. **Telegram-Bots können nur Dateien bis 50 MB senden**; größere Aufnahmen werden mit einer klaren Fehlermeldung abgelehnt — schon vor dem Download, wenn AgentDVR die Größe bereits listet.
|
|
531
|
+
Die Nachricht an das Ziel ist `{ text: 'iobfile://agent-dvr.0/<cam>/<datei>', type: 'video', fileName: '<name>.mp4', width, height, duration, caption, user, chatId }` — Telegram ab Version 6 liest die Datei selbst aus dem Dateispeicher. `width`, `height` und `duration` liest der Adapter aus der Videodatei: Telegram erkennt sie bei größeren Bot-Uploads nicht selbst und zeigt das Video im Chat sonst bis zum Öffnen im falschen Seitenverhältnis. Andere Ziele bekommen stattdessen den absoluten Dateipfad (bzw. die URI, wenn der Dateispeicher nicht auf der lokalen Platte liegt). Die Antwort ist `{ ok, error?, fileName, format, mime, size, uri, url, file, width, height, duration }`. Eine Aufnahme, die AgentDVR noch schreibt, wird verschickt, sobald sie fertig ist. **Telegram-Bots können nur Dateien bis 50 MB senden**; größere Aufnahmen werden mit einer klaren Fehlermeldung abgelehnt — schon vor dem Download, wenn AgentDVR die Größe bereits listet.
|
|
532
532
|
|
|
533
533
|
> **Über den ioBroker-Nachrichtenbus gehen keine Videodaten.** Große Nachrichten (zig MB) können die States-DB und damit den ganzen ioBroker blockieren. Deshalb gibt der Adapter nur den Dateiverweis weiter und verweigert jede Nachricht oder Antwort mit Binärdaten.
|
|
534
534
|
|
|
@@ -540,9 +540,17 @@ on({ id: 'agent-dvr.0.cam_8_Reolink.events.new', val: true }, () => {
|
|
|
540
540
|
});
|
|
541
541
|
```
|
|
542
542
|
|
|
543
|
-
Ist der Dateispeicher eingeschaltet, stattdessen auf `recordings.ts1` triggern und die gespeicherte Kopie senden (`recording: 1`)
|
|
543
|
+
Ist der Dateispeicher eingeschaltet, stattdessen auf `recordings.ts1` triggern und die gespeicherte Kopie senden (`recording: 1`):
|
|
544
544
|
|
|
545
|
-
|
|
545
|
+
```js
|
|
546
|
+
on({ id: 'agent-dvr.0.cam_8_Reolink.recordings.ts1', change: 'ne', ack: true }, () => {
|
|
547
|
+
sendTo('agent-dvr.0', 'sendRecording', { camera: 'cam_8_Reolink', recording: 1, target: 'telegram.0', caption: 'Neue Aufnahme' });
|
|
548
|
+
});
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
> **Tipp: das richtige Seitenverhältnis im Chat.** Schickst du die Videodatei selbst an Telegram (Telegram-Block in Blockly, `recordings.file1`/`uri1`), zeigt Telegram größere Videos in der Chat-Vorschau oft im falschen Format (z. B. 3:4), bis man sie öffnet — Telegram liest die Bildgröße bei größeren Bot-Uploads nicht selbst aus. `sendRecording` liest Breite, Höhe und Dauer aus der Videodatei und gibt sie mit, so läuft das Video im Chat sofort im Seitenverhältnis der Kamera. Nichts einzustellen — es klappt einfach, wenn du `sendRecording` nimmst.
|
|
552
|
+
|
|
553
|
+
`getRecording` nimmt dieselben `camera`, `recording` und `mp4`, stellt die Aufnahme genauso bereit und liefert nur, wo sie liegt: `{ ok, error?, fileName, mime, format, size, uri, url, file, width, height, duration }`. Die Datei liest das Skript selbst, z. B.:
|
|
546
554
|
|
|
547
555
|
```js
|
|
548
556
|
sendTo('agent-dvr.0', 'getRecording', { camera: 'cam_8_Reolink', recording: 'last' }, res => {
|
|
@@ -615,6 +623,11 @@ z. B. `http://192.168.1.10:8082/agent-dvr.0/photos/cam_8_Reolink/grab1.jpg` (ebe
|
|
|
615
623
|
Placeholder for the next version (at the beginning of the line):
|
|
616
624
|
### **WORK IN PROGRESS**
|
|
617
625
|
-->
|
|
626
|
+
### 0.9.1 (2026-11-13)
|
|
627
|
+
* (ipod86) fix: Aufnahmen wurden gespeichert, während AgentDVR sie noch schrieb (Video abgeschnitten) — der Adapter wartet jetzt, bis die Aufnahme fertig ist
|
|
628
|
+
* (ipod86) fix: `sendRecording` gibt Breite, Höhe und Dauer an Telegram mit — größere Videos wurden im Chat im falschen Seitenverhältnis gezeigt; `sendRecording`/`getRecording` warten außerdem, bis eine Aufnahme fertig ist
|
|
629
|
+
* (ipod86) feat: Nachrichten `getCameras` und `getWidgets` für die Web-Komponenten (Vorbereitung für Auswahllisten statt Objektbaum)
|
|
630
|
+
|
|
618
631
|
### 0.9.0 (2026-11-12)
|
|
619
632
|
* (ipod86) feat: die letzten 1–3 Aufnahmen pro Kamera im ioBroker-Dateispeicher (`recordings.file/uri/url/name/ts`), auf Wunsch als MP4 über ffmpeg
|
|
620
633
|
* (ipod86) feat: `sendRecording` / `getRecording` schicken eine Aufnahme als Video an Telegram oder stellen sie als Datei für Skripte bereit
|
package/README.md
CHANGED
|
@@ -533,7 +533,7 @@ sendTo('agent-dvr.0', 'sendRecording', {
|
|
|
533
533
|
});
|
|
534
534
|
```
|
|
535
535
|
|
|
536
|
-
The message to the target is `{ text: 'iobfile://agent-dvr.0/<cam>/<file>', type: 'video', fileName: '<name>.mp4', caption, user, chatId }` — Telegram 6 and newer reads the file itself from the file storage. Other targets get the absolute file path instead (or the URI if the file storage is not on the local disk). The answer is `{ ok, error?, fileName, format, mime, size, uri, url, file }`. **Telegram bots can only send files up to 50 MB**; larger recordings are rejected with a clear error — before downloading when AgentDVR already lists the size.
|
|
536
|
+
The message to the target is `{ text: 'iobfile://agent-dvr.0/<cam>/<file>', type: 'video', fileName: '<name>.mp4', width, height, duration, caption, user, chatId }` — Telegram 6 and newer reads the file itself from the file storage. `width`, `height` and `duration` are read from the video file: Telegram does not detect them itself for larger bot uploads and would otherwise show the video in the chat in a wrong aspect ratio until it is opened. Other targets get the absolute file path instead (or the URI if the file storage is not on the local disk). The answer is `{ ok, error?, fileName, format, mime, size, uri, url, file, width, height, duration }`. A recording AgentDVR is still writing is sent once it is finished. **Telegram bots can only send files up to 50 MB**; larger recordings are rejected with a clear error — before downloading when AgentDVR already lists the size.
|
|
537
537
|
|
|
538
538
|
> **No video data goes over the ioBroker message bus.** Large messages (tens of MB) can block the states DB and with it the whole ioBroker. That is why the adapter passes only the file reference and refuses to send or answer anything that contains binary data.
|
|
539
539
|
|
|
@@ -545,9 +545,17 @@ on({ id: 'agent-dvr.0.cam_8_Reolink.events.new', val: true }, () => {
|
|
|
545
545
|
});
|
|
546
546
|
```
|
|
547
547
|
|
|
548
|
-
With the file storage feature enabled, trigger on `recordings.ts1` and send the stored copy instead (`recording: 1`)
|
|
548
|
+
With the file storage feature enabled, trigger on `recordings.ts1` and send the stored copy instead (`recording: 1`):
|
|
549
549
|
|
|
550
|
-
|
|
550
|
+
```js
|
|
551
|
+
on({ id: 'agent-dvr.0.cam_8_Reolink.recordings.ts1', change: 'ne', ack: true }, () => {
|
|
552
|
+
sendTo('agent-dvr.0', 'sendRecording', { camera: 'cam_8_Reolink', recording: 1, target: 'telegram.0', caption: 'New recording' });
|
|
553
|
+
});
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
> **Tip: the right aspect ratio in the chat.** If you send the video file to Telegram yourself (Telegram Blockly block, `recordings.file1`/`uri1`), Telegram often shows larger videos in the chat preview in a wrong format (e.g. 3:4) until you open them — Telegram does not read the picture size from larger bot uploads itself. `sendRecording` reads width, height and duration from the video file and passes them along, so the video plays in the chat right away in the camera's aspect ratio. Nothing to configure, it simply works when you use `sendRecording`.
|
|
557
|
+
|
|
558
|
+
`getRecording` takes the same `camera`, `recording` and `mp4`, makes the recording available the same way and returns only where it is: `{ ok, error?, fileName, mime, format, size, uri, url, file, width, height, duration }`. Read the file in your script yourself, e.g.:
|
|
551
559
|
|
|
552
560
|
```js
|
|
553
561
|
sendTo('agent-dvr.0', 'getRecording', { camera: 'cam_8_Reolink', recording: 'last' }, res => {
|
|
@@ -615,6 +623,11 @@ http://<iobroker>:<webport>/agent-dvr.0/photos/<cam>/grab1.jpg
|
|
|
615
623
|
e.g. `http://192.168.1.10:8082/agent-dvr.0/photos/cam_8_Reolink/grab1.jpg` (also `grab2.jpg`, `grab3.jpg`). Use it in an image widget and refresh it on changes of `alertPhotos.ts1`. The same applies when you push the link to a TV or another app: send it on `alertPhotos.ts1`, not on `events.webhook` — otherwise the app loads the previous photo. For a live image use `urls.snapshot` or `urls.photo` with a refresh interval.
|
|
616
624
|
|
|
617
625
|
## Changelog
|
|
626
|
+
### 0.9.1 (2026-11-13)
|
|
627
|
+
* (ipod86) fix: recordings were stored while AgentDVR was still writing them (video cut off) — the adapter now waits until the recording is finished
|
|
628
|
+
* (ipod86) fix: `sendRecording` passes width, height and duration to Telegram — larger videos were shown in a wrong aspect ratio in the chat; `sendRecording`/`getRecording` also wait until a recording is finished
|
|
629
|
+
* (ipod86) feat: messages `getCameras` and `getWidgets` for the web components (prepares dropdowns instead of the object browser)
|
|
630
|
+
|
|
618
631
|
### 0.9.0 (2026-11-12)
|
|
619
632
|
* (ipod86) feat: keep the last 1–3 recordings per camera in the ioBroker file storage (`recordings.file/uri/url/name/ts`), optionally as MP4 via ffmpeg
|
|
620
633
|
* (ipod86) feat: `sendRecording` / `getRecording` send a recording to Telegram as video or provide it as a file for scripts
|
|
@@ -635,16 +648,6 @@ e.g. `http://192.168.1.10:8082/agent-dvr.0/photos/cam_8_Reolink/grab1.jpg` (also
|
|
|
635
648
|
|
|
636
649
|
<!-- markdownlint-disable-next-line MD024 -->
|
|
637
650
|
|
|
638
|
-
### 0.6.0 (2026-10-29)
|
|
639
|
-
* (ipod86) chore: clearer adapter title ("Agent DVR – Cameras & Recordings") and keywords
|
|
640
|
-
* (ipod86) fix: `events.detected_*` now also fires when AgentDVR adds the AI tag (e.g. `people`) to a recording after it was first listed
|
|
641
|
-
* (ipod86) feat: webhook with `?oid={ID}&ot={OT}` pulses `<cam>.events.webhook` immediately (20 s cooldown per camera) for the fastest possible alert photo
|
|
642
|
-
* (ipod86) feat: alert photos — on a webhook call with `oid` the full-resolution photo is stored in the file storage, last 3 per camera (`alertPhotos.grab1–3`, `ts1–3`)
|
|
643
|
-
* (ipod86) feat: alert photos served for VIS at `/agent-dvr.0/photos/<cam>/grab1.jpg`; new README section on getting images for VIS and scripts
|
|
644
|
-
* (ipod86) feat: `alertPhotos.uri1–3` with the `iobfile://` URI of each photo, sendable directly with Telegram 6
|
|
645
|
-
|
|
646
|
-
<!-- markdownlint-disable-next-line MD024 -->
|
|
647
|
-
|
|
648
651
|
[Older changelog entries in CHANGELOG_OLD.md](CHANGELOG_OLD.md)
|
|
649
652
|
|
|
650
653
|
## License
|
package/build/lib/recording.js
CHANGED
|
@@ -52,6 +52,7 @@ __export(recording_exports, {
|
|
|
52
52
|
probeFfmpeg: () => probeFfmpeg,
|
|
53
53
|
recordingAbsPath: () => recordingAbsPath,
|
|
54
54
|
recordingFileName: () => recordingFileName,
|
|
55
|
+
recordingFinished: () => recordingFinished,
|
|
55
56
|
recordingSlots: () => recordingSlots,
|
|
56
57
|
recordingStoragePath: () => recordingStoragePath,
|
|
57
58
|
recordingUri: () => recordingUri,
|
|
@@ -61,7 +62,8 @@ __export(recording_exports, {
|
|
|
61
62
|
resolveOnPath: () => resolveOnPath,
|
|
62
63
|
runFfmpeg: () => runFfmpeg,
|
|
63
64
|
safeMessage: () => safeMessage,
|
|
64
|
-
sendFileStoragePath: () => sendFileStoragePath
|
|
65
|
+
sendFileStoragePath: () => sendFileStoragePath,
|
|
66
|
+
videoInfo: () => videoInfo
|
|
65
67
|
});
|
|
66
68
|
module.exports = __toCommonJS(recording_exports);
|
|
67
69
|
var import_node_child_process = require("node:child_process");
|
|
@@ -227,6 +229,206 @@ async function detectFfmpeg(candidates, probe = (b) => probeFfmpeg(b)) {
|
|
|
227
229
|
function ffmpegStatusText(info) {
|
|
228
230
|
return info.found ? `${info.version} (${info.path})` : "not found";
|
|
229
231
|
}
|
|
232
|
+
function recordingFinished(prevSize, size, recording) {
|
|
233
|
+
return !recording && size > 0 && size === prevSize;
|
|
234
|
+
}
|
|
235
|
+
function* mp4Boxes(buf, from, to) {
|
|
236
|
+
let p = from;
|
|
237
|
+
while (p + 8 <= to) {
|
|
238
|
+
let size = buf.readUInt32BE(p);
|
|
239
|
+
const type = buf.toString("latin1", p + 4, p + 8);
|
|
240
|
+
let head = 8;
|
|
241
|
+
if (size === 1) {
|
|
242
|
+
if (p + 16 > to) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
size = Number(buf.readBigUInt64BE(p + 8));
|
|
246
|
+
head = 16;
|
|
247
|
+
} else if (size === 0) {
|
|
248
|
+
size = to - p;
|
|
249
|
+
}
|
|
250
|
+
if (size < head) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
yield { type, start: p + head, end: Math.min(p + size, to) };
|
|
254
|
+
p += size;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function mp4Child(buf, parent, type) {
|
|
258
|
+
for (const b of mp4Boxes(buf, parent.start, parent.end)) {
|
|
259
|
+
if (b.type === type) {
|
|
260
|
+
return b;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return void 0;
|
|
264
|
+
}
|
|
265
|
+
function mp4Info(buf) {
|
|
266
|
+
const info = { width: 0, height: 0, duration: 0 };
|
|
267
|
+
const top = [...mp4Boxes(buf, 0, buf.length)];
|
|
268
|
+
const moov = top.find((b) => b.type === "moov");
|
|
269
|
+
if (!moov) {
|
|
270
|
+
return info;
|
|
271
|
+
}
|
|
272
|
+
let videoId = 0;
|
|
273
|
+
let videoScale = 0;
|
|
274
|
+
for (const trak of mp4Boxes(buf, moov.start, moov.end)) {
|
|
275
|
+
if (trak.type !== "trak") {
|
|
276
|
+
continue;
|
|
277
|
+
}
|
|
278
|
+
const tkhd = mp4Child(buf, trak, "tkhd");
|
|
279
|
+
if (!tkhd || tkhd.end - tkhd.start < 84) {
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
const w = buf.readUInt32BE(tkhd.end - 8) / 65536;
|
|
283
|
+
const h = buf.readUInt32BE(tkhd.end - 4) / 65536;
|
|
284
|
+
if (w > 0 && h > 0) {
|
|
285
|
+
const v1 = buf[tkhd.start] === 1;
|
|
286
|
+
videoId = buf.readUInt32BE(tkhd.start + (v1 ? 20 : 12));
|
|
287
|
+
info.width = Math.round(w);
|
|
288
|
+
info.height = Math.round(h);
|
|
289
|
+
const mdia = mp4Child(buf, trak, "mdia");
|
|
290
|
+
const mdhd = mdia && mp4Child(buf, mdia, "mdhd");
|
|
291
|
+
if (mdhd) {
|
|
292
|
+
videoScale = buf.readUInt32BE(mdhd.start + (buf[mdhd.start] === 1 ? 20 : 12));
|
|
293
|
+
}
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
const mvhd = mp4Child(buf, moov, "mvhd");
|
|
298
|
+
if (mvhd) {
|
|
299
|
+
const v1 = buf[mvhd.start] === 1;
|
|
300
|
+
const scale = buf.readUInt32BE(mvhd.start + (v1 ? 20 : 12));
|
|
301
|
+
const dur = v1 ? Number(buf.readBigUInt64BE(mvhd.start + 24)) : buf.readUInt32BE(mvhd.start + 16);
|
|
302
|
+
if (scale > 0 && dur > 0) {
|
|
303
|
+
info.duration = Math.round(dur / scale);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (!info.duration && videoId && videoScale) {
|
|
307
|
+
let end = 0;
|
|
308
|
+
for (const moof of top) {
|
|
309
|
+
if (moof.type !== "moof") {
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
for (const traf of mp4Boxes(buf, moof.start, moof.end)) {
|
|
313
|
+
if (traf.type !== "traf") {
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
const tfhd = mp4Child(buf, traf, "tfhd");
|
|
317
|
+
if (!tfhd || buf.readUInt32BE(tfhd.start + 4) !== videoId) {
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
const tfFlags = buf.readUInt32BE(tfhd.start) & 16777215;
|
|
321
|
+
let q = tfhd.start + 8;
|
|
322
|
+
if (tfFlags & 1) {
|
|
323
|
+
q += 8;
|
|
324
|
+
}
|
|
325
|
+
if (tfFlags & 2) {
|
|
326
|
+
q += 4;
|
|
327
|
+
}
|
|
328
|
+
const defDur = tfFlags & 8 ? buf.readUInt32BE(q) : 0;
|
|
329
|
+
const tfdt = mp4Child(buf, traf, "tfdt");
|
|
330
|
+
let t = 0;
|
|
331
|
+
if (tfdt) {
|
|
332
|
+
t = buf[tfdt.start] === 1 ? Number(buf.readBigUInt64BE(tfdt.start + 4)) : buf.readUInt32BE(tfdt.start + 4);
|
|
333
|
+
}
|
|
334
|
+
for (const trun of mp4Boxes(buf, traf.start, traf.end)) {
|
|
335
|
+
if (trun.type !== "trun") {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
const flags = buf.readUInt32BE(trun.start) & 16777215;
|
|
339
|
+
const count = buf.readUInt32BE(trun.start + 4);
|
|
340
|
+
let r = trun.start + 8 + (flags & 1 ? 4 : 0) + (flags & 4 ? 4 : 0);
|
|
341
|
+
const per = (flags & 256 ? 4 : 0) + (flags & 512 ? 4 : 0) + (flags & 1024 ? 4 : 0) + (flags & 2048 ? 4 : 0);
|
|
342
|
+
for (let i = 0; i < count && r + per <= trun.end; i++) {
|
|
343
|
+
t += flags & 256 ? buf.readUInt32BE(r) : defDur;
|
|
344
|
+
r += per;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
end = Math.max(end, t);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (end > 0) {
|
|
351
|
+
info.duration = Math.round(end / videoScale);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return info;
|
|
355
|
+
}
|
|
356
|
+
function ebmlVint(buf, p, keepMarker) {
|
|
357
|
+
if (p >= buf.length) {
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
const first = buf[p];
|
|
361
|
+
let len = 1;
|
|
362
|
+
while (len <= 8 && !(first & 128 >> len - 1)) {
|
|
363
|
+
len++;
|
|
364
|
+
}
|
|
365
|
+
if (len > 8 || p + len > buf.length) {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
let val = keepMarker ? first : first & 255 >> len;
|
|
369
|
+
let allOnes = (first & 255 >> len) === 255 >> len;
|
|
370
|
+
for (let i = 1; i < len; i++) {
|
|
371
|
+
val = val * 256 + buf[p + i];
|
|
372
|
+
if (buf[p + i] !== 255) {
|
|
373
|
+
allOnes = false;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return { val, len, unknown: allOnes };
|
|
377
|
+
}
|
|
378
|
+
function mkvInfo(buf) {
|
|
379
|
+
const info = { width: 0, height: 0, duration: 0 };
|
|
380
|
+
let scale = 1e6;
|
|
381
|
+
let durTicks = 0;
|
|
382
|
+
const MASTER = /* @__PURE__ */ new Set([408125543, 357149030, 374648427, 174, 224]);
|
|
383
|
+
const walk = (from, to, depth) => {
|
|
384
|
+
let p = from;
|
|
385
|
+
while (p < to && depth < 6) {
|
|
386
|
+
const id = ebmlVint(buf, p, true);
|
|
387
|
+
const size = id && ebmlVint(buf, p + id.len, false);
|
|
388
|
+
if (!id || !size) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const start = p + id.len + size.len;
|
|
392
|
+
const end = size.unknown ? to : Math.min(start + size.val, to);
|
|
393
|
+
if (id.val === 524531317) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
if (MASTER.has(id.val)) {
|
|
397
|
+
walk(start, end, depth + 1);
|
|
398
|
+
} else if (id.val === 176 || id.val === 186 || id.val === 2807729) {
|
|
399
|
+
let v = 0;
|
|
400
|
+
for (let i = start; i < end; i++) {
|
|
401
|
+
v = v * 256 + buf[i];
|
|
402
|
+
}
|
|
403
|
+
if (id.val === 176 && !info.width) {
|
|
404
|
+
info.width = v;
|
|
405
|
+
} else if (id.val === 186 && !info.height) {
|
|
406
|
+
info.height = v;
|
|
407
|
+
} else if (id.val === 2807729) {
|
|
408
|
+
scale = v;
|
|
409
|
+
}
|
|
410
|
+
} else if (id.val === 17545) {
|
|
411
|
+
durTicks = end - start === 8 ? buf.readDoubleBE(start) : end - start === 4 ? buf.readFloatBE(start) : 0;
|
|
412
|
+
}
|
|
413
|
+
if (size.unknown) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
p = end;
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
walk(0, buf.length, 0);
|
|
420
|
+
if (durTicks > 0) {
|
|
421
|
+
info.duration = Math.round(durTicks * scale / 1e9);
|
|
422
|
+
}
|
|
423
|
+
return info;
|
|
424
|
+
}
|
|
425
|
+
function videoInfo(buf, format) {
|
|
426
|
+
try {
|
|
427
|
+
return format === "mkv" ? mkvInfo(buf) : mp4Info(buf);
|
|
428
|
+
} catch {
|
|
429
|
+
return { width: 0, height: 0, duration: 0 };
|
|
430
|
+
}
|
|
431
|
+
}
|
|
230
432
|
function isHevcMkv(buf) {
|
|
231
433
|
return buf.subarray(0, 256 * 1024).includes("V_MPEGH/ISO/HEVC");
|
|
232
434
|
}
|
|
@@ -433,6 +635,7 @@ function safeMessage(value) {
|
|
|
433
635
|
probeFfmpeg,
|
|
434
636
|
recordingAbsPath,
|
|
435
637
|
recordingFileName,
|
|
638
|
+
recordingFinished,
|
|
436
639
|
recordingSlots,
|
|
437
640
|
recordingStoragePath,
|
|
438
641
|
recordingUri,
|
|
@@ -442,6 +645,7 @@ function safeMessage(value) {
|
|
|
442
645
|
resolveOnPath,
|
|
443
646
|
runFfmpeg,
|
|
444
647
|
safeMessage,
|
|
445
|
-
sendFileStoragePath
|
|
648
|
+
sendFileStoragePath,
|
|
649
|
+
videoInfo
|
|
446
650
|
});
|
|
447
651
|
//# sourceMappingURL=recording.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/lib/recording.ts"],
|
|
4
|
-
"sourcesContent": ["// Helpers for \"recordings in the ioBroker file storage\" and sendRecording/getRecording:\n// ffmpeg detection, in-memory MKV -> MP4 remux, size limits, file names, URIs and URLs.\n// Kept free of adapter state so they can be unit tested.\n\nimport { spawn } from 'node:child_process';\nimport * as fs from 'node:fs';\nimport * as http from 'node:http';\nimport * as path from 'node:path';\n\n/** Telegram bots can upload at most 50 MB per file */\nexport const TELEGRAM_MAX_BYTES = 50 * 1024 * 1024;\n\nexport const MB = 1024 * 1024;\n\n/** Result of the ffmpeg detection */\nexport interface FfmpegInfo {\n\t/** true if a working ffmpeg was found */\n\tfound: boolean;\n\t/** ffmpeg version, e.g. 6.1.1 */\n\tversion: string;\n\t/** binary that answered */\n\tpath: string;\n}\n\n/**\n * Clamps a configured number into [min, max]; non-numbers fall back to the default.\n *\n * @param raw configured value\n * @param def default value\n * @param min lower bound\n * @param max upper bound\n */\nexport function clampNumber(raw: unknown, def: number, min: number, max: number): number {\n\tconst n = typeof raw === 'number' ? raw : parseFloat(typeof raw === 'string' ? raw : '');\n\tif (!Number.isFinite(n)) {\n\t\treturn def;\n\t}\n\treturn Math.max(min, Math.min(max, Math.round(n)));\n}\n\n/**\n * Number of kept recordings per camera (1..3, default 1).\n *\n * @param raw configured value\n */\nexport function recordingSlots(raw: unknown): number {\n\treturn clampNumber(raw, 1, 1, 3);\n}\n\n/**\n * Maximum recording size in bytes (configured in MB, 1..2000, default 50).\n *\n * @param rawMb configured value in MB\n */\nexport function maxRecordingBytes(rawMb: unknown): number {\n\treturn clampNumber(rawMb, 50, 1, 2000) * MB;\n}\n\n/**\n * Size check result for a recording against a byte limit.\n *\n * @param bytes size of the recording (0/NaN = unknown \u2192 allowed)\n * @param limit maximum in bytes\n */\nexport function exceedsLimit(bytes: number, limit: number): boolean {\n\treturn Number.isFinite(bytes) && bytes > 0 && bytes > limit;\n}\n\n/**\n * Human readable MB value with one decimal.\n *\n * @param bytes size in bytes\n */\nexport function fmtMb(bytes: number): string {\n\treturn `${(Math.round((bytes / MB) * 10) / 10).toFixed(1)} MB`;\n}\n\n/**\n * File name of a stored recording slot inside the camera folder.\n *\n * @param slot slot number (1 = newest)\n * @param ext 'mp4' or 'mkv'\n */\nexport function recordingFileName(slot: number, ext: string): string {\n\treturn `rec${slot}.${ext}`;\n}\n\n/**\n * Path of a stored recording inside the adapter's file storage (meta object = namespace).\n *\n * @param fid camera folder id, e.g. cam_8_Reolink\n * @param slot slot number\n * @param ext file extension\n */\nexport function recordingStoragePath(fid: string, slot: number, ext: string): string {\n\treturn `${fid}/${recordingFileName(slot, ext)}`;\n}\n\n/**\n * Fixed per-camera file used by sendRecording/getRecording for recordings that are not in a slot.\n *\n * @param fid camera folder id\n * @param ext file extension\n */\nexport function sendFileStoragePath(fid: string, ext: string): string {\n\treturn `${fid}/send.${ext}`;\n}\n\n/**\n * All recording files a camera can have in the file storage (slots and the send file).\n */\nexport function cameraRecordingFiles(): string[] {\n\tconst out: string[] = [];\n\tfor (const ext of ['mp4', 'mkv']) {\n\t\tfor (let i = 1; i <= 3; i++) {\n\t\t\tout.push(`rec${i}.${ext}`);\n\t\t}\n\t\tout.push(`send.${ext}`);\n\t}\n\treturn out;\n}\n\n/**\n * True if the current last recording should be stored on start: slot 1 empty or holding another recording.\n *\n * @param slot1Exists slot 1 file exists\n * @param name1 value of recordings.name1\n * @param lastFn file name of the newest recording in AgentDVR\n */\nexport function needsInitialFill(slot1Exists: boolean, name1: unknown, lastFn: string): boolean {\n\tif (!lastFn) {\n\t\treturn false;\n\t}\n\treturn !slot1Exists || name1 !== lastFn;\n}\n\n/**\n * ioBroker file URI resolved by telegram >= 6 (same format as the alert photos).\n *\n * @param namespace adapter namespace (meta object id), e.g. agent-dvr.0\n * @param fid camera folder id\n * @param slot slot number\n * @param ext file extension\n */\nexport function recordingUri(namespace: string, fid: string, slot: number, ext: string): string {\n\treturn `iobfile://${namespace}/${recordingStoragePath(fid, slot, ext)}`;\n}\n\n/**\n * Absolute path where a file-based objects DB keeps the file (<dataDir>/files/<metaId>/<path>).\n *\n * @param dataDir ioBroker data directory (utils.getAbsoluteDefaultDataDir())\n * @param namespace meta object id\n * @param fid camera folder id\n * @param slot slot number\n * @param ext file extension\n */\nexport function recordingAbsPath(dataDir: string, namespace: string, fid: string, slot: number, ext: string): string {\n\treturn path.join(dataDir, 'files', namespace, fid, recordingFileName(slot, ext));\n}\n\n/**\n * http(s) URL via the web extension, empty without a web instance.\n *\n * @param webBase base URL of the web instance, e.g. http://192.168.1.10:8082\n * @param namespace adapter namespace\n * @param fid camera folder id\n * @param slot slot number\n * @param ext file extension\n */\nexport function recordingUrl(webBase: string, namespace: string, fid: string, slot: number, ext: string): string {\n\treturn webBase ? `${webBase}/${namespace}/recordings/${fid}/${recordingFileName(slot, ext)}` : '';\n}\n\n/**\n * Extension of an AgentDVR recording file name ('mkv' when unknown).\n *\n * @param fn file name, e.g. 8_2026-11-12_15-55-29_931.mkv\n */\nexport function extOf(fn: string): string {\n\tconst m = /\\.([A-Za-z0-9]+)$/.exec(fn || '');\n\treturn m ? m[1].toLowerCase() : 'mkv';\n}\n\n/**\n * Mime type for a recording extension.\n *\n * @param ext file extension\n */\nexport function mimeOf(ext: string): string {\n\treturn ext === 'mp4' ? 'video/mp4' : ext === 'mkv' ? 'video/x-matroska' : 'application/octet-stream';\n}\n\n/**\n * Only plain AgentDVR recording file names are accepted (no paths).\n *\n * @param fn requested file name\n */\nexport function isValidRecordingName(fn: string): boolean {\n\treturn /^[\\w.-]{1,200}\\.(mkv|mp4)$/i.test(fn) && !fn.includes('..');\n}\n\n// ---- ffmpeg detection ----\n\n/**\n * Ordered list of ffmpeg binaries to try: configured path, PATH lookup, common locations.\n *\n * @param configPath configured path (empty = auto)\n * @param platform process.platform\n */\nexport function ffmpegCandidates(configPath: string, platform: string): string[] {\n\tconst out: string[] = [];\n\tconst add = (p: string | undefined): void => {\n\t\tconst v = (p || '').trim();\n\t\tif (v && !out.includes(v)) {\n\t\t\tout.push(v);\n\t\t}\n\t};\n\tadd(configPath);\n\tadd('ffmpeg');\n\tif (platform === 'win32') {\n\t\tadd('C:\\\\ffmpeg\\\\bin\\\\ffmpeg.exe');\n\t\tadd('C:\\\\Program Files\\\\ffmpeg\\\\bin\\\\ffmpeg.exe');\n\t} else {\n\t\tadd('/usr/bin/ffmpeg');\n\t\tadd('/usr/local/bin/ffmpeg');\n\t\tadd('/opt/homebrew/bin/ffmpeg');\n\t}\n\treturn out;\n}\n\n/**\n * Absolute path of a bare binary name (for display): looked up in the usual binary folders,\n * otherwise the name itself (it was found via the search path of the system).\n *\n * @param bin binary name or path\n * @param platform process.platform\n * @param exists file check (injectable for tests)\n */\nexport function resolveOnPath(\n\tbin: string,\n\tplatform: string,\n\texists: (p: string) => boolean = p => fs.existsSync(p),\n): string {\n\tif (/[\\\\/]/.test(bin)) {\n\t\treturn bin;\n\t}\n\tconst win = platform === 'win32';\n\tconst pathMod = win ? path.win32 : path.posix;\n\tconst dirs = win\n\t\t? ['C:\\\\ffmpeg\\\\bin', 'C:\\\\Program Files\\\\ffmpeg\\\\bin']\n\t\t: ['/usr/bin', '/usr/local/bin', '/opt/homebrew/bin', '/bin'];\n\tconst names = win && !/\\.exe$/i.test(bin) ? [`${bin}.exe`, bin] : [bin];\n\tfor (const d of dirs) {\n\t\tfor (const n of names) {\n\t\t\tconst full = pathMod.join(d, n);\n\t\t\tif (exists(full)) {\n\t\t\t\treturn full;\n\t\t\t}\n\t\t}\n\t}\n\treturn bin;\n}\n\n/**\n * Version from `ffmpeg -version` output, e.g. \"6.1.1\" from \"ffmpeg version 6.1.1-3ubuntu5 Copyright ...\".\n *\n * @param out stdout of ffmpeg -version\n */\nexport function parseFfmpegVersion(out: string): string {\n\tconst m = /ffmpeg version\\s+(\\S+)/i.exec(out || '');\n\tif (!m) {\n\t\treturn '';\n\t}\n\tconst v = /^n?(\\d+(?:\\.\\d+)*)/.exec(m[1]);\n\treturn v ? v[1] : m[1];\n}\n\n/**\n * Runs `<bin> -version` and returns the version, or '' if it is not a working ffmpeg.\n *\n * @param bin binary name or path\n * @param timeoutMs timeout\n */\nexport function probeFfmpeg(bin: string, timeoutMs = 5000): Promise<string> {\n\treturn new Promise(resolve => {\n\t\tlet out = '';\n\t\tlet done = false;\n\t\tconst timer: { id?: NodeJS.Timeout } = {};\n\t\tconst finish = (v: string): void => {\n\t\t\tif (!done) {\n\t\t\t\tdone = true;\n\t\t\t\tclearTimeout(timer.id);\n\t\t\t\tresolve(v);\n\t\t\t}\n\t\t};\n\t\tlet child: ReturnType<typeof spawn>;\n\t\ttry {\n\t\t\tchild = spawn(bin, ['-version'], { shell: false, windowsHide: true });\n\t\t} catch {\n\t\t\tresolve('');\n\t\t\treturn;\n\t\t}\n\t\ttimer.id = setTimeout(() => {\n\t\t\ttry {\n\t\t\t\tchild.kill('SIGKILL');\n\t\t\t} catch {\n\t\t\t\t/* ignore */\n\t\t\t}\n\t\t\tfinish('');\n\t\t}, timeoutMs);\n\t\tchild.stdout?.on('data', (c: Buffer) => {\n\t\t\tif (out.length < 4096) {\n\t\t\t\tout += c.toString();\n\t\t\t}\n\t\t});\n\t\tchild.on('error', () => finish(''));\n\t\tchild.on('close', code => finish(code === 0 ? parseFfmpegVersion(out) : ''));\n\t});\n}\n\n/**\n * Tries the candidates in order and returns the first working ffmpeg.\n *\n * @param candidates binaries in priority order\n * @param probe returns the version or '' (injectable for tests)\n */\nexport async function detectFfmpeg(\n\tcandidates: string[],\n\tprobe: (bin: string) => Promise<string> = b => probeFfmpeg(b),\n): Promise<FfmpegInfo> {\n\tfor (const c of candidates) {\n\t\tconst version = await probe(c);\n\t\tif (version) {\n\t\t\treturn { found: true, version, path: c };\n\t\t}\n\t}\n\treturn { found: false, version: '', path: '' };\n}\n\n/**\n * Text for info.ffmpeg.\n *\n * @param info detection result\n */\nexport function ffmpegStatusText(info: FfmpegInfo): string {\n\treturn info.found ? `${info.version} (${info.path})` : 'not found';\n}\n\n// ---- remux ----\n\n/**\n * True if the Matroska header announces an HEVC video track (needs the hvc1 tag in MP4 for Apple/Telegram).\n *\n * @param buf MKV data\n */\nexport function isHevcMkv(buf: Buffer): boolean {\n\treturn buf.subarray(0, 256 * 1024).includes('V_MPEGH/ISO/HEVC');\n}\n\n/**\n * ffmpeg arguments for a lossless MKV \u2192 fragmented MP4 remux via stdin/stdout.\n *\n * @param hevc tag the video track as hvc1\n * @param dropAudio leave out the audio track\n */\nexport function remuxArgs(hevc: boolean, dropAudio: boolean): string[] {\n\tconst args = ['-hide_banner', '-loglevel', 'error', '-i', 'pipe:0', '-map', '0:v:0'];\n\tif (!dropAudio) {\n\t\targs.push('-map', '0:a?');\n\t}\n\targs.push('-c', 'copy');\n\tif (hevc) {\n\t\targs.push('-tag:v', 'hvc1');\n\t}\n\tif (dropAudio) {\n\t\targs.push('-an');\n\t}\n\targs.push('-movflags', 'frag_keyframe+empty_moov', '-f', 'mp4', 'pipe:1');\n\treturn args;\n}\n\n/**\n * Runs ffmpeg once with the input on stdin and collects stdout.\n *\n * @param bin ffmpeg binary\n * @param input input data\n * @param args ffmpeg arguments\n * @param timeoutMs timeout\n * @param maxBytes abort when the output gets larger\n */\nexport function runFfmpeg(\n\tbin: string,\n\tinput: Buffer,\n\targs: string[],\n\ttimeoutMs: number,\n\tmaxBytes: number,\n): Promise<Buffer> {\n\treturn new Promise((resolve, reject) => {\n\t\tlet done = false;\n\t\tconst timer: { id?: NodeJS.Timeout } = {};\n\t\tconst chunks: Buffer[] = [];\n\t\tlet size = 0;\n\t\tlet err = '';\n\t\tconst child = spawn(bin, args, { shell: false, windowsHide: true });\n\t\tconst fail = (e: Error): void => {\n\t\t\tif (!done) {\n\t\t\t\tdone = true;\n\t\t\t\tclearTimeout(timer.id);\n\t\t\t\ttry {\n\t\t\t\t\tchild.kill('SIGKILL');\n\t\t\t\t} catch {\n\t\t\t\t\t/* ignore */\n\t\t\t\t}\n\t\t\t\treject(e);\n\t\t\t}\n\t\t};\n\t\ttimer.id = setTimeout(\n\t\t\t() => fail(new Error(`ffmpeg timeout after ${Math.round(timeoutMs / 1000)} s`)),\n\t\t\ttimeoutMs,\n\t\t);\n\t\tchild.stdout.on('data', (c: Buffer) => {\n\t\t\tsize += c.length;\n\t\t\tif (size > maxBytes) {\n\t\t\t\tfail(new Error(`MP4 larger than ${fmtMb(maxBytes)}`));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tchunks.push(c);\n\t\t});\n\t\tchild.stderr.on('data', (c: Buffer) => {\n\t\t\tif (err.length < 2000) {\n\t\t\t\terr += c.toString();\n\t\t\t}\n\t\t});\n\t\tchild.on('error', e => fail(e));\n\t\tchild.on('close', code => {\n\t\t\tif (done) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdone = true;\n\t\t\tclearTimeout(timer.id);\n\t\t\tif (code === 0 && size > 0) {\n\t\t\t\tresolve(Buffer.concat(chunks));\n\t\t\t} else {\n\t\t\t\treject(new Error(`ffmpeg exit code ${code}: ${err.trim().split('\\n').pop() || 'no output'}`));\n\t\t\t}\n\t\t});\n\t\t// EPIPE when ffmpeg stops reading early \u2014 the close handler reports the real error\n\t\tchild.stdin.on('error', () => {});\n\t\tchild.stdin.end(input);\n\t});\n}\n\n/**\n * Remuxes MKV to MP4 without re-encoding. Retries without audio if the audio codec can't go into MP4.\n *\n * @param bin ffmpeg binary\n * @param mkv input data\n * @param timeoutMs timeout per run\n * @param maxBytes output limit\n * @param onAudioDropped called when the retry without audio was needed\n * @param run ffmpeg runner (injectable for tests)\n */\nexport async function remuxToMp4(\n\tbin: string,\n\tmkv: Buffer,\n\ttimeoutMs: number,\n\tmaxBytes: number,\n\tonAudioDropped?: (reason: string) => void,\n\trun: typeof runFfmpeg = runFfmpeg,\n): Promise<Buffer> {\n\tconst hevc = isHevcMkv(mkv);\n\ttry {\n\t\treturn await run(bin, mkv, remuxArgs(hevc, false), timeoutMs, maxBytes);\n\t} catch (e) {\n\t\tconst msg = (e as Error).message;\n\t\tif (/timeout|larger than|ENOENT|Invalid data|Error opening input/i.test(msg)) {\n\t\t\tthrow e;\n\t\t}\n\t\tconst out = await run(bin, mkv, remuxArgs(hevc, true), timeoutMs, maxBytes);\n\t\tonAudioDropped?.(msg);\n\t\treturn out;\n\t}\n}\n\n// ---- download ----\n\n/** Result of a download into memory */\nexport interface DownloadResult {\n\t/** download complete */\n\tok: boolean;\n\t/** downloaded bytes */\n\tdata?: Buffer;\n\t/** error text */\n\terror?: string;\n\t/** true when the download was stopped because of the size limit */\n\ttooLarge?: boolean;\n\t/** received or announced size in bytes */\n\tsize?: number;\n}\n\n/**\n * GET into memory with timeout and size limit (Content-Length checked first, then the received bytes).\n *\n * @param opts request options (hostname, port, path, headers)\n * @param maxBytes size limit\n * @param timeoutMs overall timeout\n */\nexport function downloadToBuffer(\n\topts: http.RequestOptions,\n\tmaxBytes: number,\n\ttimeoutMs: number,\n): Promise<DownloadResult> {\n\treturn new Promise(resolve => {\n\t\tlet done = false;\n\t\tconst timer: { id?: NodeJS.Timeout } = {};\n\t\tlet req: http.ClientRequest | undefined;\n\t\tconst finish = (r: DownloadResult): void => {\n\t\t\tif (!done) {\n\t\t\t\tdone = true;\n\t\t\t\tclearTimeout(timer.id);\n\t\t\t\tresolve(r);\n\t\t\t}\n\t\t};\n\t\ttimer.id = setTimeout(() => {\n\t\t\treq?.destroy();\n\t\t\tfinish({ ok: false, error: `timeout after ${Math.round(timeoutMs / 1000)} s` });\n\t\t}, timeoutMs);\n\t\ttry {\n\t\t\treq = http.request({ ...opts, method: 'GET' }, res => {\n\t\t\t\tif (res.statusCode && res.statusCode >= 400) {\n\t\t\t\t\tres.resume();\n\t\t\t\t\tfinish({ ok: false, error: `HTTP ${res.statusCode}` });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst len = parseInt(String(res.headers['content-length'] ?? ''), 10);\n\t\t\t\tif (exceedsLimit(len, maxBytes)) {\n\t\t\t\t\treq?.destroy();\n\t\t\t\t\tfinish({ ok: false, tooLarge: true, size: len, error: `${fmtMb(len)} > limit ${fmtMb(maxBytes)}` });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst chunks: Buffer[] = [];\n\t\t\t\tlet size = 0;\n\t\t\t\tres.on('data', (c: Buffer) => {\n\t\t\t\t\tsize += c.length;\n\t\t\t\t\tif (size > maxBytes) {\n\t\t\t\t\t\treq?.destroy();\n\t\t\t\t\t\tfinish({ ok: false, tooLarge: true, size, error: `more than ${fmtMb(maxBytes)}` });\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tchunks.push(c);\n\t\t\t\t});\n\t\t\t\tres.on('end', () => finish({ ok: true, data: Buffer.concat(chunks), size }));\n\t\t\t\tres.on('error', (e: Error) => finish({ ok: false, error: e.message }));\n\t\t\t});\n\t\t\treq.on('error', (e: Error) => finish({ ok: false, error: e.message }));\n\t\t\treq.end();\n\t\t} catch (e) {\n\t\t\tfinish({ ok: false, error: (e as Error).message });\n\t\t}\n\t});\n}\n\n// ---- camera lookup for sendTo ----\n\n/** Camera reference for findCamera */\nexport interface CamRef {\n\t/** AgentDVR object id */\n\toid: number | string;\n\t/** camera name */\n\tname: string;\n\t/** folder id, e.g. cam_8_Reolink */\n\tfid: string;\n}\n\n/**\n * Finds a camera by folder id (cam_8_Reolink), oid (8 / \"8\") or name (case-insensitive).\n *\n * @param query value from the message\n * @param cams known cameras\n */\nexport function findCamera(query: unknown, cams: CamRef[]): CamRef | undefined {\n\tif (query === undefined || query === null || query === '') {\n\t\treturn undefined;\n\t}\n\tconst q = (typeof query === 'number' ? String(query) : typeof query === 'string' ? query : '').trim();\n\tconst ql = q.toLowerCase();\n\treturn (\n\t\tcams.find(c => c.fid === q) ||\n\t\tcams.find(c => String(c.oid) === q) ||\n\t\tcams.find(c => c.name.toLowerCase() === ql) ||\n\t\tcams.find(c => q.endsWith(`.${c.fid}`))\n\t);\n}\n\n// ---- message bus guard ----\n\n/** Metadata answered by sendRecording / getRecording \u2014 never the video data itself */\nexport interface ProvidedRecording {\n\t/** recording is available */\n\tok: boolean;\n\t/** error text */\n\terror?: string;\n\t/** file name for the receiver, e.g. 8_2026-11-12_15-55-29_931.mp4 */\n\tfileName?: string;\n\t/** 'mp4' or 'mkv' */\n\tformat?: string;\n\t/** mime type */\n\tmime?: string;\n\t/** size in bytes */\n\tsize?: number;\n\t/** iobfile:// URI of the file in the adapter's file storage */\n\turi?: string;\n\t/** http(s) URL via the web instance ('' without one) */\n\turl?: string;\n\t/** absolute path on the ioBroker host ('' if the file storage is not on the local disk) */\n\tfile?: string;\n}\n\n/** Largest message the adapter puts on the message bus (sendTo answers and forwards) */\nexport const MAX_MESSAGE_BYTES = 64 * 1024;\n\n/**\n * True if the value contains binary data: a Buffer, a typed array / ArrayBuffer or a\n * JSON-serialized Buffer ({ type: 'Buffer', data: [...] }).\n *\n * @param value value to check\n * @param depth recursion depth\n */\nexport function containsBinary(value: unknown, depth = 0): boolean {\n\tif (value === null || typeof value !== 'object') {\n\t\treturn false;\n\t}\n\tif (depth > 20) {\n\t\treturn true;\n\t}\n\tif (Buffer.isBuffer(value) || ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {\n\t\treturn true;\n\t}\n\tconst o = value as Record<string, unknown>;\n\tif (o.type === 'Buffer' && Array.isArray(o.data)) {\n\t\treturn true;\n\t}\n\tconst children = Array.isArray(value) ? (value as unknown[]) : Object.values(o);\n\treturn children.some(v => containsBinary(v, depth + 1));\n}\n\n/**\n * Throws if a message for the message bus contains binary data or is too large.\n *\n * @param value message\n */\nexport function assertNoBinary(value: unknown): void {\n\tif (containsBinary(value)) {\n\t\tthrow new Error('refusing to put binary data on the ioBroker message bus');\n\t}\n\tconst len = Buffer.byteLength(JSON.stringify(value ?? null));\n\tif (len > MAX_MESSAGE_BYTES) {\n\t\tthrow new Error(`refusing to put ${len} bytes on the ioBroker message bus`);\n\t}\n}\n\n/**\n * Returns the message if it is safe for the message bus, otherwise a small error answer.\n *\n * @param value message\n */\nexport function safeMessage<T>(value: T): T | { ok: false; error: string } {\n\ttry {\n\t\tassertNoBinary(value);\n\t\treturn value;\n\t} catch (e) {\n\t\treturn { ok: false, error: (e as Error).message };\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,gCAAsB;AACtB,SAAoB;AACpB,WAAsB;AACtB,WAAsB;AAGf,MAAM,qBAAqB,KAAK,OAAO;AAEvC,MAAM,KAAK,OAAO;AAoBlB,SAAS,YAAY,KAAc,KAAa,KAAa,KAAqB;AACxF,QAAM,IAAI,OAAO,QAAQ,WAAW,MAAM,WAAW,OAAO,QAAQ,WAAW,MAAM,EAAE;AACvF,MAAI,CAAC,OAAO,SAAS,CAAC,GAAG;AACxB,WAAO;AAAA,EACR;AACA,SAAO,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC;AAClD;AAOO,SAAS,eAAe,KAAsB;AACpD,SAAO,YAAY,KAAK,GAAG,GAAG,CAAC;AAChC;AAOO,SAAS,kBAAkB,OAAwB;AACz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,YAAY,OAAO,KAAK,KAAK,iBAAiB,aAAa;AACxF,WAAO;AAAA,EACR;AACA,QAAM,IAAI;AACV,MAAI,EAAE,SAAS,YAAY,MAAM,QAAQ,EAAE,IAAI,GAAG;AACjD,WAAO;AAAA,EACR;AACA,QAAM,WAAW,MAAM,QAAQ,KAAK,IAAK,QAAsB,OAAO,OAAO,CAAC;AAC9E,SAAO,SAAS,KAAK,OAAK,eAAe,GAAG,QAAQ,CAAC,CAAC;AACvD;AAOO,SAAS,eAAe,OAAsB;AACpD,MAAI,eAAe,KAAK,GAAG;AAC1B,UAAM,IAAI,MAAM,yDAAyD;AAAA,EAC1E;AACA,QAAM,MAAM,OAAO,WAAW,KAAK,UAAU,wBAAS,IAAI,CAAC;AAC3D,MAAI,MAAM,mBAAmB;AAC5B,UAAM,IAAI,MAAM,mBAAmB,GAAG,oCAAoC;AAAA,EAC3E;AACD;AAOO,SAAS,YAAe,OAA4C;AAC1E,MAAI;AACH,mBAAe,KAAK;AACpB,WAAO;AAAA,EACR,SAAS,GAAG;AACX,WAAO,EAAE,IAAI,OAAO,OAAQ,EAAY,QAAQ;AAAA,EACjD;AACD;",
|
|
4
|
+
"sourcesContent": ["// Helpers for \"recordings in the ioBroker file storage\" and sendRecording/getRecording:\n// ffmpeg detection, in-memory MKV -> MP4 remux, size limits, file names, URIs and URLs.\n// Kept free of adapter state so they can be unit tested.\n\nimport { spawn } from 'node:child_process';\nimport * as fs from 'node:fs';\nimport * as http from 'node:http';\nimport * as path from 'node:path';\n\n/** Telegram bots can upload at most 50 MB per file */\nexport const TELEGRAM_MAX_BYTES = 50 * 1024 * 1024;\n\nexport const MB = 1024 * 1024;\n\n/** Result of the ffmpeg detection */\nexport interface FfmpegInfo {\n\t/** true if a working ffmpeg was found */\n\tfound: boolean;\n\t/** ffmpeg version, e.g. 6.1.1 */\n\tversion: string;\n\t/** binary that answered */\n\tpath: string;\n}\n\n/**\n * Clamps a configured number into [min, max]; non-numbers fall back to the default.\n *\n * @param raw configured value\n * @param def default value\n * @param min lower bound\n * @param max upper bound\n */\nexport function clampNumber(raw: unknown, def: number, min: number, max: number): number {\n\tconst n = typeof raw === 'number' ? raw : parseFloat(typeof raw === 'string' ? raw : '');\n\tif (!Number.isFinite(n)) {\n\t\treturn def;\n\t}\n\treturn Math.max(min, Math.min(max, Math.round(n)));\n}\n\n/**\n * Number of kept recordings per camera (1..3, default 1).\n *\n * @param raw configured value\n */\nexport function recordingSlots(raw: unknown): number {\n\treturn clampNumber(raw, 1, 1, 3);\n}\n\n/**\n * Maximum recording size in bytes (configured in MB, 1..2000, default 50).\n *\n * @param rawMb configured value in MB\n */\nexport function maxRecordingBytes(rawMb: unknown): number {\n\treturn clampNumber(rawMb, 50, 1, 2000) * MB;\n}\n\n/**\n * Size check result for a recording against a byte limit.\n *\n * @param bytes size of the recording (0/NaN = unknown \u2192 allowed)\n * @param limit maximum in bytes\n */\nexport function exceedsLimit(bytes: number, limit: number): boolean {\n\treturn Number.isFinite(bytes) && bytes > 0 && bytes > limit;\n}\n\n/**\n * Human readable MB value with one decimal.\n *\n * @param bytes size in bytes\n */\nexport function fmtMb(bytes: number): string {\n\treturn `${(Math.round((bytes / MB) * 10) / 10).toFixed(1)} MB`;\n}\n\n/**\n * File name of a stored recording slot inside the camera folder.\n *\n * @param slot slot number (1 = newest)\n * @param ext 'mp4' or 'mkv'\n */\nexport function recordingFileName(slot: number, ext: string): string {\n\treturn `rec${slot}.${ext}`;\n}\n\n/**\n * Path of a stored recording inside the adapter's file storage (meta object = namespace).\n *\n * @param fid camera folder id, e.g. cam_8_Reolink\n * @param slot slot number\n * @param ext file extension\n */\nexport function recordingStoragePath(fid: string, slot: number, ext: string): string {\n\treturn `${fid}/${recordingFileName(slot, ext)}`;\n}\n\n/**\n * Fixed per-camera file used by sendRecording/getRecording for recordings that are not in a slot.\n *\n * @param fid camera folder id\n * @param ext file extension\n */\nexport function sendFileStoragePath(fid: string, ext: string): string {\n\treturn `${fid}/send.${ext}`;\n}\n\n/**\n * All recording files a camera can have in the file storage (slots and the send file).\n */\nexport function cameraRecordingFiles(): string[] {\n\tconst out: string[] = [];\n\tfor (const ext of ['mp4', 'mkv']) {\n\t\tfor (let i = 1; i <= 3; i++) {\n\t\t\tout.push(`rec${i}.${ext}`);\n\t\t}\n\t\tout.push(`send.${ext}`);\n\t}\n\treturn out;\n}\n\n/**\n * True if the current last recording should be stored on start: slot 1 empty or holding another recording.\n *\n * @param slot1Exists slot 1 file exists\n * @param name1 value of recordings.name1\n * @param lastFn file name of the newest recording in AgentDVR\n */\nexport function needsInitialFill(slot1Exists: boolean, name1: unknown, lastFn: string): boolean {\n\tif (!lastFn) {\n\t\treturn false;\n\t}\n\treturn !slot1Exists || name1 !== lastFn;\n}\n\n/**\n * ioBroker file URI resolved by telegram >= 6 (same format as the alert photos).\n *\n * @param namespace adapter namespace (meta object id), e.g. agent-dvr.0\n * @param fid camera folder id\n * @param slot slot number\n * @param ext file extension\n */\nexport function recordingUri(namespace: string, fid: string, slot: number, ext: string): string {\n\treturn `iobfile://${namespace}/${recordingStoragePath(fid, slot, ext)}`;\n}\n\n/**\n * Absolute path where a file-based objects DB keeps the file (<dataDir>/files/<metaId>/<path>).\n *\n * @param dataDir ioBroker data directory (utils.getAbsoluteDefaultDataDir())\n * @param namespace meta object id\n * @param fid camera folder id\n * @param slot slot number\n * @param ext file extension\n */\nexport function recordingAbsPath(dataDir: string, namespace: string, fid: string, slot: number, ext: string): string {\n\treturn path.join(dataDir, 'files', namespace, fid, recordingFileName(slot, ext));\n}\n\n/**\n * http(s) URL via the web extension, empty without a web instance.\n *\n * @param webBase base URL of the web instance, e.g. http://192.168.1.10:8082\n * @param namespace adapter namespace\n * @param fid camera folder id\n * @param slot slot number\n * @param ext file extension\n */\nexport function recordingUrl(webBase: string, namespace: string, fid: string, slot: number, ext: string): string {\n\treturn webBase ? `${webBase}/${namespace}/recordings/${fid}/${recordingFileName(slot, ext)}` : '';\n}\n\n/**\n * Extension of an AgentDVR recording file name ('mkv' when unknown).\n *\n * @param fn file name, e.g. 8_2026-11-12_15-55-29_931.mkv\n */\nexport function extOf(fn: string): string {\n\tconst m = /\\.([A-Za-z0-9]+)$/.exec(fn || '');\n\treturn m ? m[1].toLowerCase() : 'mkv';\n}\n\n/**\n * Mime type for a recording extension.\n *\n * @param ext file extension\n */\nexport function mimeOf(ext: string): string {\n\treturn ext === 'mp4' ? 'video/mp4' : ext === 'mkv' ? 'video/x-matroska' : 'application/octet-stream';\n}\n\n/**\n * Only plain AgentDVR recording file names are accepted (no paths).\n *\n * @param fn requested file name\n */\nexport function isValidRecordingName(fn: string): boolean {\n\treturn /^[\\w.-]{1,200}\\.(mkv|mp4)$/i.test(fn) && !fn.includes('..');\n}\n\n// ---- ffmpeg detection ----\n\n/**\n * Ordered list of ffmpeg binaries to try: configured path, PATH lookup, common locations.\n *\n * @param configPath configured path (empty = auto)\n * @param platform process.platform\n */\nexport function ffmpegCandidates(configPath: string, platform: string): string[] {\n\tconst out: string[] = [];\n\tconst add = (p: string | undefined): void => {\n\t\tconst v = (p || '').trim();\n\t\tif (v && !out.includes(v)) {\n\t\t\tout.push(v);\n\t\t}\n\t};\n\tadd(configPath);\n\tadd('ffmpeg');\n\tif (platform === 'win32') {\n\t\tadd('C:\\\\ffmpeg\\\\bin\\\\ffmpeg.exe');\n\t\tadd('C:\\\\Program Files\\\\ffmpeg\\\\bin\\\\ffmpeg.exe');\n\t} else {\n\t\tadd('/usr/bin/ffmpeg');\n\t\tadd('/usr/local/bin/ffmpeg');\n\t\tadd('/opt/homebrew/bin/ffmpeg');\n\t}\n\treturn out;\n}\n\n/**\n * Absolute path of a bare binary name (for display): looked up in the usual binary folders,\n * otherwise the name itself (it was found via the search path of the system).\n *\n * @param bin binary name or path\n * @param platform process.platform\n * @param exists file check (injectable for tests)\n */\nexport function resolveOnPath(\n\tbin: string,\n\tplatform: string,\n\texists: (p: string) => boolean = p => fs.existsSync(p),\n): string {\n\tif (/[\\\\/]/.test(bin)) {\n\t\treturn bin;\n\t}\n\tconst win = platform === 'win32';\n\tconst pathMod = win ? path.win32 : path.posix;\n\tconst dirs = win\n\t\t? ['C:\\\\ffmpeg\\\\bin', 'C:\\\\Program Files\\\\ffmpeg\\\\bin']\n\t\t: ['/usr/bin', '/usr/local/bin', '/opt/homebrew/bin', '/bin'];\n\tconst names = win && !/\\.exe$/i.test(bin) ? [`${bin}.exe`, bin] : [bin];\n\tfor (const d of dirs) {\n\t\tfor (const n of names) {\n\t\t\tconst full = pathMod.join(d, n);\n\t\t\tif (exists(full)) {\n\t\t\t\treturn full;\n\t\t\t}\n\t\t}\n\t}\n\treturn bin;\n}\n\n/**\n * Version from `ffmpeg -version` output, e.g. \"6.1.1\" from \"ffmpeg version 6.1.1-3ubuntu5 Copyright ...\".\n *\n * @param out stdout of ffmpeg -version\n */\nexport function parseFfmpegVersion(out: string): string {\n\tconst m = /ffmpeg version\\s+(\\S+)/i.exec(out || '');\n\tif (!m) {\n\t\treturn '';\n\t}\n\tconst v = /^n?(\\d+(?:\\.\\d+)*)/.exec(m[1]);\n\treturn v ? v[1] : m[1];\n}\n\n/**\n * Runs `<bin> -version` and returns the version, or '' if it is not a working ffmpeg.\n *\n * @param bin binary name or path\n * @param timeoutMs timeout\n */\nexport function probeFfmpeg(bin: string, timeoutMs = 5000): Promise<string> {\n\treturn new Promise(resolve => {\n\t\tlet out = '';\n\t\tlet done = false;\n\t\tconst timer: { id?: NodeJS.Timeout } = {};\n\t\tconst finish = (v: string): void => {\n\t\t\tif (!done) {\n\t\t\t\tdone = true;\n\t\t\t\tclearTimeout(timer.id);\n\t\t\t\tresolve(v);\n\t\t\t}\n\t\t};\n\t\tlet child: ReturnType<typeof spawn>;\n\t\ttry {\n\t\t\tchild = spawn(bin, ['-version'], { shell: false, windowsHide: true });\n\t\t} catch {\n\t\t\tresolve('');\n\t\t\treturn;\n\t\t}\n\t\ttimer.id = setTimeout(() => {\n\t\t\ttry {\n\t\t\t\tchild.kill('SIGKILL');\n\t\t\t} catch {\n\t\t\t\t/* ignore */\n\t\t\t}\n\t\t\tfinish('');\n\t\t}, timeoutMs);\n\t\tchild.stdout?.on('data', (c: Buffer) => {\n\t\t\tif (out.length < 4096) {\n\t\t\t\tout += c.toString();\n\t\t\t}\n\t\t});\n\t\tchild.on('error', () => finish(''));\n\t\tchild.on('close', code => finish(code === 0 ? parseFfmpegVersion(out) : ''));\n\t});\n}\n\n/**\n * Tries the candidates in order and returns the first working ffmpeg.\n *\n * @param candidates binaries in priority order\n * @param probe returns the version or '' (injectable for tests)\n */\nexport async function detectFfmpeg(\n\tcandidates: string[],\n\tprobe: (bin: string) => Promise<string> = b => probeFfmpeg(b),\n): Promise<FfmpegInfo> {\n\tfor (const c of candidates) {\n\t\tconst version = await probe(c);\n\t\tif (version) {\n\t\t\treturn { found: true, version, path: c };\n\t\t}\n\t}\n\treturn { found: false, version: '', path: '' };\n}\n\n/**\n * Text for info.ffmpeg.\n *\n * @param info detection result\n */\nexport function ffmpegStatusText(info: FfmpegInfo): string {\n\treturn info.found ? `${info.version} (${info.path})` : 'not found';\n}\n\n/**\n * AgentDVR lists a recording in getEvents while it is still being written. A recording counts as\n * finished when the camera no longer records and the listed size did not change since the last check.\n *\n * @param prevSize listed size at the previous check (-1 before the first check)\n * @param size listed size now\n * @param recording true while the camera records\n */\nexport function recordingFinished(prevSize: number, size: number, recording: boolean): boolean {\n\treturn !recording && size > 0 && size === prevSize;\n}\n\n/** Picture size and length of a video file */\nexport interface VideoInfo {\n\t/** width in pixels (0 = unknown) */\n\twidth: number;\n\t/** height in pixels (0 = unknown) */\n\theight: number;\n\t/** duration in whole seconds (0 = unknown) */\n\tduration: number;\n}\n\ninterface Box {\n\ttype: string;\n\tstart: number;\n\tend: number;\n}\n\nfunction* mp4Boxes(buf: Buffer, from: number, to: number): Generator<Box> {\n\tlet p = from;\n\twhile (p + 8 <= to) {\n\t\tlet size = buf.readUInt32BE(p);\n\t\tconst type = buf.toString('latin1', p + 4, p + 8);\n\t\tlet head = 8;\n\t\tif (size === 1) {\n\t\t\tif (p + 16 > to) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsize = Number(buf.readBigUInt64BE(p + 8));\n\t\t\thead = 16;\n\t\t} else if (size === 0) {\n\t\t\tsize = to - p;\n\t\t}\n\t\tif (size < head) {\n\t\t\treturn;\n\t\t}\n\t\tyield { type, start: p + head, end: Math.min(p + size, to) };\n\t\tp += size;\n\t}\n}\n\nfunction mp4Child(buf: Buffer, parent: Box, type: string): Box | undefined {\n\tfor (const b of mp4Boxes(buf, parent.start, parent.end)) {\n\t\tif (b.type === type) {\n\t\t\treturn b;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction mp4Info(buf: Buffer): VideoInfo {\n\tconst info: VideoInfo = { width: 0, height: 0, duration: 0 };\n\tconst top = [...mp4Boxes(buf, 0, buf.length)];\n\tconst moov = top.find(b => b.type === 'moov');\n\tif (!moov) {\n\t\treturn info;\n\t}\n\t// video track: tkhd width/height (16.16), mdhd timescale\n\tlet videoId = 0;\n\tlet videoScale = 0;\n\tfor (const trak of mp4Boxes(buf, moov.start, moov.end)) {\n\t\tif (trak.type !== 'trak') {\n\t\t\tcontinue;\n\t\t}\n\t\tconst tkhd = mp4Child(buf, trak, 'tkhd');\n\t\tif (!tkhd || tkhd.end - tkhd.start < 84) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst w = buf.readUInt32BE(tkhd.end - 8) / 65536;\n\t\tconst h = buf.readUInt32BE(tkhd.end - 4) / 65536;\n\t\tif (w > 0 && h > 0) {\n\t\t\tconst v1 = buf[tkhd.start] === 1;\n\t\t\tvideoId = buf.readUInt32BE(tkhd.start + (v1 ? 20 : 12));\n\t\t\tinfo.width = Math.round(w);\n\t\t\tinfo.height = Math.round(h);\n\t\t\tconst mdia = mp4Child(buf, trak, 'mdia');\n\t\t\tconst mdhd = mdia && mp4Child(buf, mdia, 'mdhd');\n\t\t\tif (mdhd) {\n\t\t\t\tvideoScale = buf.readUInt32BE(mdhd.start + (buf[mdhd.start] === 1 ? 20 : 12));\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t}\n\t// duration: mvhd (normal MP4), else mehd, else the end of the last fragment of the video track\n\tconst mvhd = mp4Child(buf, moov, 'mvhd');\n\tif (mvhd) {\n\t\tconst v1 = buf[mvhd.start] === 1;\n\t\tconst scale = buf.readUInt32BE(mvhd.start + (v1 ? 20 : 12));\n\t\tconst dur = v1 ? Number(buf.readBigUInt64BE(mvhd.start + 24)) : buf.readUInt32BE(mvhd.start + 16);\n\t\tif (scale > 0 && dur > 0) {\n\t\t\tinfo.duration = Math.round(dur / scale);\n\t\t}\n\t}\n\tif (!info.duration && videoId && videoScale) {\n\t\tlet end = 0;\n\t\tfor (const moof of top) {\n\t\t\tif (moof.type !== 'moof') {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (const traf of mp4Boxes(buf, moof.start, moof.end)) {\n\t\t\t\tif (traf.type !== 'traf') {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst tfhd = mp4Child(buf, traf, 'tfhd');\n\t\t\t\tif (!tfhd || buf.readUInt32BE(tfhd.start + 4) !== videoId) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst tfFlags = buf.readUInt32BE(tfhd.start) & 0xffffff;\n\t\t\t\tlet q = tfhd.start + 8;\n\t\t\t\tif (tfFlags & 0x1) {\n\t\t\t\t\tq += 8;\n\t\t\t\t}\n\t\t\t\tif (tfFlags & 0x2) {\n\t\t\t\t\tq += 4;\n\t\t\t\t}\n\t\t\t\tconst defDur = tfFlags & 0x8 ? buf.readUInt32BE(q) : 0;\n\t\t\t\tconst tfdt = mp4Child(buf, traf, 'tfdt');\n\t\t\t\tlet t = 0;\n\t\t\t\tif (tfdt) {\n\t\t\t\t\tt =\n\t\t\t\t\t\tbuf[tfdt.start] === 1\n\t\t\t\t\t\t\t? Number(buf.readBigUInt64BE(tfdt.start + 4))\n\t\t\t\t\t\t\t: buf.readUInt32BE(tfdt.start + 4);\n\t\t\t\t}\n\t\t\t\tfor (const trun of mp4Boxes(buf, traf.start, traf.end)) {\n\t\t\t\t\tif (trun.type !== 'trun') {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tconst flags = buf.readUInt32BE(trun.start) & 0xffffff;\n\t\t\t\t\tconst count = buf.readUInt32BE(trun.start + 4);\n\t\t\t\t\tlet r = trun.start + 8 + (flags & 0x1 ? 4 : 0) + (flags & 0x4 ? 4 : 0);\n\t\t\t\t\tconst per =\n\t\t\t\t\t\t(flags & 0x100 ? 4 : 0) +\n\t\t\t\t\t\t(flags & 0x200 ? 4 : 0) +\n\t\t\t\t\t\t(flags & 0x400 ? 4 : 0) +\n\t\t\t\t\t\t(flags & 0x800 ? 4 : 0);\n\t\t\t\t\tfor (let i = 0; i < count && r + per <= trun.end; i++) {\n\t\t\t\t\t\tt += flags & 0x100 ? buf.readUInt32BE(r) : defDur;\n\t\t\t\t\t\tr += per;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tend = Math.max(end, t);\n\t\t\t}\n\t\t}\n\t\tif (end > 0) {\n\t\t\tinfo.duration = Math.round(end / videoScale);\n\t\t}\n\t}\n\treturn info;\n}\n\nfunction ebmlVint(buf: Buffer, p: number, keepMarker: boolean): { val: number; len: number; unknown: boolean } | null {\n\tif (p >= buf.length) {\n\t\treturn null;\n\t}\n\tconst first = buf[p];\n\tlet len = 1;\n\twhile (len <= 8 && !(first & (0x80 >> (len - 1)))) {\n\t\tlen++;\n\t}\n\tif (len > 8 || p + len > buf.length) {\n\t\treturn null;\n\t}\n\tlet val = keepMarker ? first : first & (0xff >> len);\n\tlet allOnes = (first & (0xff >> len)) === 0xff >> len;\n\tfor (let i = 1; i < len; i++) {\n\t\tval = val * 256 + buf[p + i];\n\t\tif (buf[p + i] !== 0xff) {\n\t\t\tallOnes = false;\n\t\t}\n\t}\n\treturn { val, len, unknown: allOnes };\n}\n\nfunction mkvInfo(buf: Buffer): VideoInfo {\n\tconst info: VideoInfo = { width: 0, height: 0, duration: 0 };\n\tlet scale = 1000000;\n\tlet durTicks = 0;\n\tconst MASTER = new Set([0x18538067, 0x1549a966, 0x1654ae6b, 0xae, 0xe0]);\n\tconst walk = (from: number, to: number, depth: number): void => {\n\t\tlet p = from;\n\t\twhile (p < to && depth < 6) {\n\t\t\tconst id = ebmlVint(buf, p, true);\n\t\t\tconst size = id && ebmlVint(buf, p + id.len, false);\n\t\t\tif (!id || !size) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst start = p + id.len + size.len;\n\t\t\tconst end = size.unknown ? to : Math.min(start + size.val, to);\n\t\t\tif (id.val === 0x1f43b675) {\n\t\t\t\treturn; // first Cluster: all header data is before it\n\t\t\t}\n\t\t\tif (MASTER.has(id.val)) {\n\t\t\t\twalk(start, end, depth + 1);\n\t\t\t} else if (id.val === 0xb0 || id.val === 0xba || id.val === 0x2ad7b1) {\n\t\t\t\tlet v = 0;\n\t\t\t\tfor (let i = start; i < end; i++) {\n\t\t\t\t\tv = v * 256 + buf[i];\n\t\t\t\t}\n\t\t\t\tif (id.val === 0xb0 && !info.width) {\n\t\t\t\t\tinfo.width = v;\n\t\t\t\t} else if (id.val === 0xba && !info.height) {\n\t\t\t\t\tinfo.height = v;\n\t\t\t\t} else if (id.val === 0x2ad7b1) {\n\t\t\t\t\tscale = v;\n\t\t\t\t}\n\t\t\t} else if (id.val === 0x4489) {\n\t\t\t\tdurTicks = end - start === 8 ? buf.readDoubleBE(start) : end - start === 4 ? buf.readFloatBE(start) : 0;\n\t\t\t}\n\t\t\tif (size.unknown) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tp = end;\n\t\t}\n\t};\n\twalk(0, buf.length, 0);\n\tif (durTicks > 0) {\n\t\tinfo.duration = Math.round((durTicks * scale) / 1e9);\n\t}\n\treturn info;\n}\n\n/**\n * Width, height and duration from the headers of an MP4 (also fragmented) or MKV file. Unknown values are 0.\n * Telegram does not read them itself from larger bot uploads and then shows the video in a wrong\n * aspect ratio in the chat, so sendRecording passes them on.\n *\n * @param buf the whole file\n * @param format 'mp4' or 'mkv'\n */\nexport function videoInfo(buf: Buffer, format: string): VideoInfo {\n\ttry {\n\t\treturn format === 'mkv' ? mkvInfo(buf) : mp4Info(buf);\n\t} catch {\n\t\treturn { width: 0, height: 0, duration: 0 };\n\t}\n}\n\n// ---- remux ----\n\n/**\n * True if the Matroska header announces an HEVC video track (needs the hvc1 tag in MP4 for Apple/Telegram).\n *\n * @param buf MKV data\n */\nexport function isHevcMkv(buf: Buffer): boolean {\n\treturn buf.subarray(0, 256 * 1024).includes('V_MPEGH/ISO/HEVC');\n}\n\n/**\n * ffmpeg arguments for a lossless MKV \u2192 fragmented MP4 remux via stdin/stdout.\n *\n * @param hevc tag the video track as hvc1\n * @param dropAudio leave out the audio track\n */\nexport function remuxArgs(hevc: boolean, dropAudio: boolean): string[] {\n\tconst args = ['-hide_banner', '-loglevel', 'error', '-i', 'pipe:0', '-map', '0:v:0'];\n\tif (!dropAudio) {\n\t\targs.push('-map', '0:a?');\n\t}\n\targs.push('-c', 'copy');\n\tif (hevc) {\n\t\targs.push('-tag:v', 'hvc1');\n\t}\n\tif (dropAudio) {\n\t\targs.push('-an');\n\t}\n\targs.push('-movflags', 'frag_keyframe+empty_moov', '-f', 'mp4', 'pipe:1');\n\treturn args;\n}\n\n/**\n * Runs ffmpeg once with the input on stdin and collects stdout.\n *\n * @param bin ffmpeg binary\n * @param input input data\n * @param args ffmpeg arguments\n * @param timeoutMs timeout\n * @param maxBytes abort when the output gets larger\n */\nexport function runFfmpeg(\n\tbin: string,\n\tinput: Buffer,\n\targs: string[],\n\ttimeoutMs: number,\n\tmaxBytes: number,\n): Promise<Buffer> {\n\treturn new Promise((resolve, reject) => {\n\t\tlet done = false;\n\t\tconst timer: { id?: NodeJS.Timeout } = {};\n\t\tconst chunks: Buffer[] = [];\n\t\tlet size = 0;\n\t\tlet err = '';\n\t\tconst child = spawn(bin, args, { shell: false, windowsHide: true });\n\t\tconst fail = (e: Error): void => {\n\t\t\tif (!done) {\n\t\t\t\tdone = true;\n\t\t\t\tclearTimeout(timer.id);\n\t\t\t\ttry {\n\t\t\t\t\tchild.kill('SIGKILL');\n\t\t\t\t} catch {\n\t\t\t\t\t/* ignore */\n\t\t\t\t}\n\t\t\t\treject(e);\n\t\t\t}\n\t\t};\n\t\ttimer.id = setTimeout(\n\t\t\t() => fail(new Error(`ffmpeg timeout after ${Math.round(timeoutMs / 1000)} s`)),\n\t\t\ttimeoutMs,\n\t\t);\n\t\tchild.stdout.on('data', (c: Buffer) => {\n\t\t\tsize += c.length;\n\t\t\tif (size > maxBytes) {\n\t\t\t\tfail(new Error(`MP4 larger than ${fmtMb(maxBytes)}`));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tchunks.push(c);\n\t\t});\n\t\tchild.stderr.on('data', (c: Buffer) => {\n\t\t\tif (err.length < 2000) {\n\t\t\t\terr += c.toString();\n\t\t\t}\n\t\t});\n\t\tchild.on('error', e => fail(e));\n\t\tchild.on('close', code => {\n\t\t\tif (done) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdone = true;\n\t\t\tclearTimeout(timer.id);\n\t\t\tif (code === 0 && size > 0) {\n\t\t\t\tresolve(Buffer.concat(chunks));\n\t\t\t} else {\n\t\t\t\treject(new Error(`ffmpeg exit code ${code}: ${err.trim().split('\\n').pop() || 'no output'}`));\n\t\t\t}\n\t\t});\n\t\t// EPIPE when ffmpeg stops reading early \u2014 the close handler reports the real error\n\t\tchild.stdin.on('error', () => {});\n\t\tchild.stdin.end(input);\n\t});\n}\n\n/**\n * Remuxes MKV to MP4 without re-encoding. Retries without audio if the audio codec can't go into MP4.\n *\n * @param bin ffmpeg binary\n * @param mkv input data\n * @param timeoutMs timeout per run\n * @param maxBytes output limit\n * @param onAudioDropped called when the retry without audio was needed\n * @param run ffmpeg runner (injectable for tests)\n */\nexport async function remuxToMp4(\n\tbin: string,\n\tmkv: Buffer,\n\ttimeoutMs: number,\n\tmaxBytes: number,\n\tonAudioDropped?: (reason: string) => void,\n\trun: typeof runFfmpeg = runFfmpeg,\n): Promise<Buffer> {\n\tconst hevc = isHevcMkv(mkv);\n\ttry {\n\t\treturn await run(bin, mkv, remuxArgs(hevc, false), timeoutMs, maxBytes);\n\t} catch (e) {\n\t\tconst msg = (e as Error).message;\n\t\tif (/timeout|larger than|ENOENT|Invalid data|Error opening input/i.test(msg)) {\n\t\t\tthrow e;\n\t\t}\n\t\tconst out = await run(bin, mkv, remuxArgs(hevc, true), timeoutMs, maxBytes);\n\t\tonAudioDropped?.(msg);\n\t\treturn out;\n\t}\n}\n\n// ---- download ----\n\n/** Result of a download into memory */\nexport interface DownloadResult {\n\t/** download complete */\n\tok: boolean;\n\t/** downloaded bytes */\n\tdata?: Buffer;\n\t/** error text */\n\terror?: string;\n\t/** true when the download was stopped because of the size limit */\n\ttooLarge?: boolean;\n\t/** received or announced size in bytes */\n\tsize?: number;\n}\n\n/**\n * GET into memory with timeout and size limit (Content-Length checked first, then the received bytes).\n *\n * @param opts request options (hostname, port, path, headers)\n * @param maxBytes size limit\n * @param timeoutMs overall timeout\n */\nexport function downloadToBuffer(\n\topts: http.RequestOptions,\n\tmaxBytes: number,\n\ttimeoutMs: number,\n): Promise<DownloadResult> {\n\treturn new Promise(resolve => {\n\t\tlet done = false;\n\t\tconst timer: { id?: NodeJS.Timeout } = {};\n\t\tlet req: http.ClientRequest | undefined;\n\t\tconst finish = (r: DownloadResult): void => {\n\t\t\tif (!done) {\n\t\t\t\tdone = true;\n\t\t\t\tclearTimeout(timer.id);\n\t\t\t\tresolve(r);\n\t\t\t}\n\t\t};\n\t\ttimer.id = setTimeout(() => {\n\t\t\treq?.destroy();\n\t\t\tfinish({ ok: false, error: `timeout after ${Math.round(timeoutMs / 1000)} s` });\n\t\t}, timeoutMs);\n\t\ttry {\n\t\t\treq = http.request({ ...opts, method: 'GET' }, res => {\n\t\t\t\tif (res.statusCode && res.statusCode >= 400) {\n\t\t\t\t\tres.resume();\n\t\t\t\t\tfinish({ ok: false, error: `HTTP ${res.statusCode}` });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst len = parseInt(String(res.headers['content-length'] ?? ''), 10);\n\t\t\t\tif (exceedsLimit(len, maxBytes)) {\n\t\t\t\t\treq?.destroy();\n\t\t\t\t\tfinish({ ok: false, tooLarge: true, size: len, error: `${fmtMb(len)} > limit ${fmtMb(maxBytes)}` });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst chunks: Buffer[] = [];\n\t\t\t\tlet size = 0;\n\t\t\t\tres.on('data', (c: Buffer) => {\n\t\t\t\t\tsize += c.length;\n\t\t\t\t\tif (size > maxBytes) {\n\t\t\t\t\t\treq?.destroy();\n\t\t\t\t\t\tfinish({ ok: false, tooLarge: true, size, error: `more than ${fmtMb(maxBytes)}` });\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tchunks.push(c);\n\t\t\t\t});\n\t\t\t\tres.on('end', () => finish({ ok: true, data: Buffer.concat(chunks), size }));\n\t\t\t\tres.on('error', (e: Error) => finish({ ok: false, error: e.message }));\n\t\t\t});\n\t\t\treq.on('error', (e: Error) => finish({ ok: false, error: e.message }));\n\t\t\treq.end();\n\t\t} catch (e) {\n\t\t\tfinish({ ok: false, error: (e as Error).message });\n\t\t}\n\t});\n}\n\n// ---- camera lookup for sendTo ----\n\n/** Camera reference for findCamera */\nexport interface CamRef {\n\t/** AgentDVR object id */\n\toid: number | string;\n\t/** camera name */\n\tname: string;\n\t/** folder id, e.g. cam_8_Reolink */\n\tfid: string;\n}\n\n/**\n * Finds a camera by folder id (cam_8_Reolink), oid (8 / \"8\") or name (case-insensitive).\n *\n * @param query value from the message\n * @param cams known cameras\n */\nexport function findCamera(query: unknown, cams: CamRef[]): CamRef | undefined {\n\tif (query === undefined || query === null || query === '') {\n\t\treturn undefined;\n\t}\n\tconst q = (typeof query === 'number' ? String(query) : typeof query === 'string' ? query : '').trim();\n\tconst ql = q.toLowerCase();\n\treturn (\n\t\tcams.find(c => c.fid === q) ||\n\t\tcams.find(c => String(c.oid) === q) ||\n\t\tcams.find(c => c.name.toLowerCase() === ql) ||\n\t\tcams.find(c => q.endsWith(`.${c.fid}`))\n\t);\n}\n\n// ---- message bus guard ----\n\n/** Metadata answered by sendRecording / getRecording \u2014 never the video data itself */\nexport interface ProvidedRecording {\n\t/** recording is available */\n\tok: boolean;\n\t/** error text */\n\terror?: string;\n\t/** file name for the receiver, e.g. 8_2026-11-12_15-55-29_931.mp4 */\n\tfileName?: string;\n\t/** 'mp4' or 'mkv' */\n\tformat?: string;\n\t/** mime type */\n\tmime?: string;\n\t/** size in bytes */\n\tsize?: number;\n\t/** iobfile:// URI of the file in the adapter's file storage */\n\turi?: string;\n\t/** http(s) URL via the web instance ('' without one) */\n\turl?: string;\n\t/** absolute path on the ioBroker host ('' if the file storage is not on the local disk) */\n\tfile?: string;\n\t/** video width in pixels (0 = unknown) */\n\twidth?: number;\n\t/** video height in pixels (0 = unknown) */\n\theight?: number;\n\t/** duration in seconds (0 = unknown) */\n\tduration?: number;\n}\n\n/** Largest message the adapter puts on the message bus (sendTo answers and forwards) */\nexport const MAX_MESSAGE_BYTES = 64 * 1024;\n\n/**\n * True if the value contains binary data: a Buffer, a typed array / ArrayBuffer or a\n * JSON-serialized Buffer ({ type: 'Buffer', data: [...] }).\n *\n * @param value value to check\n * @param depth recursion depth\n */\nexport function containsBinary(value: unknown, depth = 0): boolean {\n\tif (value === null || typeof value !== 'object') {\n\t\treturn false;\n\t}\n\tif (depth > 20) {\n\t\treturn true;\n\t}\n\tif (Buffer.isBuffer(value) || ArrayBuffer.isView(value) || value instanceof ArrayBuffer) {\n\t\treturn true;\n\t}\n\tconst o = value as Record<string, unknown>;\n\tif (o.type === 'Buffer' && Array.isArray(o.data)) {\n\t\treturn true;\n\t}\n\tconst children = Array.isArray(value) ? (value as unknown[]) : Object.values(o);\n\treturn children.some(v => containsBinary(v, depth + 1));\n}\n\n/**\n * Throws if a message for the message bus contains binary data or is too large.\n *\n * @param value message\n */\nexport function assertNoBinary(value: unknown): void {\n\tif (containsBinary(value)) {\n\t\tthrow new Error('refusing to put binary data on the ioBroker message bus');\n\t}\n\tconst len = Buffer.byteLength(JSON.stringify(value ?? null));\n\tif (len > MAX_MESSAGE_BYTES) {\n\t\tthrow new Error(`refusing to put ${len} bytes on the ioBroker message bus`);\n\t}\n}\n\n/**\n * Returns the message if it is safe for the message bus, otherwise a small error answer.\n *\n * @param value message\n */\nexport function safeMessage<T>(value: T): T | { ok: false; error: string } {\n\ttry {\n\t\tassertNoBinary(value);\n\t\treturn value;\n\t} catch (e) {\n\t\treturn { ok: false, error: (e as Error).message };\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,gCAAsB;AACtB,SAAoB;AACpB,WAAsB;AACtB,WAAsB;AAGf,MAAM,qBAAqB,KAAK,OAAO;AAEvC,MAAM,KAAK,OAAO;AAoBlB,SAAS,YAAY,KAAc,KAAa,KAAa,KAAqB;AACxF,QAAM,IAAI,OAAO,QAAQ,WAAW,MAAM,WAAW,OAAO,QAAQ,WAAW,MAAM,EAAE;AACvF,MAAI,CAAC,OAAO,SAAS,CAAC,GAAG;AACxB,WAAO;AAAA,EACR;AACA,SAAO,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC;AAClD;AAOO,SAAS,eAAe,KAAsB;AACpD,SAAO,YAAY,KAAK,GAAG,GAAG,CAAC;AAChC;AAO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