Archilyzer · Source

archilyzer

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

commit aa9f0d4876c40ad822ca64bef60d82c501d4ea9f
parent 76b5617bf2fe1bdad4a60ee2b79b6ff4341e77c2
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sun,  1 Nov 2026 11:47:46 -0500

umtool Play: the picture no longer freezes at a long gap -- a gapped clip decodes per kept piece, the piece after the next join primed before it (playCut.mjs pieceWants; codecPicture keys <url>#p<k>)

One WebCodecs decoder per window URL jumped at a gap's join by the gap's
length (20-60 s on a stream excerpt): a seek to the keyframe before it, that
block's byte range, a long GOP decoded through -- no frame due meanwhile, so
the picture held its last frame 2-4 s while the sound (scheduled ahead) had
already jumped. Now the piece after the join gets its own decoder within two
cut seconds of it (more at speed), sharing the moov read; at the join the
frame is there, and the piece played is let go.

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

Diffstat:
Mumtool/components/projects/review/playEngine/codecPicture.ts | 9+++++++--
Mumtool/components/projects/review/playEngine/engine.ts | 26+++++++++++++++++++-------
Aumtool/lib/report/pieceWants.test.mjs | 28++++++++++++++++++++++++++++
Mumtool/lib/report/playCut.mjs | 31+++++++++++++++++++++++++++++++
4 files changed, 85 insertions(+), 9 deletions(-)

diff --git a/umtool/components/projects/review/playEngine/codecPicture.ts b/umtool/components/projects/review/playEngine/codecPicture.ts @@ -313,7 +313,11 @@ class ClipDecoder { } } -/** The decoders of the clips on screen and the next: one per cached window URL, let go when not wanted. */ +/** + * The decoders of the clips on screen and the next: one per cached window URL -- and per kept + * piece of a gapped clip (`<url>#p<k>`, the piece after a join primed before it) -- let go when + * not wanted. + */ export class CodecPicture { private clips = new Map<string, ClipDecoder>(); private tick = 0; @@ -324,7 +328,8 @@ export class CodecPicture { for (const w of wants) { let d = this.clips.get(w.url); if (!d) { - d = new ClipDecoder(w.url); + // `<url>#p<k>`: a gapped clip's later piece, decoded by a decoder of its own (engine.ts pieceKeys). + d = new ClipDecoder(w.url.replace(/#p\d+$/, "")); this.clips.set(w.url, d); } d.used = this.tick; diff --git a/umtool/components/projects/review/playEngine/engine.ts b/umtool/components/projects/review/playEngine/engine.ts @@ -1,6 +1,6 @@ import { BLUR_CAPTION_DEFAULT, BLUR_STRENGTH } from "umtool-report-to-video/clip-blur"; import { inGap } from "umtool-report-to-video/gaps"; -import { cutAtSource, itemIndexAt, playPlan, sourceAt } from "@/lib/report/playCut.mjs"; +import { cutAtSource, itemIndexAt, pieceWants, playPlan, sourceAt } from "@/lib/report/playCut.mjs"; import { audioSpans, decodeSpanOf, scheduleFrom } from "@/lib/report/playSchedule.mjs"; import { drawFootageLayers, type FootageLayer } from "../footageCanvas"; import { AudioBank, type ClipSound } from "./audioBank"; @@ -516,6 +516,14 @@ export class PlayEngine { return it && e?.media ? this.o.srcOf(it.id, e.media) : null; } + /** The decoder keys for item i at t: its piece playing, and the next piece when its join is near. */ + private pieceKeys(i: number, t: number, url: string) { + const it = this.plan.items[i]; + const e = this.entries.get(it.id); + if (!it.clip?.gaps?.length) return [{ key: url, mediaTime: this.mediaTimeOf(i, t) }]; + return pieceWants(it, t, e?.media?.from ?? 0, { ahead: 2 * Math.max(1, this.rate) }).map((w) => ({ key: w.piece ? `${url}#p${w.piece}` : url, mediaTime: w.mediaTime })); + } + private mediaTimeOf(i: number, t: number) { const it = this.plan.items[i]; const e = this.entries.get(it.id); @@ -539,10 +547,15 @@ export class PlayEngine { const layers: { i: number; alpha: number; source: CanvasImageSource | null; w: number; h: number }[] = []; const viaElement: { i: number; alpha: number }[] = []; const codecWants: { url: string; mediaTime: number }[] = []; + // A gapped clip decodes per kept piece (`<url>#p<k>`), the piece after the next join primed + // before it (playCut.mjs pieceWants): the picture no longer holds at a long gap's jump. + const keyOf = new Map<number, { key: string; mediaTime: number }>(); for (const v of vis) { const url = this.mediaUrl(v.i)!; - const st = this.codecs?.status(url); - if (this.codecs && st !== "unsupported" && st !== "failed") codecWants.push({ url, mediaTime: this.mediaTimeOf(v.i, t) }); + const wants = this.pieceKeys(v.i, t, url); + keyOf.set(v.i, wants[0]); + const st = this.codecs?.status(wants[0].key); + if (this.codecs && st !== "unsupported" && st !== "failed") for (const w of wants) codecWants.push({ url: w.key, mediaTime: w.mediaTime }); else viaElement.push(v); } const nextUrl = nextI >= 0 ? this.mediaUrl(nextI) : null; @@ -559,12 +572,11 @@ export class PlayEngine { this.rate, ); for (const v of vis) { - const url = this.mediaUrl(v.i)!; if (this.codecs && !viaElement.includes(v)) { - const want = this.mediaTimeOf(v.i, t); - const f = this.codecs.frameFor(url, want); + const { key, mediaTime: want } = keyOf.get(v.i)!; + const f = this.codecs.frameFor(key, want); if (f && runs) this.measure(items[v.i].id, f.timestamp / 1e6, want, (f.duration ?? 33_333) / 1e6); - if (runs && inFootage(v.i)) this.keepingUp(url, f ? want - f.timestamp / 1e6 : Infinity); + if (runs && inFootage(v.i)) this.keepingUp(key, f ? want - f.timestamp / 1e6 : Infinity); layers.push({ ...v, source: f, w: f?.displayWidth ?? 0, h: f?.displayHeight ?? 0 }); } else { const el = this.elements.sourceFor(v.i); diff --git a/umtool/lib/report/pieceWants.test.mjs b/umtool/lib/report/pieceWants.test.mjs @@ -0,0 +1,28 @@ +// A gapped clip's picture decodes per kept piece, the next primed before its join (playCut.mjs pieceWants). +import assert from "node:assert/strict"; +import test from "node:test"; +import { gapJoins, pieceWants, playPlan } from "./playCut.mjs"; + +// One clip, 10–40 s of its recording, 15–30 cut out: it plays 10–15 then 30–40 (15 s of cut). +const entries = [{ id: "a", type: "clip", video: "v", start: 10, end: 40, gaps: [{ from: 15, to: 30 }] }]; +const plan = playPlan([{ id: "a", start: 0, duration: 15 }], entries, { leadIn: 0 }); +const it = plan.items[0]; + +test("pieceWants: the piece playing; the next one primed within `ahead` of its join", () => { + const [join] = gapJoins(it); + assert.ok(join, "the plan carries the gap"); + // The cached window starts at source 5: media time is source − 5. + const early = pieceWants(it, join.at - 3, 5, { ahead: 2 }); + assert.deepEqual(early.map((w) => w.piece), [0], "3 s before the join: only the piece playing"); + const near = pieceWants(it, join.at - 1, 5, { ahead: 2 }); + assert.deepEqual(near.map((w) => w.piece), [0, 1]); + assert.equal(near[1].mediaTime, 25, "the next piece from its first second: source 30"); + const after = pieceWants(it, join.at + 0.5, 5, { ahead: 2 }); + assert.deepEqual(after.map((w) => w.piece), [1], "past the join: the second piece, nothing after it"); + assert.ok(Math.abs(after[0].mediaTime - 25.5) < 0.05); +}); + +test("pieceWants: a clip with no gaps is one piece", () => { + const p2 = playPlan([{ id: "b", start: 0, duration: 5 }], [{ id: "b", type: "clip", video: "v", start: 0, end: 5 }], { leadIn: 0 }); + assert.deepEqual(pieceWants(p2.items[0], 1, 0).map((w) => w.piece), [0]); +}); diff --git a/umtool/lib/report/playCut.mjs b/umtool/lib/report/playCut.mjs @@ -469,3 +469,34 @@ export function dateKeyLabel(k) { const d = k % 100; return m >= 1 && m <= 12 ? `${d} ${MON[m - 1]} ${y}` : null; } + +/** + * WHAT TO DECODE FOR A GAPPED CLIP (the picture's half of a jump cut): the + * kept piece playing at cut second t, and -- when the next join is at most + * `ahead` cut seconds away -- the piece after it, from its first second. Play + * keeps one WebCodecs decoder per piece (codecPicture.ts keys `<url>#p<k>`), + * so the piece after a long gap is decoded BEFORE the join: one decoder that + * jumped at the join had to seek to a keyframe, fetch its block and decode up + * through a long GOP, and the picture held its last frame 2-4 s while the + * sound had already jumped. `mediaTime` is in the window's own seconds + * (source minus `mediaFrom`, the cached file's first second). + * + * @param {PlayItem} item + * @param {number} t + * @param {number} mediaFrom + * @param {{ ahead?: number }} [o] + * @returns {Array<{ piece: number, mediaTime: number }>} + */ +export function pieceWants(item, t, mediaFrom, { ahead = 2 } = {}) { + const src = sourceAt(item, t) ?? item?.clip?.sourceFrom ?? 0; + const gaps = item?.clip?.gaps ?? []; + let k = 0; + for (const g of gaps) if (src >= g.to - 1e-6) k += 1; + const out = [{ piece: k, mediaTime: Math.max(0, src - mediaFrom) }]; + const g = gaps[k]; + if (g) { + const at = cutAtSource(item, g.from); + if (at >= t - 1e-6 && at - t <= ahead) out.push({ piece: k + 1, mediaTime: Math.max(0, g.to - mediaFrom) }); + } + return out; +}