Skip to content

Art and animation, written as code. Illustrations, loops, interactive web art, launch-videos and scored films in dozens of styles, identical on every render.

motion blur adapts to speed: render --blur auto measures each frame's on-screen motion (block-matched luma at the shutter's two ends; content that changes without moving, periodic textures and incoherent vectors rejected) and takes subframes <= 3 px apart (1 on a still frame, max 32); --shutter DEG (default 180); deterministic across workers; render prints the subframe histogram

Alex Greenshpunc2a7f81a8a29
diff --git a/skills/anidoodle/engine/src/hosts/page.ts b/skills/anidoodle/engine/src/hosts/page.ts
index 2395042..59a511d 100644
--- a/skills/anidoodle/engine/src/hosts/page.ts
+++ b/skills/anidoodle/engine/src/hosts/page.ts
@@ -62,24 +62,67 @@ export const mountFilm = (film: Film) => {
const toLin = new Float32Array(256);
for (let i = 0; i < 256; i++) { const s = i / 255; toLin[i] = s <= 0.04045 ? s / 12.92 : Math.pow((s + 0.055) / 1.055, 2.4); }
const fromLin = (l: number) => { const v = l <= 0.0031308 ? l * 12.92 : 1.055 * Math.pow(l, 1 / 2.4) - 0.055; return Math.max(0, Math.min(255, Math.round(v * 255))); };
- const blur = (frame: number, samples: number) => {
+ // SHUTTER. `shutter` is the angle in degrees: 360 spreads the subframes over the whole frame
+ // interval, 180 (film's standard, and the default) over half of it, centred on the frame.
+ // ADAPTIVE (samples 0 = auto): how many subframes a frame needs comes from how fast its picture
+ // moves on screen. Two sharp renders at the shutter's two ends are block-matched on a 1/8 luma
+ // grid (8x8 blocks, +-16 cells = +-128 px, textured blocks only); the 98th percentile displacement,
+ // divided by `px` (default 3: subframes at most 3 px apart), is the count, 1 on a still frame (the
+ // sharp frame itself, untouched), at most `max` (default 32). Pure pixels in, a number out:
+ // deterministic like the frames it measures.
+ type BlurSpec = { samples?: number; shutter?: number; max?: number; px?: number };
+ const lumaGrid = (f: number, cell: number) => {
+ renderFrame(film, ctx, f, env); const w = canvas.width, h = canvas.height, d = ctx.getImageData(0, 0, w, h).data, gw = Math.floor(w / cell), gh = Math.floor(h / cell), g = new Float32Array(gw * gh);
+ for (let y = 0; y < gh; y++) for (let x = 0; x < gw; x++) { let s = 0; for (let yy = 0; yy < cell; yy += 2) for (let xx = 0; xx < cell; xx += 2) { const p = ((y * cell + yy) * w + x * cell + xx) * 4, a = d[p + 3] / 255; s += (0.2126 * d[p] + 0.7152 * d[p + 1] + 0.0722 * d[p + 2]) * a; } g[y * gw + x] = s / ((cell * cell) / 4); }
+ return { g, gw, gh };
+ };
+ const speedOf = (t0: number, t1: number) => {
+ const cell = 8, B = 8, R = 16, A = lumaGrid(t0, cell), Z = lumaGrid(t1, cell), { gw, gh } = A, vec = new Map<number, [number, number]>();
+ const cols = Math.floor((gw - 2 * R - B) / B) + 1;
+ for (let by = R, row = 0; by + B + R <= gh; by += B, row++) for (let bx = R, col = 0; bx + B + R <= gw; bx += B, col++) {
+ let mean = 0, v = 0; for (let y = 0; y < B; y++) for (let x = 0; x < B; x++) mean += A.g[(by + y) * gw + bx + x]; mean /= B * B;
+ for (let y = 0; y < B; y++) for (let x = 0; x < B; x++) v += (A.g[(by + y) * gw + bx + x] - mean) ** 2;
+ if (v / (B * B) < 12) continue; // flat: no motion can be read off it
+ const sadAt = (dx: number, dy: number) => { let sad = 0; for (let y = 0; y < B; y++) for (let x = 0; x < B; x++) sad += Math.abs(A.g[(by + y) * gw + bx + x] - Z.g[(by + y + dy) * gw + bx + x + dx]); return sad; };
+ const cost = new Float64Array((2 * R + 1) ** 2); let best = Infinity;
+ for (let dy = -R; dy <= R; dy++) for (let dx = -R; dx <= R; dx++) { const c = sadAt(dx, dy); cost[(dy + R) * (2 * R + 1) + dx + R] = c; if (c < best) best = c; }
+ // content that changes without moving (a stroke drawn, a letter typed) matches nowhere well: not motion
+ if (best / (B * B) > 4) continue;
+ // a periodic texture (halftone, stripes) matches equally well far away: of the near-best offsets take the SMALLEST motion
+ let mx = 0, my = 0, md = Infinity;
+ for (let dy = -R; dy <= R; dy++) for (let dx = -R; dx <= R; dx++) { const c = cost[(dy + R) * (2 * R + 1) + dx + R], d = Math.hypot(dx, dy); if (c <= best * 1.1 + B * B * 0.5 && d < md) { md = d; mx = dx; my = dy; } }
+ const at = (dx: number, dy: number) => (Math.abs(dx) <= R && Math.abs(dy) <= R ? cost[(dy + R) * (2 * R + 1) + dx + R] : Infinity), c0 = at(mx, my);
+ const sub = (m: number, c: number, p: number) => { const d = m - 2 * c + p; return Number.isFinite(d) && d > 0 ? Math.max(-0.5, Math.min(0.5, (0.5 * (m - p)) / d)) : 0; };
+ vec.set(row * cols + col, [mx + (mx || my ? sub(at(mx - 1, my), c0, at(mx + 1, my)) : 0), my + (mx || my ? sub(at(mx, my - 1), c0, at(mx, my + 1)) : 0)]);
+ }
+ // real motion is coherent: a block's vector counts only if two of its neighbours agree with it (within 1.5 cells)
+ const disp: number[] = [];
+ for (const [key, [x, y]] of vec) { const r = Math.floor(key / cols), c = key % cols; let agree = 0; for (let dr = -1; dr <= 1; dr++) for (let dc = -1; dc <= 1; dc++) { if (!dr && !dc) continue; const nb = vec.get((r + dr) * cols + c + dc); if (nb && c + dc >= 0 && c + dc < cols && Math.hypot(nb[0] - x, nb[1] - y) <= 1.5) agree++; } if (agree >= 2) disp.push((Math.hypot(x, y) * cell) / env.scale); }
+ if (!disp.length) return 0;
+ disp.sort((a, b) => a - b); return disp[Math.min(disp.length - 1, Math.floor(disp.length * 0.98))];
+ };
+ const blur = (frame: number, spec: number | BlurSpec) => {
+ const o: BlurSpec = typeof spec === "number" ? { samples: spec, shutter: 360 } : spec, sh = (o.shutter ?? 180) / 360;
const n = Math.max(0, Math.min(film.meta.durationFrames - 1, Math.round(frame))), shot = film.shots.find((s) => n >= s.start && n < s.end);
- if (!shot || samples < 2 || (film.meta.step ?? (film.meta.onTwos ? 2 : 1)) > 1) { const r = seek(n); return { shot: r.shot, ms: r.ms }; }
+ const stepped = (film.meta.step ?? (film.meta.onTwos ? 2 : 1)) > 1, win = (t: number) => Math.min(shot!.end - 1, Math.max(shot!.start, t));
+ let samples = o.samples ?? 0, speed = NaN;
+ if (shot && !stepped && samples === 0) { speed = speedOf(win(n - sh / 2), win(n + sh / 2)); samples = Math.max(1, Math.min(o.max ?? 32, Math.ceil(speed / (o.px ?? 3)))); }
+ if (!shot || samples < 2 || stepped) { const r = seek(n); return { shot: r.shot, ms: r.ms, samples: 1, speed }; }
const t0 = performance.now(), w = canvas.width, h = canvas.height, acc = new Float64Array(w * h * 4);
for (let i = 0; i < samples; i++) {
- const t = Math.min(shot.end - 1, Math.max(shot.start, n + (i + 0.5) / samples - 0.5));
+ const t = win(n + ((i + 0.5) / samples - 0.5) * sh);
renderFrame(film, ctx, t, env);
const d = ctx.getImageData(0, 0, w, h).data;
for (let p = 0; p < d.length; p += 4) { const a = d[p + 3], k = a / 255; acc[p] += toLin[d[p]] * k; acc[p + 1] += toLin[d[p + 1]] * k; acc[p + 2] += toLin[d[p + 2]] * k; acc[p + 3] += a; }
}
- const img = ctx.createImageData(w, h), o = img.data, inv = 1 / samples, full = 255 * samples;
- for (let p = 0; p < o.length; p += 4) {
+ const img = ctx.createImageData(w, h), out = img.data, inv = 1 / samples, full = 255 * samples;
+ for (let p = 0; p < out.length; p += 4) {
const A = acc[p + 3]; if (A === 0) continue; // nothing was ever drawn here: stays transparent black
const c = A === full ? inv : 255 / A; // premultiplied average, un-premultiplied by the mean alpha
- o[p] = fromLin(acc[p] * c); o[p + 1] = fromLin(acc[p + 1] * c); o[p + 2] = fromLin(acc[p + 2] * c); o[p + 3] = Math.round(A * inv);
+ out[p] = fromLin(acc[p] * c); out[p + 1] = fromLin(acc[p + 1] * c); out[p + 2] = fromLin(acc[p + 2] * c); out[p + 3] = Math.round(A * inv);
}
ctx.putImageData(img, 0, 0); current = n;
- return { shot: shot.id, ms: performance.now() - t0 };
+ return { shot: shot.id, ms: performance.now() - t0, samples, speed };
};
const audio = (sr: number) => { if (!film.audio) return null; const [L, R] = film.audio(sr); if (L.length !== R.length) throw new Error("audio channels have different lengths"); const pcm = new Float32Array(L.length * 2); for (let i = 0; i < L.length; i++) { pcm[i * 2] = L[i]; pcm[i * 2 + 1] = R[i]; } return { sampleRate: sr, frames: L.length, float32: b64(new Uint8Array(pcm.buffer)) }; };
const warm = () => film.shots.forEach((s) => { seek(s.start); seek(s.start + ((s.end - s.start) >> 1)); }); // first + middle frame of every shot: builds tiles, pre-allocates the layer pool
@@ -88,16 +131,17 @@ export const mountFilm = (film: Film) => {
// poster frame is drawn once into its own surface; frame n < fade is the real frame n with the
// poster laid over it at 1 - n/fade. Frame 0 IS the poster. Nothing else changes, not the score.
let posterOf: { key: string; img: CanvasImageSource } | null = null;
- const poster = (frame: number, posterFrame: number, fade: number, samples = 1) => {
- const n = Math.round(frame), u = fade > 0 ? 1 - n / fade : n === 0 ? 1 : 0, key = `${posterFrame}/${samples}/${canvas.width}x${canvas.height}`;
+ const poster = (frame: number, posterFrame: number, fade: number, samples: number | BlurSpec = 1) => {
+ const on = typeof samples === "number" ? samples > 1 : true;
+ const n = Math.round(frame), u = fade > 0 ? 1 - n / fade : n === 0 ? 1 : 0, key = `${posterFrame}/${JSON.stringify(samples)}/${canvas.width}x${canvas.height}`;
if (u > 0 && posterOf?.key !== key) {
- samples > 1 ? blur(posterFrame, samples) : seek(posterFrame);
+ on ? blur(posterFrame, samples) : seek(posterFrame);
// the copy lives on the same kind of surface the art uses (surface(): same raster opts). A plain
// GPU <canvas> drawn onto a meta.raster "cpu" canvas flips Chrome's raster path for the rest
// of the session and every later frame comes out different: measured, not guessed.
const c = surface(canvas.width, canvas.height); c.ctx.drawImage(canvas, 0, 0); posterOf = { key, img: c.canvas };
}
- const r = samples > 1 ? blur(n, samples) : seek(n);
+ const r = on ? blur(n, samples) : seek(n);
if (u > 0 && posterOf) { ctx.save(); ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.globalAlpha = Math.min(1, u); ctx.globalCompositeOperation = "source-over"; if (u >= 1) ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.drawImage(posterOf.img, 0, 0); ctx.restore(); }
current = n; return r;
};
diff --git a/skills/anidoodle/engine/tools/adapters/playwright.mjs b/skills/anidoodle/engine/tools/adapters/playwright.mjs
index 10bdcc3..bd69776 100644
--- a/skills/anidoodle/engine/tools/adapters/playwright.mjs
+++ b/skills/anidoodle/engine/tools/adapters/playwright.mjs
@@ -25,7 +25,8 @@ export const open = async ({ pw, browser: found }, pagePath, { scale = 1, worker
frame: async (n, w = n) => { const t0 = Date.now(); const r = await pick(w).evaluate((f) => { const s = window.FILM.seek(f); const t = performance.now(); const png = window.FILM.png(); return { ...s, png, enc: performance.now() - t }; }, n); return { png: Buffer.from(r.png, "base64"), shot: r.shot, drawMs: r.ms, encodeMs: r.enc, roundTripMs: Date.now() - t0 }; },
hash: (n, w = 0) => pick(w).evaluate((f) => { window.FILM.seek(f); return window.FILM.hash(); }, n),
// motion-blurred frame: `samples` subframes averaged in the page (see hosts/page.ts blur)
- blur: async (n, samples, w = n) => { const t0 = Date.now(); const r = await pick(w).evaluate(([f, s]) => { const r = window.FILM.blur(f, s); const t = performance.now(); const png = window.FILM.png(); return { ...r, png, enc: performance.now() - t }; }, [n, samples]); return { png: Buffer.from(r.png, "base64"), shot: r.shot, drawMs: r.ms, encodeMs: r.enc, roundTripMs: Date.now() - t0 }; },
+ // `samples` is a count (a 360-degree shutter, as before) or a spec { samples: N | 0 (auto), shutter, max, px }
+ blur: async (n, samples, w = n) => { const t0 = Date.now(); const r = await pick(w).evaluate(([f, s]) => { const r = window.FILM.blur(f, s); const t = performance.now(); const png = window.FILM.png(); return { ...r, png, enc: performance.now() - t }; }, [n, samples]); return { png: Buffer.from(r.png, "base64"), shot: r.shot, drawMs: r.ms, encodeMs: r.enc, roundTripMs: Date.now() - t0, samples: r.samples, speed: r.speed }; },
// a frame of the poster dissolve (see hosts/page.ts poster): frame n with poster frame p over it
poster: async (n, p, fade, samples = 1, w = n) => { const t0 = Date.now(); const r = await pick(w).evaluate(([f, pf, fd, s]) => { const r = window.FILM.poster(f, pf, fd, s); const t = performance.now(); const png = window.FILM.png(); return { ...r, png, enc: performance.now() - t }; }, [n, p, fade, samples]); return { png: Buffer.from(r.png, "base64"), shot: r.shot, drawMs: r.ms, encodeMs: r.enc, roundTripMs: Date.now() - t0 }; },
posterHash: (n, p, fade, samples = 1, w = 0) => pick(w).evaluate(([f, pf, fd, s]) => { window.FILM.poster(f, pf, fd, s); return window.FILM.hash(); }, [n, p, fade, samples]),
diff --git a/skills/anidoodle/engine/tools/render.mjs b/skills/anidoodle/engine/tools/render.mjs
index 3811909..ebbdf63 100644
--- a/skills/anidoodle/engine/tools/render.mjs
+++ b/skills/anidoodle/engine/tools/render.mjs
@@ -1,10 +1,16 @@
// node tools/render.mjs <film> [--scale 1] [--workers 4] [--out out/x.mp4|.gif|.webm|.apng] [--gif-fps 15] [--width 640]
// [--blur N] [--from F] [--to F]
-// --blur N motion blur (N an integer >= 1): every output frame is the average of N subframes over
-// a one-frame shutter, integrated in linear light and weighted by alpha inside the page.
-// Fast pans and dolly moves stop juddering; held frames come out unchanged because their
-// subframes are identical. Stepped art (meta.step > 1 or onTwos) is NOT blurred: the
-// shutter would straddle two drawings. Costs N times the draw time. --blur 1 is untouched.
+// --blur N|auto motion blur: every output frame is the average of subframes spread over the shutter,
+// integrated in linear light and weighted by alpha inside the page. Fast pans and dolly
+// moves stop juddering. Stepped art (meta.step > 1 or onTwos) is NOT blurred: the shutter
+// would straddle two drawings. --blur 1 is untouched.
+// N: N subframes on every frame (costs N times the draw time).
+// auto: as many as the frame's own on-screen speed needs, measured per frame by block-
+// matching two sharp renders at the shutter's ends: subframes at most --blur-px apart
+// (default 3 px), 1 on a still frame (the sharp frame, untouched), at most --blur-max (32).
+// Deterministic: the count is a function of the frame's pixels.
+// --shutter DEG the shutter angle: 180 (default, film's standard: half the frame interval) to 360
+// (the whole interval, the old --blur behaviour). 180-240 reads as natural motion.
// --from/--to render only frames [from, to): for checking a passage, not for shipping. A range
// render is silent (the score would not line up), says so, and by default writes
// out/<film>.<from>-<to>.<ext> so it can never overwrite the finished film.
@@ -48,8 +54,11 @@ if (process.argv.includes("--shapes")) {
process.exit(0);
}
const film = requireFilm(process.argv[2], "render", "node tools/render.mjs <film> [--scale 1] [--out out/x.mp4|.gif|.webm|.apng] [--from F] [--to F] [--poster-frame N] [--blur N]");
-const BLUR = Number(arg("blur", 1));
-if (!Number.isInteger(BLUR) || BLUR < 1) { console.error(`--blur wants a whole number of subframes >= 1, got '${arg("blur")}'`); process.exit(2); }
+const BLUR = arg("blur", "1") === "auto" ? "auto" : Number(arg("blur", 1)), SHUTTER = Number(arg("shutter", 180)), BMAX = Number(arg("blur-max", 32)), BPX = Number(arg("blur-px", 3));
+if (BLUR !== "auto" && (!Number.isInteger(BLUR) || BLUR < 1)) { console.error(`--blur wants a whole number of subframes >= 1 or 'auto', got '${arg("blur")}'`); process.exit(2); }
+if (!(SHUTTER > 0 && SHUTTER <= 360)) { console.error(`--shutter wants an angle in (0, 360] degrees, got '${arg("shutter")}'`); process.exit(2); }
+if (!Number.isInteger(BMAX) || BMAX < 2 || !(BPX > 0)) { console.error(`--blur-max wants a whole number >= 2 and --blur-px a number > 0`); process.exit(2); }
+const BLURRED = BLUR === "auto" || BLUR > 1, BSPEC = BLUR === "auto" ? { samples: 0, shutter: SHUTTER, max: BMAX, px: BPX } : { samples: BLUR, shutter: SHUTTER };
const scale = Number(arg("scale", 1)), fmt = (arg("out", "").match(/\.(gif|webm|apng)$/i)?.[1] ?? "mp4").toLowerCase(), workers = Number(arg("workers", Math.max(1, Math.min(4, Math.floor(cpus().length / 2)))));
const HASHES = arg("hashes", null) ? new Map() : null;
const RANGE_ASKED = process.argv.includes("--from") || process.argv.includes("--to");
@@ -79,11 +88,11 @@ if (RANGE_ASKED && !ranged) console.log("range covers the whole film: rendering
if (POSTER !== null && POSTER >= N) { console.error(`--poster-frame ${POSTER} is outside the film; this film has frames 0-${N - 1}`); process.exit(2); }
if (POSTER !== null) console.log(`poster: frame 0 is frame ${POSTER}, dissolving into the opening by frame ${Math.max(1, FADE)}`);
const posterAt = (n) => POSTER !== null && n < Math.max(1, FADE); // frames the poster dissolve touches
-const drawAt = (n, w) => (posterAt(n) ? session.poster(n, POSTER, FADE, BLUR, w) : BLUR > 1 ? session.blur(n, BLUR, w) : session.frame(n, w));
+const drawAt = (n, w) => (posterAt(n) ? session.poster(n, POSTER, FADE, BLURRED ? BSPEC : 1, w) : BLURRED ? session.blur(n, BSPEC, w) : session.frame(n, w));
// a film whose cuts sit on its beat grid (meta.score.grid) must hear its score at that grid's tempo
if (meta.score?.grid && Math.abs(meta.score.tempo / meta.bpm - 1) > 0.005) { console.error(`render: the score plays at ${meta.score.tempo.toFixed(2)} bpm but this film's cuts sit on a ${meta.bpm} bpm grid (${((meta.score.tempo / meta.bpm - 1) * 100).toFixed(1)} %, limit 0.5 %): the cuts would drift off the downbeats. Play the score at the film's bpm and make the film whole bars of it (launchTemplate does), or compose a 1-bar stretch section`); process.exit(2); }
console.log(`film: "${meta.title}" ${meta.W}x${meta.H} @ ${meta.fps} fps, ${N} frames, ${meta.bpm} bpm, scale ${scale}, ${session.workers} page(s)`);
-if (BLUR > 1) console.log(`motion blur: ${BLUR} subframes per frame, one-frame shutter, linear light`);
+if (BLURRED) console.log(`motion blur: ${BLUR === "auto" ? `adaptive (subframes <= ${BPX} px apart, max ${BMAX})` : `${BLUR} subframes per frame`}, ${SHUTTER}-degree shutter, linear light`);
if (ranged) console.log(`range render: frames [${FROM}, ${TO}) of ${N}, silent by design`);
// audio: pure JS in the page -> WAV here (skipped for a range render: the score would not line up)
@@ -119,7 +128,7 @@ const done = new Promise((res, rej) => ff.on("close", (c) => (c ? rej(new Error(
const cost = [], pending = new Map(); let next, write;
const pump = async () => { while (pending.has(write)) { const b = pending.get(write); pending.delete(write); if (!ff.stdin.write(b)) await new Promise((r) => ff.stdin.once("drain", r)); write++; } };
next = FROM; write = FROM;
-await Promise.all(Array.from({ length: session.workers }, async (_, w) => { while (next < TO) { const n = next++; while (n - write > session.workers * 3) await new Promise((r) => setTimeout(r, 5)); const f = await drawAt(n, w); if (HASHES) HASHES.set(n, createHash("md5").update(f.png).digest("hex")); cost.push({ n, shot: f.shot, draw: f.drawMs, enc: f.encodeMs, rt: f.roundTripMs }); pending.set(n, f.png); await pump(); } }));
+await Promise.all(Array.from({ length: session.workers }, async (_, w) => { while (next < TO) { const n = next++; while (n - write > session.workers * 3) await new Promise((r) => setTimeout(r, 5)); const f = await drawAt(n, w); if (HASHES) HASHES.set(n, createHash("md5").update(f.png).digest("hex")); cost.push({ n, shot: f.shot, draw: f.drawMs, enc: f.encodeMs, rt: f.roundTripMs, samples: f.samples ?? 1 }); pending.set(n, f.png); await pump(); } }));
await pump(); ff.stdin.end(); await done;
const wall = (Date.now() - t0) / 1000;
if (HASHES) { const hf = resolve(arg("hashes")); mkdirSync(join(hf, ".."), { recursive: true }); writeFileSync(hf, [...HASHES].sort((a, b) => a[0] - b[0]).map(([n, h]) => `${n} ${h}`).join("\n") + "\n"); console.log(`frame hashes -> ${hf}`); }
@@ -130,15 +139,16 @@ console.log("\nframe cost (ms), draw = art core only, png = canvas PNG encode in
for (const id of [...new Set(cost.map((c) => c.shot))]) { const c = cost.filter((x) => x.shot === id), d = stat(c.map((x) => x.draw)), e = stat(c.map((x) => x.enc)); console.log(` ${id.padEnd(12)} draw median ${d.med.toFixed(0)} p95 ${d.p95.toFixed(0)} max ${d.max.toFixed(0)} | png median ${e.med.toFixed(0)} (${c.length} frames)`); }
const slow = [...cost].sort((a, b) => b.draw - a.draw).slice(0, 3).map((c) => `#${c.n} ${c.shot} ${c.draw.toFixed(0)}ms`).join(", ");
console.log(` slowest: ${slow}\n budget: 150 ms draw per frame -> ${cost.every((c) => c.draw <= 150) ? "PASS" : "OVER on " + cost.filter((c) => c.draw > 150).length + " frames"}`);
+if (BLUR === "auto") { const hist = {}; cost.forEach((c) => { const b = c.samples <= 1 ? "1" : c.samples <= 4 ? "2-4" : c.samples <= 8 ? "5-8" : c.samples <= 16 ? "9-16" : "17+"; hist[b] = (hist[b] ?? 0) + 1; }); console.log(` adaptive blur: subframes per frame ${Object.entries(hist).map(([k, v]) => `${k}: ${v}`).join(", ")} (mean ${(cost.reduce((a, c) => a + c.samples, 0) / cost.length).toFixed(1)}, max ${Math.max(...cost.map((c) => c.samples))})`); }
console.log(` wall clock: ${wall.toFixed(1)} s for ${TO - FROM} frames = ${((TO - FROM) / wall).toFixed(1)} fps end to end (build + launch + render + encode)`);
// ---- verify: same frame, different order, different page. Standard = visually identical; hash equality is the cheap first test.
const probe = [...new Set([0, ...meta.shots.flatMap((s) => [s.start, s.end - 1]), ...((k) => Array.from({ length: k }, (_, i) => Math.round(i * (N - 1) / (k - 1 || 1))))(Math.min(6, N)), N - 1])].filter((n) => n >= FROM && n < TO).sort((a, b) => a - b), fwd = [], rev = [];
if (!probe.length) probe.push(FROM);
-const hashOf = (n, w) => (posterAt(n) ? session.posterHash(n, POSTER, FADE, BLUR, w) : BLUR > 1 ? session.blurHash(n, BLUR, w) : session.hash(n, w)); // probe what was WRITTEN: poster dissolve, blurred frame
+const hashOf = (n, w) => (posterAt(n) ? session.posterHash(n, POSTER, FADE, BLURRED ? BSPEC : 1, w) : BLURRED ? session.blurHash(n, BSPEC, w) : session.hash(n, w)); // probe what was WRITTEN: poster dissolve, blurred frame
for (const n of probe) fwd.push(await hashOf(n, 0)); for (const n of [...probe].reverse()) rev.unshift(await hashOf(n, session.workers - 1));
const same = probe.filter((_, i) => fwd[i] === rev[i]).length;
-console.log(`\ndeterminism: ${same}/${probe.length} probe frames${BLUR > 1 ? ` (blurred, ${BLUR} subframes)` : ""} hash-identical (forward on page 0 vs reversed on page ${session.workers - 1})${same === probe.length ? "" : " -> fall back to PSNR > 45 dB in the Phase 2 gate"}`);
+console.log(`\ndeterminism: ${same}/${probe.length} probe frames${BLURRED ? ` (blurred, ${BLUR === "auto" ? "adaptive" : `${BLUR} subframes`}, ${SHUTTER} degrees)` : ""} hash-identical (forward on page 0 vs reversed on page ${session.workers - 1})${same === probe.length ? "" : " -> fall back to PSNR > 45 dB in the Phase 2 gate"}`);
await session.close();
const pr = execFileSync("ffprobe", ["-v", "error", "-show_entries", "stream=codec_type,codec_name,width,height,nb_frames,duration", "-of", "csv=p=0", out]).toString().trim().split("\n");
console.log(`\noutput: ${out}`); pr.forEach((l) => console.log(` ${l}`));