diff --git a/tools/aqua-feel/sync.mjs b/tools/aqua-feel/sync.mjs index 5d198b3..a1b42d2 100644 --- a/tools/aqua-feel/sync.mjs +++ b/tools/aqua-feel/sync.mjs @@ -100,7 +100,7 @@ export function sourceFrames(showinfo) { // Stream start_time offsets are applied so both clocks are the container's clock; video is resampled to constant frame rate by pts. export function readVideo(path, { ffmpeg = process.env.FFMPEG ?? "ffmpeg", targetFps } = {}) { // ffmpeg only (no ffprobe: static builds ship without it). `ffmpeg -i` lists the streams; the first decoded frame of each stream says when it starts. - const run = (a) => { const r = spawnSync(ffmpeg, a, { encoding: "utf8", maxBuffer: 1 << 26 }); if (r.error?.code === "ENOENT") throw new Error("ffmpeg is not on PATH (set FFMPEG=/path/to/ffmpeg); give --wav and --track instead"); return String(r.stderr ?? ""); }; + const run = (a) => { const r = spawnSync(ffmpeg, a, { encoding: "utf8", maxBuffer: 1 << 26 }); if (r.error?.code === "ENOENT") throw new Error("ffmpeg is not on PATH (set FFMPEG=/path/to/ffmpeg); give --wav and --track instead"); if (r.error) throw new Error(`ffmpeg failed (${r.error.code}): its frame list may be truncated, so the capture's stalls would be under-measured`); return String(r.stderr ?? ""); }; const lines = run(["-hide_banner", "-i", path]).split("\n"), find = (kind) => lines.find((l) => new RegExp(`Stream #\\d+:\\d+.*: ${kind}:`).test(l)); const vl = find("Video"), al = find("Audio"); if (!vl || !al) throw new Error("file needs one video and one audio stream"); diff --git a/tools/aqua-feel/sync.test.mjs b/tools/aqua-feel/sync.test.mjs index f593dd3..72394da 100644 --- a/tools/aqua-feel/sync.test.mjs +++ b/tools/aqua-feel/sync.test.mjs @@ -212,7 +212,7 @@ t("sourceFrames: the rate is the median frame gap, the stale-frame bound is the // The video path needs ffmpeg (FFMPEG=/path or on PATH); skipped, and said so, when there is none. { - const { readVideo } = await import("./sync.mjs"), { execFileSync } = await import("node:child_process"); + const { readVideo } = await import("./sync.mjs"), { execFileSync } = await import("node:child_process"), require_fs = await import("node:fs"), { tmpdir } = await import("node:os"), { join } = await import("node:path"); const ff = process.env.FFMPEG ?? "ffmpeg"; let have = true; try { execFileSync(ff, ["-version"], { stdio: "ignore" }); } catch { have = false; } if (!have) console.log("skip video path: no ffmpeg (set FFMPEG)"); @@ -252,6 +252,17 @@ t("sourceFrames: the rate is the median frame gap, the stale-frame bound is the for (const p of r.pairs) assert.ok(p.lagHighMs - p.lagLowMs >= v.sourceGapMs * 1.5, `interval ${p.lagHighMs - p.lagLowMs} ms narrower than the capture's own stalls`); assert.match(formatSync(r), /source frames are up to that far apart/); }); + if (have) t("the CLI carries the capture's frame gaps into its report (feel.mjs plumbing)", () => { + const { mkdtempSync, readFileSync: rf } = require_fs, out = join(mkdtempSync(join(tmpdir(), "sync-cli-")), "r.json"); + execFileSync("node", [new URL("./feel.mjs", import.meta.url).pathname, "sync", "--video", new URL("./fixtures/perlines-aurora-vfr.webm", import.meta.url).pathname, "--allow-unpaired", "--no-gate", "--json", out], { env: { ...process.env, FFMPEG: ff }, stdio: "ignore" }); + const r = JSON.parse(rf(out, "utf8")); + assert.ok(r.visualGapMs > 1000 / 59 * 1.5, `visualGapMs ${r.visualGapMs}`); assert.equal(r.framePeriodMs, r.visualGapMs); + }); + if (have) t("a failed ffmpeg read (e.g. output buffer overflow) is an error, not a quietly shorter frame list", () => { + const { mkdtempSync, writeFileSync: wf, chmodSync } = require_fs, d = mkdtempSync(join(tmpdir(), "sync-stub-")), stub = join(d, "ffmpeg"); + wf(stub, "#!/bin/sh\nhead -c 70000000 /dev/zero | tr '\\0' 'x' >&2\n"); chmodSync(stub, 0o755); + assert.throws(() => readVideo(new URL("./fixtures/perlines-aurora-vfr.webm", import.meta.url).pathname, { ffmpeg: stub }), /ffmpeg failed \(ENOBUFS\)/); + }); } console.log(`${n} sync checks passed. Fixtures only (synthetic, plus one browser capture when ffmpeg is present); nothing was heard or seen.`);