Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 0d83c3edcee6ffc149e79efd036d6b0cff3d4533
parent 804719d4adb05e62435b4a712c66fba881c1f651
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri, 23 Oct 2026 15:50:16 -0400

umtool: a clip held only by a whole recording is opened in the bench as an excerpt (the clip and 45 s either side, cut once by ffmpeg into out/bench-excerpts/, started when the clip is opened)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Meditor/CHANGELOG.md | 1+
Mumtool/app/api/report/audio/route.ts | 8+++++++-
Mumtool/app/api/report/clip/route.ts | 5++++-
Mumtool/app/api/report/peaks/route.ts | 8+++++++-
Mumtool/app/api/report/raw/route.ts | 8+++++++-
Aumtool/lib/report/serve-excerpt.test.mjs | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/serve.mjs | 108++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
7 files changed, 192 insertions(+), 7 deletions(-)

diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## [Unreleased] +- **umtool's clip editor opens a clip from a whole saved recording as a short excerpt.** When the only file holding a clip was the whole recording (hours long), the editor used all of it as its view: a waveform of the whole stream with the clip a sliver in it, and a video seeking hours into a large file. It now cuts the clip and 45 seconds either side from the recording once, on the umtool machine, and works on that; the cut starts when the clip is opened and is kept for the next time. The rendered video still cuts from the whole recording. - **A recording saved from a live capture now plays in umtool's clip editor.** A stream recorded while it was on air has no length in its transcript's record, and umtool read a saved recording's length from there, so the whole recording counted as no window and every clip cut from it sat in the clip walk as not fetched. umtool now asks the saved file itself for its length when the record has none (once per file). - **Rumble clip windows are cut from the whole recording, and a window whose picture runs off its sound is set aside.** A window fetched by seeking into Rumble's stream came out with the picture 1 to 4 seconds behind the sound 26 times out of 318, while a cut from a saved whole recording was exactly in sync. Fetch windows (`pnpm ops fetch-windows`, a site's **Fetch missing evidence**, umtool) now saves a Rumble video once, the way **Persist source video** does and on Rumble's download queue, then cuts every window of it from that copy: three clips of one video are one download, logged as "↧ <channel>/<id>: saving the whole recording (Rumble windows are cut from it), then cutting 3 window(s)". If that download fails, its windows fail with its message and nothing falls back to a seek. Which platforms work this way is `clips.wholeRecordingPlatforms` in settings.json (default `["rumble"]`), and `"wholeRecording": false` on a run seeks as before. Every window fetched by a seek, on any platform, is now checked with ffprobe for a picture or sound that starts late or a picture and sound of different lengths. A bad one is renamed `<from>-<to>.desynced.mp4`, never deleted, and fails with "the picture runs 3.2 s off the sound (a Rumble HLS seek); set aside as … — save the whole recording ("Persist source video") and fetch again to cut it from the saved video". A bad window already on disk is set aside when a fetch would have used it, and the same run fetches those seconds again. No reader (the video page, umtool, report videos) sees a set-aside window, and **Evict fetched windows** removes them by age like any window. **Check sync** on /storage and on a channel's Storage panel (`pnpm ops check-windows`, `{"slug"?, "video"?, "dryRun"?}`) checks the windows already on disk. Needs a restart of the editor. - **umtool's clip editor keeps a voice's pitch at any speed, and goes up to 4×.** A selection, an edge, a transcript line or the auto-audition played at 1.5× or 2× used to rise in pitch with the speed (2× was an octave up), unlike the same video at 2× in a player: the bench plays a range from decoded audio, whose speed control is a tape-speed knob. At any speed but 1× the range is now time-stretched at its own pitch first (waveform-similarity overlap-add) and played at 1×, still starting and stopping on the exact sample; a clip's selection is stretched ahead while the editor is idle, so playing it does not wait. The speed list adds 1.75×, 2.5×, 3×, 3.5× and 4×. Needs a restart of umtool. diff --git a/umtool/app/api/report/audio/route.ts b/umtool/app/api/report/audio/route.ts @@ -1,6 +1,6 @@ import { spawn } from "node:child_process"; import { stat } from "node:fs/promises"; -import { absOf, pickWindow, resolveClip, windowsFor } from "@/lib/report/serve.mjs"; +import { absOf, ensureWindowFile, pickWindow, resolveClip, windowsFor } from "@/lib/report/serve.mjs"; import { MAX_DECODE_SPAN, wavHeader } from "@/lib/report/playback.mjs"; import { FFMPEG_BIN } from "umtool-report-to-video/build-video"; @@ -37,6 +37,12 @@ export async function GET(request: Request) { const windows = await windowsFor(r.project, r.clip); const win = pickWindow(windows, url.searchParams.get("file")); if (!win) return Response.json({ error: "no cached window for this clip" }, { status: 404 }); + // A recording's excerpt is cut on first read (serve.mjs, "A RECORDING IS NOT A WINDOW"). + try { + await ensureWindowFile(win); + } catch (e) { + return Response.json({ error: `could not cut the excerpt: ${e instanceof Error ? e.message : String(e)}` }, { status: 500 }); + } const abs = absOf(win); if (!abs) return Response.json({ error: "outside the roots" }, { status: 400 }); const st = await stat(abs).catch(() => null); diff --git a/umtool/app/api/report/clip/route.ts b/umtool/app/api/report/clip/route.ts @@ -1,5 +1,5 @@ import path from "node:path"; -import { resolveClip, segmentFor, windowsFor } from "@/lib/report/serve.mjs"; +import { ensureWindowFile, resolveClip, segmentFor, windowsFor } from "@/lib/report/serve.mjs"; import { manifestToken } from "@/lib/report/manifest.mjs"; import { cuesInWindow, readClipDetail, siblingsOf } from "@/lib/projects/report.mjs"; @@ -30,6 +30,9 @@ export async function GET(request: Request) { // The view is the widest cached file when there is one, else a generous span // around the window so the waveform is not a blank rectangle before a fetch. const widest = windows[0] ?? null; + // A recording's excerpt: start cutting it now, so the player's first read + // usually finds it made (lib/report/serve.mjs, "A RECORDING IS NOT A WINDOW"). + if (widest && "excerptOf" in widest) void ensureWindowFile(widest).catch(() => {}); const view = widest ? { from: widest.from, to: widest.to } : { from: Math.max(0, clip.start - 20), to: clip.end + 20 }; diff --git a/umtool/app/api/report/peaks/route.ts b/umtool/app/api/report/peaks/route.ts @@ -1,4 +1,4 @@ -import { absOf, pickWindow, resolveClip, windowsFor } from "@/lib/report/serve.mjs"; +import { absOf, ensureWindowFile, pickWindow, resolveClip, windowsFor } from "@/lib/report/serve.mjs"; import { ENV_RATE, analyseMedia } from "@/lib/media"; export const dynamic = "force-dynamic"; @@ -21,6 +21,12 @@ export async function GET(request: Request) { const windows = await windowsFor(r.project, r.clip); const win = pickWindow(windows, url.searchParams.get("file")); if (!win) return Response.json({ error: "no cached window for this clip" }, { status: 404 }); + // A recording's excerpt is cut on first read (serve.mjs, "A RECORDING IS NOT A WINDOW"). + try { + await ensureWindowFile(win); + } catch (e) { + return Response.json({ error: `could not cut the excerpt: ${e instanceof Error ? e.message : String(e)}` }, { status: 500 }); + } const abs = absOf(win); if (!abs) return Response.json({ error: "outside the roots" }, { status: 400 }); diff --git a/umtool/app/api/report/raw/route.ts b/umtool/app/api/report/raw/route.ts @@ -1,7 +1,7 @@ import { createReadStream } from "node:fs"; import { stat } from "node:fs/promises"; import { Readable } from "node:stream"; -import { absOf, pickWindow, resolveClaim, resolveClip, windowsFor } from "@/lib/report/serve.mjs"; +import { absOf, ensureWindowFile, pickWindow, resolveClaim, resolveClip, windowsFor } from "@/lib/report/serve.mjs"; import { readClaimDetail } from "@/lib/projects/report.mjs"; export const dynamic = "force-dynamic"; @@ -44,6 +44,12 @@ export async function GET(request: Request) { // A member of the server's own scan, never a path from the client. const win = pickWindow(windows, url.searchParams.get("file")); if (!win) return new Response("no cached window covering that moment", { status: 404 }); + // A recording's excerpt is cut on first read (serve.mjs, "A RECORDING IS NOT A WINDOW"). + try { + await ensureWindowFile(win); + } catch (e) { + return new Response(`could not cut the excerpt: ${e instanceof Error ? e.message : String(e)}`, { status: 500 }); + } const abs = absOf(win); if (!abs) return new Response("outside the roots", { status: 400 }); diff --git a/umtool/lib/report/serve-excerpt.test.mjs b/umtool/lib/report/serve-excerpt.test.mjs @@ -0,0 +1,61 @@ +// A recording is not a window: the bench is given an excerpt of a long file. +// +// Run with: pnpm test:scripts +import assert from "node:assert/strict"; +import test from "node:test"; +import path from "node:path"; +import os from "node:os"; +import { execFileSync } from "node:child_process"; +import { mkdtemp, rm, stat } from "node:fs/promises"; + +const root = await mkdtemp(path.join(os.tmpdir(), "bench-excerpt-")); +// The roots are read when paths.mjs loads: this file's temp dir is one. +process.env.MIX_ROOTS = root; +const { excerptOf, ensureWindowFile, EXCERPT_OVER_S } = await import("./serve.mjs"); + +test.after(() => rm(root, { recursive: true, force: true })); + +const probe = (f) => + JSON.parse(execFileSync("ffprobe", ["-v", "error", "-show_entries", "stream=codec_type,start_time,duration:format=duration", "-of", "json", f]).toString()); + +test("a window is left alone; a recording gets the clip and a minute either side, edges rounded out", () => { + const win = { name: "100.00-160.00.mp4", path: "/x/100.00-160.00.mp4", from: 100, to: 160 }; + assert.equal(excerptOf(win, { video: "v", start: 110, end: 120 }, "/p"), null); + const rec = { name: "source-media.mp4", path: "/s/source-media.mp4", from: 0, to: 13554 }; + const e = excerptOf(rec, { video: "v7gkv5w", start: 4129.16, end: 4147.13 }, "/p"); + assert.equal(e.from, 4080); + assert.equal(e.to, 4200); + assert.equal(e.name, "4080.00-4200.00.excerpt.mp4"); + assert.equal(e.path, path.join("/p", "out", "bench-excerpts", "v7gkv5w", e.name)); + assert.deepEqual(e.excerptOf, { name: "source-media.mp4", path: "/s/source-media.mp4", from: 0 }); + // Clamped to the recording, and a small trim inside the rounding reuses the same file. + assert.equal(excerptOf(rec, { video: "v", start: 20, end: 30 }, "/p").from, 0); + assert.equal(excerptOf(rec, { video: "v", start: 4129.5, end: 4146 }, "/p").name, e.name); + assert.ok(EXCERPT_OVER_S >= 300); + assert.equal(excerptOf(rec, { video: "v" }, "/p"), null, "no span, no excerpt"); +}); + +test("the excerpt is cut once, frame-exact, both tracks from zero", async () => { + const src = path.join(root, "source-media.mp4"); + execFileSync("ffmpeg", [ + "-v", "error", "-y", + "-f", "lavfi", "-i", "testsrc2=size=320x240:rate=25:duration=40", + "-f", "lavfi", "-i", "sine=frequency=440:duration=40", + "-c:v", "libx264", "-preset", "ultrafast", "-c:a", "aac", "-shortest", src, + ]); + const rec = { name: "source-media.mp4", path: src, from: 0, to: 40 }; + const e = excerptOf(rec, { video: "vid", start: 18, end: 22 }, root, { over: 10, pad: 3, step: 5 }); + assert.deepEqual([e.from, e.to], [15, 25]); + await Promise.all([ensureWindowFile(e), ensureWindowFile(e)]); + const st = await stat(e.path); + const p = probe(e.path); + const v = p.streams.find((s) => s.codec_type === "video"); + const a = p.streams.find((s) => s.codec_type === "audio"); + assert.ok(Number(v.start_time) <= 0.05 && Number(a.start_time) <= 0.05, JSON.stringify(p.streams)); + assert.ok(Math.abs(Number(p.format.duration) - 10) < 0.2, p.format.duration); + // A second ask finds it and does not cut again. + await ensureWindowFile(e); + assert.equal((await stat(e.path)).mtimeMs, st.mtimeMs); + // A real window is never touched. + await ensureWindowFile({ name: "w.mp4", path: path.join(root, "nope.mp4"), from: 0, to: 1 }); +}); diff --git a/umtool/lib/report/serve.mjs b/umtool/lib/report/serve.mjs @@ -7,11 +7,13 @@ // membership check and once on resolveInRoots. import path from "node:path"; import { createReadStream } from "node:fs"; -import { realpath, stat } from "node:fs/promises"; +import { mkdir, realpath, rename, rm, stat } from "node:fs/promises"; +import { execFile } from "node:child_process"; +import { promisify } from "node:util"; import { Readable } from "node:stream"; import { REPORTS_ROOT, inside, resolveInRoots } from "../paths.mjs"; import { walkProjects } from "../projects/walk.mjs"; -import { DEFAULT_VARIANT, VARIANTS, WIN_EPS, variantPaths } from "umtool-report-to-video/build-video"; +import { DEFAULT_VARIANT, FFMPEG_BIN, VARIANTS, WIN_EPS, variantPaths } from "umtool-report-to-video/build-video"; import { rawCacheOf } from "./raw-cache.mjs"; import { channelsDirFor, @@ -108,7 +110,107 @@ export async function windowsFor(project, clip, cache = null) { const contains = (w) => (w.from <= start + WIN_EPS && w.to >= end - WIN_EPS ? 1 : 0); return all .filter((w) => overlap(w) > 0) - .sort((a, b) => contains(b) - contains(a) || overlap(b) - overlap(a) || width(b) - width(a)); + .sort((a, b) => contains(b) - contains(a) || overlap(b) - overlap(a) || width(b) - width(a)) + .map((w) => (contains(w) ? excerptOf(w, clip, project.dir) ?? w : w)); +} + +// --------------------------------------------------------------------------- +// A RECORDING IS NOT A WINDOW. +// +// Since the saved-video tier (and since Rumble windows are cut from the whole +// recording), the widest file holding a clip is often the whole stream: 3 h 45 m +// for one 18-second clip (2026-10-23, costco-ok). The bench took it as its view +// -- a waveform of 13,554 s with the clip a sliver in it, the peaks of a 2 GB +// file decoded first, the <video> seeking hours into a container on a platter. +// +// So a window much longer than any clip is answered by an EXCERPT of it: the +// clip and 45 s either side (edges rounded out to 15 s, so a trim inside +// that does not cut again), re-encoded once on this machine -- frame-exact, both +// tracks from zero -- into the project's out/bench-excerpts/, and served like +// any window. The listing only DESCRIBES it: the bench page asks windowsFor for +// every clip, and nothing should encode until a route reads the bytes +// (ensureWindowFile) -- except the clip route, which starts the cut without +// waiting when a clip is opened, so the player usually finds it made (a 2-minute +// excerpt of a 1080p recording on a platter is 10-30 s of ffmpeg on a busy +// machine). The render never comes through here; it cuts the clip from the +// whole recording itself. +// --------------------------------------------------------------------------- + +/** A window longer than this (seconds) is a recording, and the bench is given an excerpt of it. */ +export const EXCERPT_OVER_S = 600; +/** Seconds kept on either side of the clip. */ +export const EXCERPT_PAD_S = 45; +/** An excerpt's edges are rounded out to multiples of this, so small trims reuse it. */ +export const EXCERPT_STEP_S = 15; + +/** + * The excerpt standing in for `win` for this clip, or null when `win` is a + * window already. + * + * @param {{name: string, path: string, from: number, to: number}} win + * @param {{video: string, start: number, end: number}} clip + * @param {string} projectDir + * @param {{over?: number, pad?: number, step?: number}} [opts] + */ +export function excerptOf(win, clip, projectDir, { over = EXCERPT_OVER_S, pad = EXCERPT_PAD_S, step = EXCERPT_STEP_S } = {}) { + if (!(win.to - win.from > over)) return null; + if (!Number.isFinite(clip.start) || !Number.isFinite(clip.end)) return null; + const from = Math.max(win.from, Math.floor((clip.start - pad) / step) * step); + const to = Math.min(win.to, Math.ceil((clip.end + pad) / step) * step); + if (!(to > from)) return null; + const name = `${from.toFixed(2)}-${to.toFixed(2)}.excerpt.mp4`; + return { + name, + from, + to, + path: path.join(projectDir, "out", "bench-excerpts", String(clip.video), name), + excerptOf: { name: win.name, path: win.path, from: win.from }, + }; +} + +const execFileP = promisify(execFile); +const cutting = new Map(); + +/** + * Make sure a window's file is on disk: a no-op for a real window; for an + * excerpt, cut it once (newer than its source = done) and share the cut with + * every request that asks meanwhile. + * + * @param {{path: string, from: number, to: number, excerptOf?: {path: string, from: number}}} win + */ +export async function ensureWindowFile(win, { ffmpeg = FFMPEG_BIN } = {}) { + if (!win?.excerptOf) return; + const src = resolveInRoots(win.excerptOf.path); + if (!src) throw new Error("the recording is outside the roots"); + const srcSt = await stat(src); + const have = await stat(win.path).catch(() => null); + if (have && have.size > 0 && have.mtimeMs >= srcSt.mtimeMs) return; + if (!cutting.has(win.path)) { + const job = (async () => { + await mkdir(path.dirname(win.path), { recursive: true }); + const tmp = `${win.path}.part.mp4`; + try { + await execFileP(ffmpeg, [ + "-v", "error", "-y", + "-ss", String(win.from - win.excerptOf.from), + "-i", src, + "-t", String(win.to - win.from), + "-map", "0:v:0", "-map", "0:a:0?", + "-vf", "scale=-2:'min(720,ih)'", + "-c:v", "libx264", "-preset", "ultrafast", "-crf", "26", "-threads", "0", + "-c:a", "aac", "-b:a", "160k", "-ac", "2", + "-movflags", "+faststart", + tmp, + ], { maxBuffer: 4 * 1024 * 1024 }); + await rename(tmp, win.path); + } catch (e) { + await rm(tmp, { force: true }); + throw e; + } + })().finally(() => cutting.delete(win.path)); + cutting.set(win.path, job); + } + await cutting.get(win.path); } export function pickWindow(windows, wantedName) {