Archilyzer · Source

archilyzer

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

commit 39e9bac188859b012fa86e19721971cc8129021c
parent 873ffc79d7f63fbad02109b5e8d6500bc8c0e70e
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu, 29 Oct 2026 06:03:59 -0400

umtool take --from: seed the twin's ladder with the other take's fit scales

A --from twin linked the other take's ladder chunks, but its size-capped rung
started at scale 1 (no ladder.json of its own), so its first try keyed every
chunk anew: on the Trisha copy the fit24 rung encoded 29 + 3 chunks where 3
would do. seedLadderFit (variants.mjs) writes each size-capped rung's last
good scale from the other take's ladder.json into this take's own (written,
not linked; never over a scale of its own); linkFromTake calls it. A twin
out/ in variants.test.mjs now encodes 0 rung chunks on its first run.

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

Diffstat:
Mumtool/lib/report/takeFrom.mjs | 11+++++++++--
Mumtool/lib/report/takeFrom.test.mjs | 20+++++++++++++++++---
Mumtool/lib/report/takeMaker.mjs | 1+
Mumtool/report-to-video/README.md | 6+++++-
Mumtool/report-to-video/variants.mjs | 33+++++++++++++++++++++++++++++++++
Mumtool/report-to-video/variants.test.mjs | 20++++++++++++++++++--
6 files changed, 83 insertions(+), 8 deletions(-)

