MCPcopy
hub / github.com/cpaczek/skylight / captureOnce

Function captureOnce

tracker/scripts/byte0-verify.ts:47–65  ·  view source on GitHub ↗
(secs: number)

Source from the content-addressed store, hash-verified

45const zoomWide = () => tx(0x0100, [0x81, 0x01, 0x04, 0x47, 0, 0, 0, 0, 0xff]);
46
47function captureOnce(secs: number): Promise<Uint8Array[]> {
48 return new Promise((resolve) => {
49 const ff = spawn("ffmpeg", [
50 // NOTE: no -rw_timeout — this ffmpeg build rejects it for RTSP
51 // ("Option rw_timeout not found") and exits instantly with 0 frames.
52 // The SIGKILL watchdog below is the hang protection.
53 "-hide_banner", "-loglevel", "error", "-rtsp_transport", "tcp", "-i", RTSP,
54 "-vf", `scale=${W}:${H},format=gray`, "-t", String(secs), "-f", "rawvideo", "pipe:1",
55 ]);
56 // Belt & braces: the camera's RTSP server can wedge and feed nothing.
57 const watchdog = setTimeout(() => ff.kill("SIGKILL"), (secs + 12) * 1000);
58 const fb = W * H; let buf = Buffer.alloc(0); const frames: Uint8Array[] = [];
59 ff.stdout.on("data", (c: Buffer) => {
60 buf = Buffer.concat([buf, c]);
61 while (buf.length >= fb) { frames.push(new Uint8Array(buf.subarray(0, fb))); buf = buf.subarray(fb); }
62 });
63 ff.on("close", () => { clearTimeout(watchdog); resolve(frames); });
64 });
65}
66const med = (a: number[]): number => a.slice().sort((x, y) => x - y)[a.length >> 1] ?? 0;
67const ax = (s: { dx: number; dy: number }, axis: "pan" | "tilt") => Math.abs(axis === "pan" ? s.dx : s.dy);
68

Callers 1

runFunction · 0.85

Calls 2

pushMethod · 0.80
killMethod · 0.45

Tested by

no test coverage detected