diff --git a/umtool/lib/report/takeFrom.mjs b/umtool/lib/report/takeFrom.mjs @@ -33,7 +33,10 @@ // ladder/chunks/<key>.mp4|m4a each encoded rung chunk of the variant // ladder (ladder-chunks.mjs), keyed by the // master chunk it was made from and the -// rung's settings +// rung's settings; and, into this take's +// own ladder/ladder.json (written, not +// linked), each size-capped rung's last +// good scale it has none of // // THIS take's own files win when they are newer (release fast-rerender): a // take re-run `--force --from <other>` after it was stopped mid-render has @@ -63,6 +66,7 @@ import { DEFAULT_VARIANT, SEGMENT_FILE_SUFFIXES, VARIANTS, XFADE_FROM_FILE } fro import { CHUNKS_DIR, CHUNKS_RECORD, HASH_MEMO_FILE } from "umtool-report-to-video/chunked-encode"; import { LADDER_CHUNKS_DIR, LADDER_DIR, isLadderChunkFile } from "umtool-report-to-video/ladder-chunks"; import { KEEP_FRAMES_DIR, keptFramesDir } from "umtool-report-to-video/prune-frames"; +import { seedLadderFit } from "umtool-report-to-video/variants"; import { takesDirOf } from "./takes.mjs"; /** Where a take keeps a layer aside: its `out/.keep-frames/<layer>-frames` (prune-frames.mjs). */ @@ -117,7 +121,7 @@ export async function fromTakeSourced(projectDir, id, from) { * `takeOut/ladder/` (see the top of the file). The counts are summed over the * variants; a frame layer of the full variant is named `full/<layer>-frames`. * @returns {Promise<{ segments: number, frames: string[], batches: number, chunks: number, records: number, - * ladder: number, variants: string[], keptOwn: string[], keptOwnFrames: string[] }>} + * ladder: number, ladderFit?: string[], variants: string[], keptOwn: string[], keptOwnFrames: string[] }>} */ export async function linkFromTake(projectDir, id, from, takeOut) { const src = await fromTakeSourced(projectDir, id, from); @@ -146,6 +150,9 @@ export async function linkFromTake(projectDir, id, from, takeOut) { await mkdir(ladderOut, { recursive: true }); if (!(await isFile(path.join(ladderOut, f))) && (await linkFile(path.join(ladder, f), path.join(ladderOut, f)))) out.ladder += 1; } + // Its size-capped rungs' last good scales, as where this take's start: the + // chunks the two cuts share then key alike on those rungs too. + out.ladderFit = await seedLadderFit(otherOut, takeOut); return out; } diff --git a/umtool/lib/report/takeFrom.test.mjs b/umtool/lib/report/takeFrom.test.mjs @@ -185,13 +185,27 @@ test("linkFromTake: the chunk record (unless ours is newer), the full variant, t const rungFile = `rung-${"ab".repeat(12)}.mp4`; await writeFile(path.join(ladder, rungFile), "rung"); await writeFile(path.join(ladder, `.rung-${"cd".repeat(12)}.1.partial.mp4`), "half"); - await writeFile(path.join(other, "ladder", "ladder.json"), "{}"); + const basis = { maxMiB: 24, seconds: 781.37, srcHeight: 1080, maxHeight: null }; + await writeFile(path.join(other, "ladder", "ladder.json"), JSON.stringify({ + version: 1, master: { id: "x" }, + rungs: { "720p": { keys: ["a"], audio: "copy", master: "x", file: "f" }, fit24: { keys: ["b"], audio: "c", master: "x", file: "g", fit: { basis, scale: 0.94 } } }, + })); const withLadder = await linkFromTake(p.dir, "twin", "blurred", out); assert.equal(withLadder.ladder, 1); assert.ok(sameFile(path.join(ladder, rungFile), path.join(out, "ladder", "chunks", rungFile))); assert.deepEqual((await import("node:fs")).readdirSync(path.join(out, "ladder", "chunks")), [rungFile]); - assert.ok(!existsSync(path.join(out, "ladder", "ladder.json")), "the record is this take's own"); - assert.equal((await linkFromTake(p.dir, "twin", "blurred", out)).ladder, 0); + // Their record is not linked; their size-capped rung's scale seeds ours. + assert.deepEqual(withLadder.ladderFit, ["fit24"]); + const seededRec = JSON.parse(await readFile(path.join(out, "ladder", "ladder.json"), "utf8")); + assert.deepEqual(seededRec.rungs, { fit24: { keys: [], audio: null, master: null, file: null, fit: { basis, scale: 0.94 } } }); + assert.ok(!sameFile(path.join(other, "ladder", "ladder.json"), path.join(out, "ladder", "ladder.json"))); + // Our own scale is never overwritten. + seededRec.rungs.fit24.fit.scale = 0.88; + await writeFile(path.join(out, "ladder", "ladder.json"), JSON.stringify(seededRec)); + const again2 = await linkFromTake(p.dir, "twin", "blurred", out); + assert.equal(again2.ladder, 0); + assert.deepEqual(again2.ladderFit, []); + assert.equal(JSON.parse(await readFile(path.join(out, "ladder", "ladder.json"), "utf8")).rungs.fit24.fit.scale, 0.88); // No full variant on the other side: only sourced. await rm(full, { recursive: true }); assert.deepEqual((await linkFromTake(p.dir, "twin", "blurred", out)).variants, ["sourced"]); diff --git a/umtool/lib/report/takeMaker.mjs b/umtool/lib/report/takeMaker.mjs @@ -560,6 +560,7 @@ export async function makeTake(projectDir, rawSpec, opts = {}) { `${got.frames.length ? got.frames.join(", ") : "no chrome frames"}, ${got.batches} crossfade batch(es), ` + `${got.chunks ?? 0} encode chunk(s)${got.records ? ` and ${got.records} chunk record(s)` : ""}` + `${got.ladder ? `, ${got.ladder} ladder chunk(s)` : ""}` + + `${got.ladderFit?.length ? ` (the scale ${got.ladderFit.join(", ")} landed at)` : ""}` + `${(got.variants?.length ?? 1) > 1 ? ` (variants ${got.variants.join(", ")})` : ""} — reused where they still match`, ); // This take's own newer build, kept (takeFrom.mjs): said, so a re-run says why it did not start over. diff --git a/umtool/report-to-video/README.md b/umtool/report-to-video/README.md @@ -2935,7 +2935,11 @@ by the master's inode and the record), each rung is encoded chunk by chunk: while it lands over it is lowered by what it overshot (at least 6 %), and the scale it last landed under at is kept, so the next run starts there with the same keys and encodes nothing; -- rung chunks no rung of the ladder names are removed after a run. +- rung chunks no rung of the ladder names are removed after a run; +- `umtool take --from` links the other take's `out/ladder/chunks/` and seeds + this take's `ladder.json` with its size-capped rungs' last good scales + (`seedLadderFit`; never over one of this take's own), so a twin's first + ladder run encodes only the chunks that differ, on every rung. So a change to one clip re-encodes that clip's chunks on every rung, and a second run with nothing changed encodes nothing. `--whole` (or no chunks, or diff --git a/umtool/report-to-video/variants.mjs b/umtool/report-to-video/variants.mjs @@ -303,6 +303,39 @@ async function openLadder({ outDir, src, work, slug, onLog }) { return { run, remember, save, rec }; } +/** + * Seed `toOut`'s ladder record with `fromOut`'s size-capped rungs' last good + * scales (`take --from`, takeFrom.mjs): a rung this out/ has no scale for + * starts where the other take's landed, so the chunks the two cuts share key + * alike and are not encoded again. Never overwrites a scale of this out/'s + * own. Returns the rung names seeded. + * + * @param {string} fromOut + * @param {string} toOut + * @returns {Promise<string[]>} + */ +export async function seedLadderFit(fromOut, toOut) { + const theirs = await readJson(path.join(fromOut, LADDER_DIR, LADDER_RECORD)); + if (theirs?.version !== 1 || !isObj(theirs.rungs)) return []; + const file = path.join(toOut, LADDER_DIR, LADDER_RECORD); + const own = await readJson(file); + const rec = own?.version === 1 && isObj(own.rungs) ? own : { version: 1, master: null, rungs: {} }; + const seeded = []; + for (const [name, r] of Object.entries(theirs.rungs)) { + const fit = isObj(r) ? r.fit : null; + if (!isObj(fit) || !isObj(fit.basis) || !(fit.scale > 0 && fit.scale <= 1)) continue; + if (isObj(rec.rungs[name]?.fit)) continue; + rec.rungs[name] = { ...(isObj(rec.rungs[name]) ? rec.rungs[name] : { keys: [], audio: null, master: null, file: null }), fit: { basis: fit.basis, scale: fit.scale } }; + seeded.push(name); + } + if (!seeded.length) return []; + await mkdir(path.dirname(file), { recursive: true }); + const tmp = path.join(path.dirname(file), `.${LADDER_RECORD}.${process.pid}.seed`); + await writeFile(tmp, JSON.stringify(rec, null, 2) + "\n", "utf8"); + await rename(tmp, file); + return seeded; +} + const encodeOf = (r) => ({ from: "chunks", chunks: r.chunks, encoded: r.encoded, reused: r.reused, seconds: r.seconds, ...(r.skipped ? { unchanged: true } : {}) }); /** diff --git a/umtool/report-to-video/variants.test.mjs b/umtool/report-to-video/variants.test.mjs @@ -6,14 +6,14 @@ import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; import { createHash } from "node:crypto"; -import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs"; +import { existsSync, linkSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; import { - DEFAULT_VARIANTS, encodeVariants, fitPlan, parseVariantArgs, validateVariants, VARIANTS_FILE, variantsOf, + DEFAULT_VARIANTS, encodeVariants, fitPlan, parseVariantArgs, seedLadderFit, validateVariants, VARIANTS_FILE, variantsOf, } from "./variants.mjs"; import { CHUNKS_DIR, CHUNKS_RECORD } from "./chunked-encode.mjs"; import { LADDER_CHUNKS_DIR, LADDER_DIR, LADDER_RECORD } from "./ladder-chunks.mjs"; @@ -223,6 +223,22 @@ test("the ladder from the master's chunks: each rung chunk encoded once; a secon } assert.equal(r2.fit.encode.scale, rec1.rungs.fit.fit.scale, "the fit starts where it last landed"); + // A twin out/ (what `take --from` makes): the master's chunks and the + // ladder's linked, the fit's scale seeded -- its first ladder run encodes nothing. + const twin = path.join(out, "twin"); + mkdirSync(path.join(twin, "sourced", CHUNKS_DIR), { recursive: true }); + mkdirSync(path.join(twin, LADDER_DIR, LADDER_CHUNKS_DIR), { recursive: true }); + for (const f of readdirSync(path.join(work, CHUNKS_DIR))) linkSync(path.join(work, CHUNKS_DIR, f), path.join(twin, "sourced", CHUNKS_DIR, f)); + for (const f of readdirSync(path.join(out, LADDER_DIR, LADDER_CHUNKS_DIR))) linkSync(path.join(out, LADDER_DIR, LADDER_CHUNKS_DIR, f), path.join(twin, LADDER_DIR, LADDER_CHUNKS_DIR, f)); + linkSync(master, path.join(twin, "demo.mp4")); + assert.deepEqual(await seedLadderFit(out, twin), ["fit"]); + const rt = by(await encodeVariants(twin, { slug: "demo", variants })); + assert.equal(rt.half.encode.encoded, 0); + assert.equal(rt.fit.encode.encoded, 0, JSON.stringify(rt.fit.encode)); + assert.equal(md5(rt.half.path), sums.half); + assert.equal(md5(rt.fit.path), sums.fit); + rmSync(twin, { recursive: true }); + // A rung's file gone: joined again from the cached chunks, to the same bytes. rmSync(r1.half.path); const r3 = by(await encodeVariants(out, { slug: "demo", variants, only: ["half"] }));