// Montage editing (`render.montage`, release 33 M3): the pure parts -- the // settings and their validation, where a phrase is said, the ramp, the cut // window, the pieces (punch-in, stutter), the cut styles, the counter, the // wall's layout and timing -- and real renders of a four-clip montage per // named style over synthetic lavfi clips: the length the plan says, to the // frame, and the flash, the counter, the year stamp, the whip and the wall // where they should be. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import test from "node:test"; import { counterText, CUT_FRAMES, cutStyleParts, DECLICK, formatClipDate, locatePhrase, montageOn, montageOverlayFilters, montagePieces, montagePiecesGraph, montageWindow, normalisePhrase, parseClipDate, piecesFrames, planMontage, platformLabel, rampCap, rampCaps, resolveMontage, safeText, stutters, tallyMarks, timedText, validateMontage, wallComposeArgs, wallPlan, wallTileClips, whisperWords, wallGroups, wallBeats, wallFirstGap, montageSplit, refineOnset, speechEnvelope, envelopeLag, WALL_SLIDE_FRAMES, bandFeatures, consensusLags, templateOnset, clipStream, distinctTileClips, wallCells, wallTileLabel, wallTileArgs, loudnessGain, parseIntegratedLoudness, levelFilters, nearSilent, median, relocateBySound, shiftAllowed, SILENT_LUFS, } from "./montage.mjs"; import { applyMontageStyle, MONTAGE_STYLE_NAMES, mergePatch } from "./montage-styles.mjs"; import { buildVideo, snap } from "./build-video.mjs"; import { lintManifest } from "./lint.mjs"; import { verifyBuild } from "./verify-build.mjs"; import { MONO_BOLD_FONT_FILE, MONO_FONT_FILE } from "./brand.mjs"; const PALETTE = { bg: "#15121c", fg: "#ece8f4", muted: "#9a93ad", accent: "#7c5cff", amber: "#f2b84b" }; const clip = (id, extra = {}) => ({ id, type: "clip", video: `v-${id}`, start: 10, end: 20, ...extra }); const manifest = (montage, timeline = [clip("c1"), clip("c2")], render = {}) => ({ render: { width: 1920, height: 1080, fps: 30, palette: PALETTE, ...render, montage }, timeline, }); // ---- settings and validation --------------------------------------------------- test("validateMontage: absent or null is off and says nothing; the named styles all validate", () => { assert.deepEqual(validateMontage({ render: {}, timeline: [] }), []); assert.deepEqual(validateMontage(manifest(null)), []); assert.equal(montageOn({}), false); assert.equal(montageOn({ montage: null }), false); assert.equal(montageOn({ montage: {} }), true); // Thirty clips: build-to-wall's exclusive wall takes twenty-five of them. const thirty = Array.from({ length: 30 }, (_, i) => clip(`s${i + 1}`)); for (const name of MONTAGE_STYLE_NAMES) { assert.deepEqual(validateMontage(applyMontageStyle(manifest(undefined, thirty), name)), [], name); } }); test("validateMontage: unknown keys and bad values are errors that say what is wrong", () => { const errs = (m, tl) => validateMontage(manifest(m, tl)); assert.match(errs([])[0], /render\.montage must be an object/); assert.match(errs({ tightn: "phrase" })[0], /render\.montage\.tightn is not a setting here \(the settings are tighten, phrasePad, /); assert.match(errs({ tighten: "word" })[0], /render\.montage\.tighten must be "phrase" or "sentence", not "word"/); assert.match(errs({ phrasePad: -1 })[0], /phrasePad must be a number from 0 to 5 seconds/); assert.match(errs({ cut: "wipe" })[0], /render\.montage\.cut must be "hard" or "flash" or "whip" or "dip", not "wipe"/); assert.match(errs({ flashColor: "red" })[0], /flashColor must be "white", "accent" or a #rrggbb colour/); assert.deepEqual(errs({ flashColor: "#ff8800" }), []); assert.match(errs({ counter: { style: "dial" } })[0], /counter\.style must be "chip" or "big" or "tally"/); assert.match(errs({ counter: { position: "middle" } })[0], /counter\.position must be "top-left"/); assert.match(errs({ counter: { of: "yes" } })[0], /counter\.of must be true or false/); assert.match(errs({ counter: { colour: 1 } })[0], /counter\.colour is not a setting here/); assert.match(errs({ counter: 3 })[0], /counter must be an object/); assert.match(errs({ punch: { scale: 1.2 } })[0], /punch\.mode must be "snap" or "drift", not undefined/); assert.match(errs({ punch: { mode: "snap", scale: 3 } })[0], /punch\.scale must be a number from 1 to 2/); assert.match(errs({ punch: { mode: "snap", anchor: "face" } })[0], /punch\.anchor must be "upper" or "center"/); assert.match(errs({ stutter: { times: 3 } })[0], /stutter needs `every` \(every Nth clip\) or `clips`/); assert.match(errs({ stutter: { every: 0 } })[0], /stutter\.every must be a whole number from 1/); assert.match(errs({ stutter: { every: 2, times: 5 } })[0], /stutter\.times must be 2, 3 or 4/); assert.match(errs({ stutter: { clips: ["c9"] } })[0], /stutter\.clips names "c9", which is not a clip in the timeline/); assert.deepEqual(errs({ stutter: { clips: ["c2"] } }), []); assert.match(errs({ stutter: { every: 2, length: 3 } })[0], /stutter\.length must be a number from 0\.1 to 1 seconds/); assert.match(errs({ ramp: { from: 4, to: 1 } })[0], /ramp trims around the phrase, so it needs render\.montage\.tighten "phrase"/); assert.match(errs({ tighten: "phrase", ramp: { from: 4 } })[0], /ramp\.to must be a number from 0\.5 to 60 seconds, not undefined/); assert.deepEqual(errs({ tighten: "phrase", ramp: { from: 4, to: 1 } }), []); assert.match(errs({ wall: { tiles: 12 } })[0], /wall\.tiles must be 9 or 16 or 25, not 12/); assert.match(errs({ wall: { at: "middle" } })[0], /wall\.at must be "end" or "start"/); assert.match(errs({ wall: { build: 0 } })[0], /wall\.build must be a number from 1 to 60/); assert.match(errs({ yearStamp: "yes" })[0], /yearStamp must be true or false/); }); test("validateMontage: what a montage does not combine with", () => { const deck = validateMontage(manifest({}, undefined, { chrome: { engine: "hyperframes", layout: "deck", deck: {} } })); assert.ok(deck.some((e) => /does not combine with render\.chrome \(the deck\)/.test(e)), deck.join("; ")); assert.match(validateMontage(manifest({}, undefined, { rail: { width: 300 } }))[0], /does not combine with render\.rail/); assert.match(validateMontage(manifest({}, undefined, { chromeEngine: "hyperframes" }))[0], /chromeEngine "hyperframes"/); assert.match( validateMontage(manifest({}, [clip("c1"), clip("c2", { muteFrom: 12 })]))[0], /^timeline\[1\] \(c2\)\.muteFrom is not supported under render\.montage/, ); }); test("the lint and a build's validators say it too", () => { const m = { slug: "x", title: "X", ...manifest({ cut: "wipe" }) }; const lint = lintManifest(m, { manifestDir: os.tmpdir(), exists: () => true }); assert.ok(lint.errors.some((e) => /render\.montage\.cut must be/.test(e)), lint.errors.join("; ")); }); test("resolveMontage: every default filled in; the accent flash is the palette's", () => { assert.equal(resolveMontage({}), null); const r = resolveMontage({ palette: PALETTE, montage: { flashColor: "accent", punch: { mode: "drift" }, stutter: { every: 3 }, wall: { tiles: 9 }, counter: {} } }); assert.equal(r.tighten, null); assert.equal(r.phrasePad, 0.6); assert.equal(r.cut, "hard"); assert.equal(r.flashColor, "#7c5cff"); assert.deepEqual(r.counter, { style: "chip", position: "top-left", of: false, showDate: true, showSource: false }); assert.deepEqual(r.punch, { mode: "drift", scale: 1.08, anchor: "upper" }); assert.deepEqual(r.stutter, { every: 3, clips: [], times: 3, length: 0.35, step: 0.04 }); assert.deepEqual(r.wall, { at: "end", tiles: 9, build: 6, year: false, groups: "single", sync: false, clips: "spread", exclusive: false, label: null, spread: null, distinct: false, }); assert.equal(resolveMontage({ montage: { wall: { groups: "double" } } }).wall.sync, true, "groups sync by default"); assert.equal(resolveMontage({ montage: { wall: { groups: "double", sync: false } } }).wall.sync, false); assert.deepEqual(resolveMontage({ montage: { ramp: { from: 3, into: "wall" } } }).ramp, { from: 3, to: undefined, into: "wall" }); assert.equal(r.ramp, null); assert.equal(r.yearStamp, false); assert.equal(resolveMontage({ montage: { punch: { mode: "snap" } } }).punch.scale, 1.15); assert.equal(resolveMontage({ montage: {} }).flashColor, "#ffffff"); }); // ---- the counter's words ---------------------------------------------------------- test("dates, sources and the counter text", () => { assert.deepEqual(parseClipDate("20190502"), { y: 2019, m: 5, d: 2 }); assert.deepEqual(parseClipDate("2019-05-02"), { y: 2019, m: 5, d: 2 }); assert.deepEqual(parseClipDate("2019-05-02T10:00:00Z"), { y: 2019, m: 5, d: 2 }); assert.equal(parseClipDate("May 2019"), null); assert.equal(parseClipDate("20191302"), null); assert.equal(parseClipDate(null), null); assert.equal(formatClipDate({ y: 2019, m: 5, d: 2 }), "2 May 2019"); assert.equal(formatClipDate(null), ""); assert.equal(platformLabel("youtube"), "YouTube"); assert.equal(platformLabel("RUMBLE"), "Rumble"); assert.equal(platformLabel("mystream"), "Mystream"); assert.equal(platformLabel(null), ""); assert.equal(safeText("it's 50% off: [now], ok?"), "its 50 off now ok"); assert.equal(safeText("#12 · 2 May 2019"), "#12 · 2 May 2019"); const date = { y: 2019, m: 5, d: 2 }; assert.deepEqual(counterText({ n: 12, date, platform: "youtube" }), { number: "#12", line: "2 May 2019" }); assert.deepEqual(counterText({ n: 12, of: 75, date, platform: "youtube", showSource: true }), { number: "#12 of 75", line: "2 May 2019 · YouTube" }); assert.deepEqual(counterText({ n: 3, date, showDate: false }), { number: "#3", line: "" }); }); // ---- where the phrase is said ------------------------------------------------------ const CUES = [ { start: 10, end: 12, text: "well folks it is a" }, { start: 12, end: 13.6, text: "slow news day again" }, { start: 13.6, end: 16, text: "and a slow news week" }, ]; test("timedText: the spans' characters spread over their spans, normalised, one space between", () => { const tt = timedText([{ start: 0, end: 1, text: "It's A" }, { start: 1, end: 2, text: "b,c" }]); assert.equal(tt.text, "its a b c "); assert.equal(tt.t0.length, tt.text.length); assert.equal(tt.t0[0], 0); assert.ok(Math.abs(tt.t0[4] - 5 / 6) < 1e-9, "the a is the 6th of the cue's 6 characters"); assert.equal(tt.t0[6], 1); assert.equal(normalisePhrase(" Slow News-Day! "), "slow news day"); }); test("locatePhrase: by character position inside its cue; across cues; the occurrence nearest `near`", () => { const a = locatePhrase("slow news day", CUES, { from: 10, to: 16 }); assert.equal(a.start, 12); assert.ok(Math.abs(a.end - (12 + (1.6 * 13) / 19)) < 1e-9, `end ${a.end}`); // Across a cue boundary: "it is a slow" spans cues one and two. const b = locatePhrase("it is a slow", CUES, { from: 10, to: 16 }); assert.ok(b.start > 10 && b.start < 12 && b.end > 12 && b.end < 13, JSON.stringify(b)); // Two occurrences of "slow news": the one nearest `near` wins. assert.equal(locatePhrase("slow news", CUES, { from: 10, to: 16, near: 12.5 }).start, 12); assert.ok(locatePhrase("slow news", CUES, { from: 10, to: 16, near: 15 }).start > 13.6); // Outside the window, or not said: null. assert.equal(locatePhrase("slow news day", CUES, { from: 0, to: 9 }), null); assert.equal(locatePhrase("fast news day", CUES, { from: 10, to: 16 }), null); assert.equal(locatePhrase("", CUES), null); // A whole-word match first; a phrase running on into a longer word only when there is none. const runOn = [{ start: 0, end: 2, text: "slow news days" }]; assert.ok(locatePhrase("slow news day", runOn)); assert.equal(locatePhrase("slow new", CUES, { from: 10, to: 16 }).start, 12, "a prefix of news"); assert.equal(locatePhrase("low news", CUES, { from: 10, to: 16 }), null, "never mid-word at the start"); }); test("whisperWords: whisper.cpp's token offsets as words; null for any other shape", () => { const doc = { transcription: [ { offsets: { from: 9000, to: 12000 }, tokens: [ { text: "[_BEG_]", offsets: { from: 9000, to: 9000 } }, { text: " slow", offsets: { from: 9100, to: 9400 } }, { text: " ne", offsets: { from: 9400, to: 9550 } }, { text: "ws", offsets: { from: 9550, to: 9700 } }, { text: " day", offsets: { from: 9700, to: 10100 } }, { text: "[_TT_500]", offsets: { from: 10100, to: 10100 } }, ], }, { tokens: [{ text: " far", offsets: { from: 90000, to: 90400 } }] }, ], }; assert.deepEqual(whisperWords(doc, 9, 11), [ { start: 9.1, end: 9.4, text: "slow" }, { start: 9.4, end: 9.7, text: "news" }, { start: 9.7, end: 10.1, text: "day" }, ]); assert.equal(whisperWords(doc).length, 4); assert.equal(whisperWords({ chunk_data: [] }), null); assert.equal(whisperWords({ cues: [] }), null); assert.equal(whisperWords(null), null); const words = whisperWords(doc, 9, 11); const hit = locatePhrase("slow news day", words, { from: 9, to: 11 }); assert.deepEqual({ start: hit.start, end: Number(hit.end.toFixed(6)) }, { start: 9.1, end: 10.1 }); }); // ---- the plan across the cut ----------------------------------------------------- test("rampCap: lerp(from, to, k/(n−1)) -- the first clip `from`, the last `to`, linear between", () => { const ramp = { from: 4, to: 1 }; assert.deepEqual(rampCaps(4, ramp), [4, 3, 2, 1]); assert.equal(rampCap(0, 1, ramp), 4); assert.equal(rampCap(3, 7, ramp), 2.5); assert.equal(rampCap(2, 4, null), null); }); test("planMontage: each clip's place, year change, stutter and edges; cards count as entries, not clips", () => { const timeline = [ { id: "t0", type: "card", seconds: 2 }, clip("a", { montage: { date: "20190102", platform: "youtube" } }), clip("b", { date: "2019-06-01" }), clip("c"), clip("d", { montage: { date: "20210101" } }), ]; const settings = resolveMontage({ montage: { tighten: "phrase", ramp: { from: 4, to: 1 }, stutter: { every: 2, clips: ["a"] } } }); const plan = planMontage(timeline, settings, (e) => (e.id === "c" ? "20200303" : null)); assert.deepEqual([...plan.keys()], ["a", "b", "c", "d"]); assert.deepEqual([...plan.values()].map((p) => p.k), [0, 1, 2, 3]); assert.deepEqual([...plan.values()].map((p) => p.n), [4, 4, 4, 4]); assert.deepEqual([...plan.values()].map((p) => p.cap), [4, 3, 2, 1]); assert.deepEqual([...plan.values()].map((p) => p.stutter), [true, true, false, true]); assert.deepEqual([...plan.values()].map((p) => p.year), [2019, 2019, 2020, 2021]); assert.deepEqual([...plan.values()].map((p) => p.yearChange), [true, false, true, true]); assert.equal(plan.get("a").platform, "youtube"); assert.equal(plan.get("a").first, false, "a card opens the cut"); assert.equal(plan.get("d").last, true); const walled = planMontage(timeline.slice(1), resolveMontage({ montage: { wall: { at: "end" } } })); assert.equal(walled.get("a").first, true); assert.equal(walled.get("d").last, false, "the wall closes the cut"); const atStart = planMontage(timeline.slice(1), resolveMontage({ montage: { wall: { at: "start" } } })); assert.equal(atStart.get("a").first, false); assert.equal(atStart.get("d").last, true); assert.deepEqual([...plan.values()].map((p) => [p.number, p.of]), [[1, 4], [2, 4], [3, 4], [4, 4]]); // A take of part of the cut: the clips keep their own numbers, and every-Nth stutter follows them. const part = planMontage( [clip("x", { montage: { n: 31, of: 75 } }), clip("y", { montage: { n: 32, of: 75 } })], resolveMontage({ montage: { stutter: { every: 2, clips: [] } } }), ); assert.deepEqual([...part.values()].map((p) => [p.k, p.number, p.of, p.stutter]), [[0, 31, 75, false], [1, 32, 75, true]]); assert.equal(stutters({ every: 5, clips: [] }, 4, "x"), true); assert.equal(stutters({ every: 5, clips: [] }, 5, "x"), false); assert.equal(stutters(null, 4, "x"), false); }); // ---- one clip's cut ------------------------------------------------------------------- const noSnap = () => ({ at: NaN, snapped: false }); test("montageWindow: the phrase ± pad, inside the extent; snapped edges kept only outside the phrase", () => { const sil = [{ s: 1.0, e: 1.5 }, { s: 4.0, e: 4.5 }]; const base = { extent: [0, 8], play: [0.5, 7], tighten: "phrase", pad: 0.6, cap: null, silences: sil, snapWindow: 0.4, render: {}, snap }; const w = montageWindow({ ...base, phrase: { start: 2, end: 3.1 } }); assert.equal(w.tight, true); assert.deepEqual(w.start, { at: 1.4, snapped: true }, "the silence's end, less the 0.10 s lead"); assert.deepEqual(w.end, { at: 4.18, snapped: true }, "the silence's start, plus 0.18 s"); assert.equal(w.cutA, 1.4); assert.equal(w.cutB, 4.18); // No silence near: the exact pads. const bare = montageWindow({ ...base, silences: [], phrase: { start: 2, end: 3.1 } }); assert.equal(bare.cutA, 1.4); assert.ok(Math.abs(bare.cutB - 3.7) < 1e-9); assert.equal(bare.start.snapped, false); // A snap that would land inside the phrase is refused. const inside = montageWindow({ ...base, pad: 0.1, silences: [{ s: 2.2, e: 2.6 }], phrase: { start: 2.5, end: 3.1 } }); assert.equal(inside.start.snapped, false); assert.equal(inside.cutA, 2.4); // Never past the extent. const edge = montageWindow({ ...base, extent: [1.8, 3.3], silences: [], phrase: { start: 2, end: 3.1 } }); assert.equal(edge.cutA, 1.8); assert.equal(edge.cutB, 3.3); }); test("montageWindow: under a ramp the pads are trimmed to the cap, never into the phrase", () => { const base = { extent: [0, 10], play: [0, 10], tighten: "phrase", pad: 2, silences: [], snapWindow: 0.4, render: {}, snap }; const w = montageWindow({ ...base, cap: 2, phrase: { start: 4, end: 5 } }); assert.ok(Math.abs(w.cutA - 3.5) < 1e-9 && Math.abs(w.cutB - 5.5) < 1e-9, JSON.stringify(w)); // One side short of pad: the other takes the room. const lop = montageWindow({ ...base, cap: 2, phrase: { start: 0.2, end: 1.2 } }); assert.ok(Math.abs(lop.cutA - 0) < 1e-9 && Math.abs(lop.cutB - 2) < 1e-9, JSON.stringify(lop)); // A phrase longer than the cap keeps the phrase. const long = montageWindow({ ...base, cap: 1, phrase: { start: 4, end: 6 } }); assert.equal(long.cutA, 4); assert.equal(long.cutB, 6); // A snap that would break the cap is refused. const snapped = montageWindow({ ...base, cap: 2, silences: [{ s: 6, e: 7 }], snapWindow: 1, phrase: { start: 4, end: 5 } }); assert.equal(snapped.end.snapped, false); assert.ok(snapped.cutB - snapped.cutA <= 2 + 1e-9); }); test("montageWindow: not tightening, or no phrase -- today's play window, snapped as every clip is", () => { const sil = [{ s: 1.0, e: 1.5 }, { s: 4.0, e: 4.5 }]; const want = (w0, w1) => { const a = snap(w0, sil, "start", 0.4, {}); const b = snap(w1, sil, "end", 0.4, {}); const cutA = Math.min(a.at, w1 - 1); return { cutA, cutB: Math.max(b.at, cutA + 1), start: a, end: b, tight: false }; }; const base = { extent: [0, 8], play: [1.3, 4.1], pad: 0.6, cap: null, silences: sil, snapWindow: 0.4, render: {}, snap }; assert.deepEqual(montageWindow({ ...base, tighten: "sentence", phrase: { start: 2, end: 3 } }), want(1.3, 4.1)); assert.deepEqual(montageWindow({ ...base, tighten: null, phrase: { start: 2, end: 3 } }), want(1.3, 4.1)); assert.deepEqual(montageWindow({ ...base, tighten: "phrase", phrase: null }), want(1.3, 4.1)); assert.deepEqual(montageWindow({ ...base, tighten: "phrase", phrase: { start: 9, end: 10 } }), want(1.3, 4.1), "outside the extent"); void noSnap; }); // ---- the pieces ------------------------------------------------------------------ test("montagePieces: one piece; a snap punch-in at the onset; a stutter of the phrase's end", () => { assert.deepEqual(montagePieces({ frames: 90, fps: 30 }), [{ f0: 0, f1: 90, zoom: 1 }]); const snapIn = montagePieces({ frames: 90, fps: 30, onset: 1, punch: { mode: "snap", scale: 1.15 } }); assert.deepEqual(snapIn, [{ f0: 0, f1: 30, zoom: 1 }, { f0: 30, f1: 90, zoom: 1.15 }]); // A drift has no pieces of its own (it zooms the whole segment). assert.deepEqual(montagePieces({ frames: 90, fps: 30, onset: 1, punch: { mode: "drift", scale: 1.08 } }), [{ f0: 0, f1: 90, zoom: 1 }]); const st = montagePieces({ frames: 90, fps: 30, onset: 1, phraseEnd: 2, punch: { mode: "snap", scale: 1.15 }, stutter: { times: 3, length: 0.35, step: 0.04 }, }); // Fragment = frames 49..60 (0.35 s = 10.5 → 11 frames) heard three times, each a step more zoomed. assert.deepEqual(st, [ { f0: 0, f1: 30, zoom: 1 }, { f0: 30, f1: 49, zoom: 1.15 }, { f0: 49, f1: 60, zoom: 1.15 }, { f0: 49, f1: 60, zoom: 1.196, repeat: 1 }, { f0: 49, f1: 60, zoom: 1.242, repeat: 2 }, { f0: 60, f1: 90, zoom: 1.15 }, ]); assert.equal(piecesFrames(st), 112); // No room for a fragment: no stutter. assert.deepEqual(montagePieces({ frames: 90, fps: 30, phraseEnd: 0.05, stutter: { times: 3, length: 0.35, step: 0 } }).length, 1); // Never outside the cut. assert.deepEqual(montagePieces({ frames: 30, fps: 30, phraseEnd: 5, stutter: { times: 2, length: 0.2, step: 0 } }), [ { f0: 0, f1: 24, zoom: 1 }, { f0: 24, f1: 30, zoom: 1 }, { f0: 24, f1: 30, zoom: 1, repeat: 1 }, ]); }); test("montagePiecesGraph: one piece is a straight run; pieces are split, trimmed, zoomed, joined; drift is a zoompan", () => { const box = { w: 320, h: 180 }; const one = montagePiecesGraph({ pieces: [{ f0: 0, f1: 90, zoom: 1 }], fps: 30, box, bg: "#000000" }); assert.equal(one.frames, 90); assert.equal(one.seconds, 3); assert.equal(one.v, "[mv]"); assert.equal(one.a, "[ma]"); assert.deepEqual(one.parts, [ "[0:v]fps=30[mvs0]", "[0:a]anull[mas0]", "[mvs0]trim=start_frame=0:end_frame=90,setpts=PTS-STARTPTS,scale=320:180:force_original_aspect_ratio=decrease,pad=320:180:(ow-iw)/2:(oh-ih)/2:color=#000000,setsar=1[mv0]", "[mas0]atrim=start=0:end=3,asetpts=PTS-STARTPTS[ma0]", "[mv0]null[mvc]", "[ma0]anull[mac]", "[mvc]tpad=stop_mode=clone:stop_duration=1,trim=end_frame=90,setpts=PTS-STARTPTS[mv]", `[mac]apad=whole_dur=3,atrim=end=3,afade=t=in:d=${DECLICK},afade=t=out:st=2.985:d=${DECLICK}[ma]`, ]); const two = montagePiecesGraph({ pieces: [{ f0: 0, f1: 30, zoom: 1 }, { f0: 30, f1: 90, zoom: 1.15 }], fps: 30, box, bg: "#000000" }); assert.equal(two.parts[0], "[0:v]fps=30,split=2[mvs0][mvs1]"); assert.equal(two.parts[1], "[0:a]asplit=2[mas0][mas1]"); assert.match(two.parts[4], /^\[mvs1\]trim=start_frame=30:end_frame=90,setpts=PTS-STARTPTS,crop=w='floor\(iw\/1\.15\/2\)\*2':h='floor\(ih\/1\.15\/2\)\*2':x='\(iw-ow\)\/2':y='\(ih-oh\)\*0\.35',scale=320:180/); assert.match(two.parts[5], /^\[mas1\]atrim=start=1:end=3,asetpts=PTS-STARTPTS,afade=t=in:d=0\.005,afade=t=out:st=1\.995:d=0\.005\[ma1\]$/); assert.equal(two.parts[6], "[mv0][ma0][mv1][ma1]concat=n=2:v=1:a=1[mvc][mac]"); const drift = montagePiecesGraph({ pieces: [{ f0: 0, f1: 90, zoom: 1 }], fps: 30, box, bg: "#000000", punch: { mode: "drift", scale: 1.08, anchor: "center" } }); assert.match(drift.parts.at(-2), /scale=640:360,zoompan=z='1\+0\.08\*on\/89':x='iw\/2-iw\/zoom\/2':y='\(ih-ih\/zoom\)\*0\.5':d=1:s=320x180:fps=30,setsar=1\[mv\]$/); const deaf = montagePiecesGraph({ pieces: [{ f0: 0, f1: 90, zoom: 1 }], fps: 30, box, bg: "#000000", inA: "[mpa]", hasVideo: false }); assert.equal(deaf.v, null); assert.ok(deaf.parts.every((p) => !p.includes("[0:v]"))); assert.equal(deaf.parts[0], "[mpa]anull[mas0]"); }); // ---- the cut styles ---------------------------------------------------------------- test("cutStyleParts: hard is nothing; flash fades in from the colour; dip to black and up; edges of the cut left alone", () => { const base = { frames: 90, fps: 30, w: 320, h: 180, inLabel: "[v]", outLabel: "[o]" }; assert.deepEqual(cutStyleParts({ ...base, cut: "hard", first: false, last: false }), ["[v]null[o]"]); assert.deepEqual(cutStyleParts({ ...base, cut: "flash", first: false, last: false, flashColor: "#ffffff" }), ["[v]fade=t=in:st=0:d=0.1:color=#ffffff[o]"]); assert.equal(CUT_FRAMES.flash, 3); assert.deepEqual(cutStyleParts({ ...base, cut: "flash", first: true, last: false }), ["[v]null[o]"], "nothing to cut from"); assert.deepEqual(cutStyleParts({ ...base, cut: "dip", first: false, last: false }), ["[v]fade=t=in:st=0:d=0.0667,fade=t=out:st=2.9:d=0.0667[o]"]); assert.deepEqual(cutStyleParts({ ...base, cut: "dip", first: true, last: false }), ["[v]fade=t=out:st=2.9:d=0.0667[o]"]); assert.deepEqual(cutStyleParts({ ...base, cut: "dip", first: true, last: true }), ["[v]null[o]"]); }); test("cutStyleParts: whip slides the first four frames in and the last four out, blurred along the move", () => { const base = { frames: 90, fps: 30, w: 320, h: 180, inLabel: "[v]", outLabel: "[o]", cut: "whip" }; const both = cutStyleParts({ ...base, first: false, last: false }); assert.equal(both[0], "[v]split=3[wph][wpb][wpt]"); assert.equal(both[1], "[wph]trim=end_frame=4,setpts=PTS-STARTPTS,split[wh1][wh2]"); assert.equal(both[2], "[wh1][wh2]hstack,crop=w=320:h=180:x='320*(1-0.9*pow(1-(n+1)/5,2))':y=0,avgblur=sizeX=11:sizeY=1[wh]"); assert.equal(both[3], "[wpb]trim=start_frame=4:end_frame=86,setpts=PTS-STARTPTS[wb]"); assert.equal(both[4], "[wpt]trim=start_frame=86,setpts=PTS-STARTPTS,split[wt1][wt2]"); assert.equal(both[5], "[wt1][wt2]hstack,crop=w=320:h=180:x='320*0.9*pow((n+1)/5,2)':y=0,avgblur=sizeX=11:sizeY=1[wt]"); assert.equal(both[6], "[wh][wb][wt]concat=n=3:v=1:a=0[o]"); const opening = cutStyleParts({ ...base, first: true, last: false }); assert.equal(opening[0], "[v]split=2[wpb][wpt]"); assert.equal(opening.at(-1), "[wb][wt]concat=n=2:v=1:a=0[o]"); assert.deepEqual(cutStyleParts({ ...base, first: true, last: true }), ["[v]null[o]"]); assert.deepEqual(cutStyleParts({ ...base, frames: 8, first: false, last: false }), ["[v]null[o]"], "too short to whip"); }); // ---- the counter and the year stamp ---------------------------------------------------- test("tallyMarks: four uprights struck through by the fifth, ten groups a row; the last mark is the newest", () => { const t = tallyMarks(7, 1080); assert.equal(t.marks.length, 7); assert.deepEqual(t.marks.map((m) => m.strike), [false, false, false, false, true, false, false]); assert.ok(t.marks[4].w > t.marks[4].h, "the strike lies across"); assert.ok(t.marks[5].x > t.marks[3].x, "the second group starts right of the first"); const many = tallyMarks(55, 1080); assert.ok(many.marks[50].y > many.marks[0].y, "the eleventh group starts a second row"); assert.ok(many.height > t.height); for (const m of many.marks) assert.ok(m.x >= 0 && m.x + m.w <= many.width && m.y + m.h <= many.height, JSON.stringify(m)); }); const RENDER_1080 = { width: 1920, height: 1080, fps: 30, palette: PALETTE }; const CTX = { k: 11, n: 75, date: { y: 2019, m: 5, d: 2 }, platform: "youtube", year: 2019, yearChange: true }; test("montageOverlayFilters: the chip -- one drawtext on its ground, in its corner", () => { const settings = resolveMontage({ montage: { counter: { style: "chip", of: true, showSource: true } } }); const f = montageOverlayFilters({ settings, ctx: CTX, render: RENDER_1080, font: "/f.ttf" }); assert.equal(f.length, 1); assert.match(f[0], /^drawtext=fontfile='\/f\.ttf':expansion=none:text='#12 of 75 · 2 May 2019 · YouTube':fontsize=37:fontcolor=#ece8f4:box=1:boxcolor=#15121c@0\.72:boxborderw=17:x=55:y=55$/); const br = montageOverlayFilters({ settings: resolveMontage({ montage: { counter: { position: "bottom-right" } } }), ctx: CTX, render: RENDER_1080, font: "/f.ttf" }); assert.match(br[0], /:x=W-55-text_w:y=H-55-text_h$/); }); test("montageOverlayFilters: big slams in and goes; tally draws k+1 marks, the newest late; the year stamp across from the counter", () => { const big = montageOverlayFilters({ settings: resolveMontage({ montage: { counter: { style: "big", position: "bottom-left" } } }), ctx: CTX, render: RENDER_1080, font: "/f.ttf" }); assert.equal(big.length, 2); assert.match(big[0], /text='12':fontsize='259\*\(1\+0\.9\*max\(0,1-t\/0\.18\)\)':fontcolor=#7c5cff/); assert.match(big[0], /alpha='min\(1,t\/0\.04\)\*if\(lt\(t,1\.2\),1,max\(0,1-\(t-1\.2\)\/0\.3\)\)'/); assert.match(big[1], /text='2 May 2019'/); const tally = montageOverlayFilters({ settings: resolveMontage({ montage: { counter: { style: "tally", showDate: false } } }), ctx: { ...CTX, k: 6 }, render: RENDER_1080, font: "/f.ttf" }); assert.equal(tally.length, 1 + 7, "the ground and seven marks"); assert.match(tally[0], /^drawbox=.*:color=#15121c@0\.6:t=fill$/); assert.ok(tally.slice(1, -1).every((d) => /color=#ece8f4:t=fill$/.test(d))); assert.match(tally.at(-1), /color=#7c5cff:t=fill:enable='gte\(t,0\.12\)'$/); const year = montageOverlayFilters({ settings: resolveMontage({ montage: { yearStamp: true, counter: { position: "top-left" } } }), ctx: CTX, render: RENDER_1080, font: "/f.ttf" }); assert.equal(year.length, 2); assert.match(year[1], /text='2019':fontsize=173:.*:x=W-38-text_w:y=38$/); assert.deepEqual(montageOverlayFilters({ settings: resolveMontage({ montage: { yearStamp: true } }), ctx: { ...CTX, yearChange: false }, render: RENDER_1080, font: "/f.ttf" }), []); assert.match(montageOverlayFilters({ settings: resolveMontage({ montage: { yearStamp: true } }), ctx: CTX, render: RENDER_1080, font: "/f.ttf" })[0], /x=W-38-text_w:y=38$/, "no counter: top right"); assert.deepEqual(montageOverlayFilters({ settings: resolveMontage({ montage: {} }), ctx: CTX, render: RENDER_1080, font: "/f.ttf" }), []); }); // ---- the wall ------------------------------------------------------------------------- test("wallTileClips: spread evenly first to last; fewer clips go round again", () => { assert.deepEqual(wallTileClips(["a", "b", "c", "d", "e", "f", "g", "h", "i"], 9), ["a", "b", "c", "d", "e", "f", "g", "h", "i"]); const ids = Array.from({ length: 75 }, (_, i) => `s${i + 1}`); const t = wallTileClips(ids, 16); assert.equal(t.length, 16); assert.equal(t[0], "s1"); assert.equal(t[15], "s75"); assert.equal(new Set(t).size, 16); assert.deepEqual(wallTileClips(["a", "b", "c"], 9), ["a", "b", "c", "a", "b", "c", "a", "b", "c"]); assert.deepEqual(wallTileClips([], 9), []); }); test("wallPlan: a centred grid inside the frame; tiles come faster and faster; the beat; all on frames", () => { const p = wallPlan({ tiles: 16, build: 8, durations: Array(16).fill(1.2), fps: 30, width: 1920, height: 1080 }); assert.equal(p.cols, 4); assert.equal(p.layout.length, 16); for (const l of p.layout) assert.ok(l.x >= 0 && l.y >= 0 && l.x + l.w <= 1920 && l.y + l.h <= 1080, JSON.stringify(l)); assert.equal(p.tileW % 2, 0); assert.equal(p.tileH % 2, 0); assert.ok(Math.abs(p.tileW / p.tileH - 16 / 9) < 0.02); assert.equal(p.layout[1].x - p.layout[0].x, p.tileW + p.gap); assert.equal(p.appear[0], 0); const gaps = p.appear.slice(1).map((t, i) => t - p.appear[i]); for (let i = 1; i < gaps.length; i += 1) assert.ok(gaps[i] <= gaps[i - 1] + 1e-9, `gaps shrink: ${gaps}`); assert.ok(p.appear.at(-1) < p.beat); assert.equal(p.beat, 8); assert.equal(p.beatLen, Math.round((1.2 + 0.25) * 30) / 30); assert.equal(p.frames, 240 + Math.round(1.45 * 30)); assert.equal(p.seconds, p.frames / 30); for (const f of p.appearFrames) assert.ok(Number.isInteger(f)); // The beat is the longest phrase, held to 0.8–2.5 s. assert.equal(wallPlan({ tiles: 9, build: 4, durations: [9], fps: 30, width: 1920, height: 1080 }).beatLen, Math.round(2.75 * 30) / 30); assert.equal(wallPlan({ tiles: 25, build: 4, durations: [0.1], fps: 30, width: 1920, height: 1080 }).cols, 5); }); test("wallComposeArgs: each tile appears, plays, freezes and plays again at the beat; the newest up, the rest ducked; exactly its frames", () => { const plan = wallPlan({ tiles: 9, build: 3, durations: Array(9).fill(1), fps: 30, width: 320, height: 180 }); const tiles = Array.from({ length: 9 }, (_, i) => ({ file: `/t/${i}.mp4`, seconds: 1 })); const settings = resolveMontage({ montage: { cut: "flash", wall: { tiles: 9 } } }); const args = wallComposeArgs({ tiles, plan, render: { width: 320, height: 180, fps: 30, palette: PALETTE }, settings, first: false, last: true, encode: ["-c:v", "libx264"], outPath: "/o.mp4" }); const graph = args[args.indexOf("-filter_complex") + 1]; assert.equal(args.filter((a) => a === "-i").length, 9); assert.match(graph, /\[0:v\]split\[wv0a\]\[wv0b\]/); assert.match(graph, new RegExp(`tpad=start_duration=${plan.appear[4].toFixed(4).replace(/0+$/, "").replace(/\.$/, "")}:start_mode=add:color=#15121c`)); assert.match(graph, /xstack=inputs=9:layout=0_0\|/); assert.match(graph, /volume='if\(lt\(t,[\d.]+\),1,0\.22\)':eval=frame/); assert.match(graph, /amix=inputs=18:normalize=0:duration=longest,alimiter=limit=0\.9/); assert.match(graph, /fade=t=in:st=0:d=0\.1:color=#ffffff\[v\]/, "the cut into the wall flashes"); assert.equal(args[args.indexOf("-frames:v") + 1], String(plan.frames)); }); // ---- real renders --------------------------------------------------------------------- const have = ["ffmpeg", "ffprobe"].every((b) => spawnSync(b, ["-version"]).status === 0); const FPS = 30; const RENDER = { width: 320, height: 180, fps: FPS, audioRate: 48000, audioChannels: 2, preset: "ultrafast", transition: 0, headerHeight: 0, qr: false, palette: PALETTE, fontRegular: MONO_FONT_FILE, fontBold: MONO_BOLD_FONT_FILE, snapWindow: 0.4, silenceMinDur: 0.1, }; /** * Four six-second clips: mid grey with a white bar at x 40–60 (something for * a whip to move), and a tone that sounds 1 s in every 1.5 (silences to snap * to). Their cues say "slow news day" from 2.0 s; the years run 2019–2022. */ async function fixture(montage, { extraRender = {}, amp = () => 0.5 } = {}) { const root = await mkdtemp(path.join(os.tmpdir(), "rtv-montage-")); await mkdir(path.join(root, "media"), { recursive: true }); const timeline = []; for (let i = 1; i <= 4; i += 1) { const file = path.join(root, "media", `c${i}.mp4`); const r = spawnSync("ffmpeg", [ "-v", "error", "-y", "-f", "lavfi", "-i", `color=c=0x808080:s=320x180:r=${FPS}:d=6`, "-f", "lavfi", "-i", `aevalsrc='${amp(i)}*sin(2*PI*${300 + 40 * i}*t)*between(mod(t,1.5),0,1.0)':s=48000:d=6`, "-vf", "drawbox=x=40:y=0:w=20:h=180:color=white:t=fill", "-c:v", "libx264", "-preset", "ultrafast", "-c:a", "aac", "-shortest", file, ]); assert.equal(r.status, 0, String(r.stderr)); await writeFile(path.join(root, "media", `c${i}.json`), JSON.stringify({ cues: [ { start: 0.2, end: 2.0, text: "well folks it is a" }, { start: 2.0, end: 3.6, text: "slow news day again" }, { start: 3.6, end: 5.8, text: "and here we go" }, ], })); timeline.push({ id: `c${i}`, type: "clip", src: `media/c${i}.mp4`, cues: `media/c${i}.json`, start: 0.2, end: 5.8, title: `Clip ${i}`, channelTitle: "Demo", montage: { n: i, date: `20${18 + i}0${i}0${i}`, platform: "youtube", match: "slow news day", speakerCheck: false }, }); } const manifestPath = path.join(root, "video.manifest.json"); await writeFile(manifestPath, JSON.stringify({ slug: "demo", title: "Demo", render: { ...RENDER, ...extraRender, montage }, timeline, })); return { root, manifestPath }; } function framesOf(file) { const r = spawnSync("ffprobe", ["-v", "error", "-count_frames", "-select_streams", "v:0", "-show_entries", "stream=nb_read_frames", "-of", "csv=p=0", file]); assert.equal(r.status, 0, String(r.stderr)); return Number(String(r.stdout).trim()); } /** A signalstats value (YAVG: mean luma 0–255; YHIGH: its 90th percentile) of frame `n` of `file` inside a crop `w:h:x:y`. */ function luma(file, n, crop, key = "YAVG") { const r = spawnSync("ffmpeg", [ "-v", "error", "-i", file, "-vf", `select='eq(n,${n})',crop=${crop},signalstats,metadata=print:key=lavfi.signalstats.${key}:file=-`, "-frames:v", "1", "-f", "null", "-", ]); assert.equal(r.status, 0, String(r.stderr)); const m = String(r.stdout).match(new RegExp(`${key}=([\\d.]+)`)); assert.ok(m, `no ${key} for frame ${n}`); return Number(m[1]); } /** Mean U (chroma blue, 128 neutral) of frame `n` inside a crop. */ function chromaU(file, n, crop) { const r = spawnSync("ffmpeg", [ "-v", "error", "-i", file, "-vf", `select='eq(n,${n})',crop=${crop},signalstats,metadata=print:key=lavfi.signalstats.UAVG:file=-`, "-frames:v", "1", "-f", "null", "-", ]); assert.equal(r.status, 0, String(r.stderr)); return Number(String(r.stdout).match(/UAVG=([\d.]+)/)[1]); } /** The cut records' planned frames, per clip in order, and their sum (+ the wall's). */ async function planned(root, ids, wall = false) { const seg = path.join(root, "out", "sourced", "segments"); const recs = await Promise.all(ids.map(async (id) => JSON.parse(await readFile(path.join(seg, `${id}.cut.json`), "utf8")))); const frames = recs.map((r) => r.montage.frames); const wallFrames = wall ? JSON.parse(await readFile(path.join(seg, "montage-wall.cut.json"), "utf8")).montageWall.frames : 0; return { recs, frames, total: frames.reduce((a, b) => a + b, 0) + wallFrames, wallFrames }; } const IDS = ["c1", "c2", "c3", "c4"]; const styled = (name, patch = {}) => mergePatch(applyMontageStyle({ render: {} }, name).render.montage, patch); test("render: without render.montage (absent or null) the cut is byte for byte the same", { skip: !have && "needs ffmpeg" }, async () => { const a = await fixture(undefined); const b = await fixture(null); try { await buildVideo({ manifestPath: a.manifestPath, opts: { noNetwork: true } }); await buildVideo({ manifestPath: b.manifestPath, opts: { noNetwork: true } }); const md5 = (f) => spawnSync("md5sum", [f]).stdout.toString().split(" ")[0]; for (const f of ["demo.mp4", "sourced/segments/c2.mp4"]) { assert.equal(md5(path.join(a.root, "out", f)), md5(path.join(b.root, "out", f)), f); } const rec = JSON.parse(await readFile(path.join(a.root, "out", "sourced", "segments", "c1.cut.json"), "utf8")); assert.equal(rec.montage, undefined, "no montage in the cut record"); } finally { await rm(a.root, { recursive: true, force: true }); await rm(b.root, { recursive: true, force: true }); } }); test("render: straight -- each clip cut to its phrase, the length the plan says to the frame, the chip on the picture", { skip: !have && "needs ffmpeg" }, async () => { const { root, manifestPath } = await fixture(styled("straight")); try { const r = await buildVideo({ manifestPath, opts: { noNetwork: true } }); const p = await planned(root, IDS); for (const rec of p.recs) { assert.equal(rec.montage.found, "cues"); assert.equal(rec.montage.tight, true); // Phrase 2.0–3.095 ± 0.6, snapped to the silences at 1.5 and 4.0. assert.deepEqual([rec.start, rec.end], [1.4, 4.18]); assert.deepEqual(rec.montage.phrase, [2, 3.095]); assert.equal(rec.montage.frames, 83); } for (const id of IDS) assert.equal(framesOf(path.join(root, "out", "sourced", "segments", `${id}.mp4`)), 83, id); assert.ok(Math.abs(framesOf(r.out) - p.total) <= 1, `${framesOf(r.out)} vs ${p.total}`); // The chip's ground darkens the grey top-left; the bottom-left is untouched. assert.ok(luma(r.out, 100, "40:8:8:8") < 110, "chip ground"); assert.ok(Math.abs(luma(r.out, 100, "60:20:200:150") - 128) < 8, "plain grey elsewhere"); } finally { await rm(root, { recursive: true, force: true }); } }); test("render: flash-count -- a white flash on the cut, not before; the big number slams in in the accent", { skip: !have && "needs ffmpeg" }, async () => { const { root, manifestPath } = await fixture(styled("flash-count")); try { const r = await buildVideo({ manifestPath, opts: { noNetwork: true } }); const p = await planned(root, IDS); assert.ok(Math.abs(framesOf(r.out) - p.total) <= 1); const cut = p.frames[0]; assert.ok(luma(r.out, cut, "100:60:200:20") > 225, "the first frame of clip 2 is the flash"); assert.ok(luma(r.out, cut - 1, "100:60:200:20") < 140, "the frame before the cut is not"); assert.ok(luma(r.out, cut + 4, "100:60:200:20") < 140, "and it is gone by the fourth frame"); assert.ok(luma(r.out, 0, "100:60:200:20") < 140, "the cut's first clip opens without one"); // The number, in the accent (blue-heavy), bottom-left early in the clip -- gone by 1.6 s. assert.ok(chromaU(r.out, cut + 12, "40:40:6:130") > 134, "the accent number"); assert.ok(Math.abs(chromaU(r.out, cut + 60, "40:40:6:130") - 128) < 3, "gone"); } finally { await rm(root, { recursive: true, force: true }); } }); test("render: accelerate -- the cuts shorten along the ramp, drift, tally marks; length to the frame", { skip: !have && "needs ffmpeg" }, async () => { const { root, manifestPath } = await fixture(styled("accelerate", { ramp: { from: 2.6, to: 1.2 } })); try { const r = await buildVideo({ manifestPath, opts: { noNetwork: true } }); const p = await planned(root, IDS); const caps = rampCaps(4, { from: 2.6, to: 1.2 }); p.recs.forEach((rec, k) => { assert.ok(rec.end - rec.start <= caps[k] + 0.002, `${rec.id}: ${rec.end - rec.start} > ${caps[k]}`); assert.ok(rec.start <= 2.0 && rec.end >= 3.095, `${rec.id} keeps the phrase`); }); for (let k = 1; k < 4; k += 1) assert.ok(p.frames[k] < p.frames[k - 1], `shorter: ${p.frames}`); assert.ok(Math.abs(framesOf(r.out) - p.total) <= 1); // The fourth clip's tally: its newest mark lands at 0.12 s. const at = p.frames[0] + p.frames[1] + p.frames[2]; const t = tallyMarks(4, 180); const pad = Math.round(180 * 0.012); const m = Math.round(180 * 0.035); const nm = t.marks[3]; const crop = `${nm.w}:${nm.h}:${m + pad + nm.x}:${m + pad + nm.y}`; assert.ok(luma(r.out, at + 8, crop) > luma(r.out, at, crop) + 15, "the newest mark is drawn at 0.12 s"); } finally { await rm(root, { recursive: true, force: true }); } }); test("render: stutter -- the stuttered clip is longer by its repeats; snap punch-in at the onset", { skip: !have && "needs ffmpeg" }, async () => { const { root, manifestPath } = await fixture(styled("stutter", { stutter: { every: null, clips: ["c2"] } })); try { const r = await buildVideo({ manifestPath, opts: { noNetwork: true } }); const p = await planned(root, IDS); const c2 = p.recs[1].montage; const repeats = c2.pieces.filter((x) => x.repeat); assert.equal(repeats.length, 2, "heard three times"); const frag = repeats[0].f1 - repeats[0].f0; assert.equal(frag, Math.round(0.35 * FPS)); assert.equal(c2.frames, 83 + 2 * frag); assert.equal(p.recs[0].montage.pieces.filter((x) => x.repeat).length, 0); assert.equal(framesOf(path.join(root, "out", "sourced", "segments", "c2.mp4")), c2.frames); assert.ok(Math.abs(framesOf(r.out) - p.total) <= 1); // The punch-in: the bar (x 40–60) moves outward and widens at the onset (0.6 s in). const seg = path.join(root, "out", "sourced", "segments", "c1.mp4"); assert.ok(luma(seg, 5, "12:120:44:50") > 230, "before the onset the bar is where it was"); assert.ok(luma(seg, 40, "6:120:30:50") > 200, "after it the bar has moved left, as a zoom from the centre moves it"); } finally { await rm(root, { recursive: true, force: true }); } }); test("render: wall-finale -- a wall segment after the clips, every tile filled at the end; length to the frame", { skip: !have && "needs ffmpeg" }, async () => { const { root, manifestPath } = await fixture(styled("wall-finale", { wall: { tiles: 9, build: 2 } })); try { const r = await buildVideo({ manifestPath, opts: { noNetwork: true } }); const p = await planned(root, IDS, true); assert.ok(p.wallFrames > 60); assert.ok(Math.abs(framesOf(r.out) - p.total) <= 1, `${framesOf(r.out)} vs ${p.total}`); const plan = wallPlan({ tiles: 9, build: 2, durations: [1], fps: FPS, width: 320, height: 180 }); const start = p.total - p.wallFrames; const last = plan.layout[8]; const tile = `${last.w - 4}:${last.h - 4}:${last.x + 2}:${last.y + 2}`; // The last tile is ground at the wall's start and footage (grey, with the // year) by the beat. assert.ok(luma(r.out, start + 2, tile) < 40, "empty at first"); assert.ok(luma(r.out, p.total - 3, tile) > 100, "filled by the end"); const wall = JSON.parse(await readFile(path.join(root, "out", "sourced", "segments", "montage-wall.cut.json"), "utf8")); assert.deepEqual(wall.montageWall.tiles, ["c1", "c2", "c3", "c4", "c1", "c2", "c3", "c4", "c1"]); // The chapters name it. const ch = spawnSync("ffprobe", ["-v", "error", "-show_chapters", "-of", "json", r.out]); const titles = JSON.parse(String(ch.stdout)).chapters.map((c) => c.tags?.title); assert.equal(titles.length, 5); assert.equal(titles.at(-1), "All together"); // verify-build counts the wall's chapter, and a phrase cut's length is no shortfall. const v = await verifyBuild(manifestPath); assert.deepEqual(v.problems, []); } finally { await rm(root, { recursive: true, force: true }); } }); test("render: whip-years -- the bar slides at the cut; the year large across from the chip", { skip: !have && "needs ffmpeg" }, async () => { const { root, manifestPath } = await fixture(styled("whip-years")); try { const r = await buildVideo({ manifestPath, opts: { noNetwork: true } }); const p = await planned(root, IDS); assert.ok(Math.abs(framesOf(r.out) - p.total) <= 1); const cut = p.frames[0]; // Mid-clip the bar is at x 40–60; on the incoming whip's first frame it has // been carried right (shifted ~0.58 of the width), blurred. assert.ok(luma(r.out, cut - 30, "16:40:42:120") > 230, "the bar where it is"); assert.ok(luma(r.out, cut, "16:40:42:120") < 200, "gone from there on the whip"); assert.ok(luma(r.out, cut, "60:40:200:120") > luma(r.out, cut - 30, "60:40:200:120") + 4, "carried right, smeared"); // The year stamp: top right, early in each clip (every clip is a new year), gone by 1.4 s. assert.ok(luma(r.out, cut + 10, "80:30:236:6", "YHIGH") > 200, "the year"); assert.ok(luma(r.out, cut + 45, "80:30:236:6", "YHIGH") < 140, "then not"); } finally { await rm(root, { recursive: true, force: true }); } }); test("render: dip -- two frames to black before the cut, two up from it", { skip: !have && "needs ffmpeg" }, async () => { const { root, manifestPath } = await fixture({ tighten: "phrase", cut: "dip" }); try { const r = await buildVideo({ manifestPath, opts: { noNetwork: true } }); const p = await planned(root, IDS); const cut = p.frames[0]; const box = "100:60:200:20"; assert.ok(luma(r.out, cut - 1, box) < 30, "the last frame before the cut is black"); assert.ok(luma(r.out, cut, box) < 30, "and the first after it"); assert.ok(luma(r.out, cut + 3, box) > 110, "then the picture"); assert.ok(luma(r.out, cut - 4, box) > 110, "and before the dip"); assert.ok(Math.abs(framesOf(r.out) - p.total) <= 1); } finally { await rm(root, { recursive: true, force: true }); } }); // ---- release 33 wall-sync: groups, sync, tail, exclusive, the ramp into the wall ------------- test("validateMontage: the wall's groups, sync, clips, exclusive; the ramp into the wall", () => { const errs = (m, tl) => validateMontage(manifest(m, tl)); assert.match(errs({ wall: { groups: "triple" } })[0], /wall\.groups must be "single" or "double", not "triple"/); assert.match(errs({ wall: { clips: "head" } })[0], /wall\.clips must be "spread" or "tail", not "head"/); assert.match(errs({ wall: { sync: 1 } })[0], /wall\.sync must be true or false/); assert.match(errs({ wall: { exclusive: "yes" } })[0], /wall\.exclusive must be true or false/); assert.match(errs({ tighten: "phrase", ramp: { from: 3, into: "end" }, wall: {} })[0], /ramp\.into must be "wall", not "end"/); assert.match(errs({ tighten: "phrase", ramp: { from: 3, into: "wall" } })[0], /ramp\.into "wall" needs render\.montage\.wall/); assert.deepEqual(errs({ tighten: "phrase", ramp: { from: 3, into: "wall" }, wall: {} }), [], "no `to` needed"); assert.match(errs({ tighten: "phrase", ramp: { from: 3 } })[0], /ramp\.to must be a number/, "without into, `to` is needed"); const eleven = Array.from({ length: 11 }, (_, i) => clip(`s${i + 1}`)); assert.match( errs({ wall: { tiles: 9, clips: "tail", exclusive: true } }, eleven.slice(0, 10))[0], /wall\.exclusive takes the wall's 9 clip\(s\) out of the cut, leaving 1 — it needs at least 2 clips outside the wall/, ); assert.deepEqual(errs({ wall: { tiles: 9, clips: "tail", exclusive: true } }, eleven), []); assert.match(errs({ wall: { tiles: 9, exclusive: true } }, eleven.slice(0, 4))[0], /leaving 0/, "fewer clips than tiles: all of them are tiles"); }); test("wallGroups: 1, 1, 2, 4, 8 … and the leftover", () => { assert.deepEqual(wallGroups(16, "double"), [1, 1, 2, 4, 8]); assert.deepEqual(wallGroups(9, "double"), [1, 1, 2, 5]); assert.deepEqual(wallGroups(25, "double"), [1, 1, 2, 4, 8, 9]); assert.deepEqual(wallGroups(4, "single"), [1, 1, 1, 1]); for (const n of [9, 16, 25]) assert.equal(wallGroups(n, "double").reduce((a, b) => a + b), n); }); test("wallBeats: single is today's arrivals; double's gaps fall evenly to half the first and sum to the build", () => { const single = wallBeats({ tiles: 16, build: 8 }); single.beats.forEach((b, i) => assert.equal(b, 8 * (1 - (1 - i / 16) ** 2))); const d = wallBeats({ tiles: 25, build: 7.5, groups: "double" }); assert.deepEqual(d.sizes, [1, 1, 2, 4, 8, 9]); assert.equal(d.beats[0], 0); assert.ok(Math.abs(d.gaps.reduce((a, b) => a + b) - 7.5) < 1e-9); assert.ok(Math.abs(d.gaps[0] - 7.5 / 4.5) < 1e-9); assert.ok(Math.abs(d.gaps.at(-1) - d.gaps[0] / 2) < 1e-9); for (let i = 1; i < d.gaps.length; i += 1) assert.ok(d.gaps[i] < d.gaps[i - 1]); assert.equal(wallFirstGap({ tiles: 25, build: 7.5, groups: "double" }), d.gaps[0]); assert.equal(wallFirstGap({ tiles: 16, build: 8, groups: "single" }), single.gaps[0]); assert.deepEqual(wallBeats({ tiles: 1, build: 3, groups: "double" }).gaps, [3]); }); test("montageSplit: spread or tail; an exclusive wall takes its clips out of the run, in order", () => { const tl = [{ id: "t0", type: "card" }, ...Array.from({ length: 12 }, (_, i) => clip(`s${i + 1}`))]; const r = (wall) => montageSplit(tl, resolveMontage({ montage: { wall } })); const spread = r({ tiles: 9 }); assert.equal(spread.wall.length, 9); assert.equal(spread.wallOnly.size, 0); assert.equal(spread.linear.length, 12); const tail = r({ tiles: 9, clips: "tail" }); assert.deepEqual(tail.wall, ["s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12"], "the latest nine, in date order"); assert.equal(tail.wallOnly.size, 0); const excl = r({ tiles: 9, clips: "tail", exclusive: true }); assert.deepEqual(excl.linear, ["s1", "s2", "s3"]); assert.deepEqual([...excl.wallOnly], tail.wall); assert.deepEqual(montageSplit(tl, resolveMontage({ montage: {} })).wall, []); }); test("planMontage under an exclusive tail wall: the run is numbered, ramped and edged on its own", () => { const tl = Array.from({ length: 12 }, (_, i) => clip(`s${i + 1}`, { montage: { date: `20${10 + i}0101` } })); const settings = resolveMontage({ montage: { tighten: "phrase", ramp: { from: 3.5, into: "wall" }, wall: { tiles: 9, build: 4, groups: "double", clips: "tail", exclusive: true } }, }); const plan = planMontage(tl, settings); const run = ["s1", "s2", "s3"].map((id) => plan.get(id)); assert.deepEqual(run.map((p) => p.k), [0, 1, 2]); assert.deepEqual(run.map((p) => p.n), [3, 3, 3]); assert.deepEqual(run.map((p) => p.number), [1, 2, 3], "the counter runs to N − tiles"); assert.deepEqual(run.map((p) => p.of), [3, 3, 3]); assert.equal(run[0].cap, 3.5); assert.ok(Math.abs(run[2].cap - wallFirstGap(settings.wall)) < 1e-9, "the last cut meets the wall's first gap"); assert.equal(run[0].first, true); assert.equal(run[2].last, false, "the wall follows"); for (const id of ["s4", "s12"]) { assert.equal(plan.get(id).wallOnly, true); assert.equal(plan.get(id).k, undefined); } assert.equal(plan.get("s12").year, 2021); // The clips' own montage.n still wins (a take of part of the cut). const own = planMontage(tl.map((e, i) => ({ ...e, montage: { ...e.montage, n: i + 1 } })), settings); assert.deepEqual(["s1", "s2", "s3"].map((id) => own.get(id).number), [1, 2, 3]); // Not exclusive: every clip runs, and the ramp ends at `to`. const all = planMontage(tl, resolveMontage({ montage: { tighten: "phrase", ramp: { from: 3, to: 1 }, wall: { tiles: 9, clips: "tail" } } })); assert.equal(all.size, 12); assert.equal(all.get("s12").cap, 1); }); test("wallPlan grouped and synced: a group shows its lead before its beat, so every onset lands on it; the crowd on one frame", () => { const leads = Array.from({ length: 9 }, (_, i) => (i === 3 ? 0.05 : 0.12)); const p = wallPlan({ tiles: 9, build: 4, durations: Array(9).fill(1.2), fps: 30, width: 320, height: 180, groups: "double", leads }); assert.equal(p.grouped, true); assert.deepEqual(p.groups, [1, 1, 2, 5]); assert.deepEqual(p.groupOf, [0, 1, 2, 2, 3, 3, 3, 3, 3]); assert.equal(Math.min(...p.appearFrames), 0, "the earliest show is the wall's first frame"); p.appearFrames.forEach((f, i) => { assert.ok(Number.isInteger(f)); assert.equal(f + Math.round(leads[i] * 30), p.groupBeatFrames[p.groupOf[i]], `tile ${i}'s onset on its group's beat`); assert.equal(p.restartFrames[i] + Math.round(leads[i] * 30), p.beatFrames, `tile ${i}'s onset on the final beat`); }); assert.equal(p.groupBeatFrames[1] - p.groupBeatFrames[0], Math.round(4 / 3 * 30)); assert.equal(p.beatFrames - p.groupBeatFrames[0], 120); assert.equal(p.seconds, p.frames / 30); // Unsynced groups: tiles show on the beat itself. const u = wallPlan({ tiles: 16, build: 6, durations: Array(16).fill(1), fps: 30, width: 1920, height: 1080, groups: "double" }); assert.deepEqual(u.appearFrames.slice(0, 4), [0, u.groupBeatFrames[1], u.groupBeatFrames[2], u.groupBeatFrames[2]]); assert.deepEqual(u.restartFrames, Array(16).fill(u.beatFrames)); // Single, unsynced: today's plan, field for field. const today = wallPlan({ tiles: 9, build: 3, durations: Array(9).fill(1), fps: 30, width: 320, height: 180 }); assert.equal(today.grouped, undefined); assert.deepEqual(wallPlan({ tiles: 9, build: 3, durations: Array(9).fill(1), fps: 30, width: 320, height: 180, groups: "single", leads: null }), today); }); test("wallComposeArgs grouped: tiles slide in on their beat, a group in unison, silent before the next beat, the crowd at the end", () => { const plan = wallPlan({ tiles: 9, build: 4, durations: Array(9).fill(1.2), fps: 30, width: 320, height: 180, groups: "double", leads: Array(9).fill(0.12) }); const tiles = Array.from({ length: 9 }, (_, i) => ({ file: `/t/${i}.mp4`, seconds: 2 })); const settings = resolveMontage({ montage: { cut: "whip", wall: { tiles: 9, groups: "double" } } }); const r4 = (v) => String(Number(v.toFixed(4))); const args = wallComposeArgs({ tiles, plan, render: { width: 320, height: 180, fps: 30, palette: PALETTE }, settings, first: false, last: true, encode: [], outPath: "/o.mp4" }); const graph = args[args.indexOf("-filter_complex") + 1]; assert.match(graph, /^color=c=#15121c:s=320x180:r=30:d=[\d.]+,setsar=1\[wc0\]/); assert.ok(graph.includes(`[wc4][wt4]overlay=x='${plan.layout[4].x}+50*pow(max(0,1-(t-${r4(plan.appear[4])})/0.1333),2)':y=${plan.layout[4].y}:enable='gte(t,${r4(plan.appear[4])})'`)); assert.equal(WALL_SLIDE_FRAMES, 4); // Group levels: alone 1, a pair 0.8839, five 0.559. assert.match(graph, /\[wa0a\]atrim=end=[\d.]+,asetpts=PTS-STARTPTS,volume=1,afade=t=out/); assert.match(graph, /\[wa2a\]atrim=end=[\d.]+,asetpts=PTS-STARTPTS,volume=0\.8839,/); assert.match(graph, /\[wa8a\]atrim=end=[\d.]+,asetpts=PTS-STARTPTS,volume=0\.559,/); // Tile 0 falls silent 40 ms before group 1's beat. const once0 = Number(graph.match(/\[wa0a\]atrim=end=([\d.]+)/)[1]); assert.ok(Math.abs(plan.appear[0] + once0 - (plan.groupBeats[1] - 0.04)) < 1e-3, `${once0}`); assert.match(graph, new RegExp(`\\[wa8b\\]atrim=end=[\\d.]+,asetpts=PTS-STARTPTS,volume=0\\.5333,adelay=${Math.round(plan.restart[8] * 1000)}:all=1`)); assert.match(graph, /\[wg\]split=2\[wph\]\[wpb\]|\[wg\]split=3/, "the whip in"); assert.equal(args[args.indexOf("-frames:v") + 1], String(plan.frames)); }); test("refineOnset: the sharpest rise near the estimate, to the frame; null without one", () => { const rate = 8000; const mk = (onset, len = 1.2) => Float64Array.from({ length: Math.round(len * rate) }, (_, i) => { const t = i / rate; const noise = 0.01 * Math.sin(i * 12.9898) * Math.sin(i * 78.233); return noise + (t >= onset ? 0.5 * Math.sin(2 * Math.PI * 300 * t) : 0); }); const r = refineOnset(mk(0.73), rate, 0.6); assert.ok(Math.abs(r.at - 0.73) <= 0.01, JSON.stringify(r)); assert.ok(r.rise > 20); assert.ok(Math.abs(refineOnset(mk(0.45), rate, 0.6).at - 0.45) <= 0.01, "earlier than the estimate"); assert.equal(refineOnset(mk(5), rate, 0.6), null, "no rise at all"); assert.equal(refineOnset(mk(1.1), rate, 0.6, { window: 0.3 }), null, "a rise outside the window"); const env = speechEnvelope(mk(0.5), rate); assert.equal(env.length, Math.floor((1.2 * rate - 160) / 40) + 1); assert.ok(env[10] < -30 && env.at(-1) > -10); }); test("consensusLags + templateOnset: takes of one phrase at different times line up, and land on its onset", () => { const rate = 16000; // A floor of noise, then two "syllables" (500 Hz, 900 Hz) from `on`; every estimate says 0.8 s. const take = (on) => Int16Array.from({ length: 2.4 * rate }, (_, i) => { const t = i / rate; const noise = 300 * ((Math.sin(i * 12.9898) * 43758.5453) % 1); const syl = (t >= on && t < on + 0.25) || (t >= on + 0.35 && t < on + 0.6); return Math.round(noise + (syl ? 9000 * Math.sin(2 * Math.PI * (t < on + 0.3 ? 500 : 900) * t) : 0)); }); const origin = Math.round((0.8 - 256 / rate) / 0.005); for (const ons of [[1.05, 1.0, 1.12, 0.98, 1.07], [0.6, 0.65, 0.7, 0.62, 0.66], [0.9, 0.93, 0.95, 0.87, 1.1, 0.91]]) { const feats = ons.map((o) => bandFeatures(take(o), rate)); assert.equal(feats[0][0].length, 8); const { lags, r } = consensusLags(feats, { origin, pre: 10, span: 160, search: 80 }); assert.equal([...lags].sort((a, b) => a - b)[Math.floor(lags.length / 2)], 0, "the median shift is zero"); for (const x of r) assert.ok(x > 0.9, `r ${x}`); const a = templateOnset(feats, lags, { origin }); ons.forEach((o, i) => assert.ok(Math.abs(0.8 + lags[i] * 0.005 + a.shift - o) <= 0.0051, `${ons}: take ${i}`)); } // Two takes: no consensus, no shift. assert.deepEqual(consensusLags([[], []], { origin: 0 }).lags, [0, 0]); }); test("envelopeLag: a shifted copy is found at its shift", () => { const a = Array.from({ length: 200 }, (_, i) => Math.sin(i / 7) + (i > 80 && i < 120 ? 3 : 0)); const b = [...Array(9).fill(a[0]), ...a.slice(0, 191)]; assert.equal(envelopeLag(a, b, 20).lag, 9); assert.equal(envelopeLag(b, a, 20).lag, -9); assert.equal(envelopeLag(a, a, 5).lag, 0); }); /** * Twelve clips over six six-second files. Their sound: a quiet floor, a tone * at 0.3–1.2 s, the PHRASE's tone from `onset` (2.25 s, a quarter second * after the cues say 2.0), and another from 3.9 s. Years 2019 on, three a * year; montage.n 1–12. */ async function wallFixture(montage, { stream = null } = {}) { const root = await mkdtemp(path.join(os.tmpdir(), "rtv-wallsync-")); await mkdir(path.join(root, "media"), { recursive: true }); for (let i = 1; i <= 6; i += 1) { const r = spawnSync("ffmpeg", [ "-v", "error", "-y", "-f", "lavfi", "-i", `color=c=0x808080:s=320x180:r=${FPS}:d=6`, "-f", "lavfi", "-i", `aevalsrc='0.01*sin(2*PI*97*t)*sin(2*PI*13*t)+0.5*sin(2*PI*${300 + 40 * i}*t)*(between(t,0.3,1.2)+between(t,2.25,3.2)+between(t,3.9,5.5))':s=48000:d=6`, "-vf", "drawbox=x=40:y=0:w=20:h=180:color=white:t=fill", "-c:v", "libx264", "-preset", "ultrafast", "-c:a", "aac", "-shortest", path.join(root, "media", `c${i}.mp4`), ]); assert.equal(r.status, 0, String(r.stderr)); await writeFile(path.join(root, "media", `c${i}.json`), JSON.stringify({ cues: [ { start: 0.2, end: 2.0, text: "well folks it is a" }, { start: 2.0, end: 3.6, text: "slow news day again" }, { start: 3.6, end: 5.8, text: "and here we go" }, ], })); } const timeline = Array.from({ length: 12 }, (_, k) => { const j = (k % 6) + 1; return { id: `s${k + 1}`, type: "clip", src: `media/c${j}.mp4`, cues: `media/c${j}.json`, start: 0.2, end: 5.8, title: `Clip ${k + 1}`, channelTitle: "Demo", montage: { n: k + 1, date: `${2019 + Math.floor(k / 3)}0${(k % 9) + 1}01`, platform: "youtube", match: "slow news day", ...(stream ? { stream: stream(k) } : {}), }, }; }); const manifestPath = path.join(root, "video.manifest.json"); await writeFile(manifestPath, JSON.stringify({ slug: "demo", title: "Demo", render: { ...RENDER, montage }, timeline })); return { root, manifestPath }; } test("render: today's wall with its new keys spelled out at their defaults is byte for byte today's", { skip: !have && "needs ffmpeg" }, async () => { const base = { tighten: "phrase", ramp: { from: 2.6, to: 1.2 }, wall: { tiles: 9, build: 2 } }; const a = await wallFixture(base); const b = await wallFixture({ ...base, ramp: { ...base.ramp, into: null }, wall: { ...base.wall, groups: "single", sync: false, clips: "spread", exclusive: false } }); try { await buildVideo({ manifestPath: a.manifestPath, opts: { noNetwork: true } }); await buildVideo({ manifestPath: b.manifestPath, opts: { noNetwork: true } }); const md5 = (f) => spawnSync("md5sum", [f]).stdout.toString().split(" ")[0]; // On a mismatch, say which segment differs. const segs = ["s1", "s2", "s3", "s12", "montage-wall"].map((id) => `sourced/segments/${id}.mp4`); const which = segs.filter((f) => md5(path.join(a.root, "out", f)) !== md5(path.join(b.root, "out", f))); assert.equal(md5(path.join(a.root, "out", "demo.mp4")), md5(path.join(b.root, "out", "demo.mp4")), `differs: ${which.join(", ") || "only the final"}`); } finally { await rm(a.root, { recursive: true, force: true }); await rm(b.root, { recursive: true, force: true }); } }); test("render: build-to-wall over twelve clips -- three run, nine are tiles in groups, onsets synced to the beats", { skip: !have && "needs ffmpeg" }, async () => { const montage = mergePatch(applyMontageStyle({ render: {} }, "build-to-wall").render.montage, { wall: { tiles: 9, build: 4 } }); const { root, manifestPath } = await wallFixture(montage); try { const r = await buildVideo({ manifestPath, opts: { noNetwork: true } }); const seg = path.join(root, "out", "sourced", "segments"); // The run: s1–s3 only; the tiles have no segment. const p = await planned(root, ["s1", "s2", "s3"], true); await assert.rejects(readFile(path.join(seg, "s4.cut.json"))); assert.ok(Math.abs(framesOf(r.out) - p.total) <= 1, `${framesOf(r.out)} vs ${p.total}`); // The ramp meets the wall: the last cut is no longer than the first gap. const gap = wallFirstGap(resolveMontage({ montage }).wall); assert.ok(p.recs[2].end - p.recs[2].start <= gap + 0.002, `${p.recs[2].end - p.recs[2].start} vs ${gap}`); const wall = JSON.parse(await readFile(path.join(seg, "montage-wall.cut.json"), "utf8")).montageWall; assert.deepEqual(wall.tiles, ["s4", "s5", "s6", "s7", "s8", "s9", "s10", "s11", "s12"]); assert.deepEqual(wall.groups, [1, 1, 2, 5]); // Every onset moved from the cues' 2.0 to the sound's 2.25 (the tiles agree, and their // mean loudness rises there), to within 15 ms. for (const t of wall.sync) { assert.equal(t.estimate, 2); assert.equal(t.by, "consensus", t.id); assert.ok(Math.abs(t.onset - 2.25) <= 0.015, `${t.id} ${t.onset}`); } assert.ok(Math.abs(wall.syncAnchor - 0.25) <= 0.015, `anchor ${wall.syncAnchor}`); // In each tile's own file the phrase starts its lead in (measured on the tile's sound). for (const id of ["s4", "s8"]) { const pcm = spawnSync("ffmpeg", ["-v", "error", "-i", path.join(seg, "montage-wall", `${id}.mp4`), "-ac", "1", "-ar", "16000", "-f", "s16le", "-"], { maxBuffer: 1 << 24 }).stdout; const samples = new Int16Array(pcm.buffer, pcm.byteOffset, Math.floor(pcm.length / 2)); const at = refineOnset(samples, 16000, 0.12, { window: 0.1 }).at; assert.ok(Math.abs(at - 0.12) <= 0.03, `${id}: onset ${at} in its tile`); } // The last group's tiles are ground before their beat and footage on it. const plan = wallPlan({ tiles: 9, build: 4, durations: Array(9).fill(1.2), fps: FPS, width: 320, height: 180, groups: "double", leads: Array(9).fill(0.12) }); const start = p.total - p.wallFrames; const l = plan.layout[8]; const tile = `${l.w - 8}:${l.h - 24}:${l.x + 4}:${l.y + 4}`; assert.ok(luma(r.out, start + plan.appearFrames[8] - 2, tile) < 40, "empty before its group"); assert.ok(luma(r.out, start + plan.appearFrames[8] + 6, tile) > 100, "filled on its beat"); // Heard all through: on each group's beat and at the final one. const level = (from) => Number(String(spawnSync("ffmpeg", ["-nostdin", "-ss", from.toFixed(3), "-t", "0.3", "-i", path.join(seg, "montage-wall.mp4"), "-vn", "-af", "volumedetect", "-f", "null", "-"]).stderr).match(/mean_volume: (-?[\d.]+)/)[1]); for (const b of [...wall.groupBeats, wall.beat]) assert.ok(level(b) > -40, `silent at ${b}`); // Chapters: three clips and the wall; verify-build agrees. const ch = spawnSync("ffprobe", ["-v", "error", "-show_chapters", "-of", "json", r.out]); assert.equal(JSON.parse(String(ch.stdout)).chapters.length, 4); assert.deepEqual((await verifyBuild(manifestPath)).problems, []); } finally { await rm(root, { recursive: true, force: true }); } }); // ---- release 33 montage-polish: repeats apart, even loudness, tile labels --------------------- test("validateMontage: wall label, spread, distinct; loudness", () => { const errs = (m, tl) => validateMontage(manifest(m, tl)); assert.match(errs({ wall: { label: "date" } })[0], /wall\.label must be "year" or "number" or "both", not "date"/); assert.match(errs({ wall: { spread: "even" } })[0], /wall\.spread must be "stream", not "even"/); assert.match(errs({ wall: { distinct: 1 } })[0], /wall\.distinct must be true or false/); const eleven = Array.from({ length: 11 }, (_, i) => clip(`s${i + 1}`)); assert.match(errs({ wall: { tiles: 9, clips: "tail", exclusive: true, distinct: true } }, eleven)[0], /wall\.distinct does not combine with render\.montage\.wall\.exclusive/); assert.deepEqual(errs({ wall: { tiles: 9, clips: "tail", distinct: true, spread: "stream", label: "both" } }, eleven), []); assert.match(errs({ loudness: { target: -3 } })[0], /loudness\.target must be a number from -40 to -5 LUFS/); assert.match(errs({ loudness: { mode: "stream" } })[0], /loudness\.mode must be "clip"/); assert.match(errs({ loudness: { gain: 2 } })[0], /loudness\.gain is not a setting here/); assert.match(errs({ loudness: -16 })[0], /loudness must be an object/); assert.deepEqual(errs({ loudness: {} }), []); }); test("resolveMontage: a label from today's year; loudness defaults", () => { assert.equal(resolveMontage({ montage: { wall: { year: true } } }).wall.label, "year"); assert.equal(resolveMontage({ montage: { wall: { year: true, label: "both" } } }).wall.label, "both"); assert.equal(resolveMontage({ montage: { wall: {} } }).wall.label, null); assert.deepEqual(resolveMontage({ montage: { loudness: {} } }).loudness, { target: -16, mode: "clip" }); assert.equal(resolveMontage({ montage: {} }).loudness, null); }); test("clipStream: its own stream, else its day (a mirror shares the day), else its video", () => { assert.equal(clipStream({ montage: { stream: "x", date: "20260507" }, video: "v" }), "x"); assert.equal(clipStream({ montage: { date: "20260507" }, video: "v1" }), clipStream({ date: "2026-05-07", video: "Gu2" })); assert.equal(clipStream({ video: "v9" }), "v9"); assert.equal(clipStream({ src: "media/a.mp4" }), "media/a.mp4"); }); test("distinctTileClips: one tile per stream, latest first for a tail, in cut order", () => { const ids = ["a1", "b1", "c1", "c2", "d1", "e1", "e2"]; const streamOf = new Map(ids.map((id) => [id, id[0]])); assert.deepEqual(distinctTileClips(ids, 4, "tail", streamOf), ["b1", "c2", "d1", "e2"]); assert.deepEqual(distinctTileClips(ids, 6, "tail", streamOf), ["a1", "b1", "c2", "d1", "e1", "e2"], "fewer streams than tiles: the latest of the rest"); assert.deepEqual(distinctTileClips(ids, 4, "spread", streamOf), wallTileClips(["a1", "b1", "c1", "d1", "e1"], 4)); const tl = ids.map((id) => clip(id, { montage: { stream: id[0] } })); assert.deepEqual(montageSplit(tl, resolveMontage({ montage: { wall: { tiles: 4, clips: "tail", distinct: true } } })).wall, ["b1", "c2", "d1", "e2"]); }); test("wallCells: repeats of one stream never touch across a row or a column; nothing moves without a repeat", () => { // The auditioned take's tail: five same-stream pairs side by side, and a same-day mirror pair. const streams = ["a", "b", "c", "c", "d", "e", "f", "f", "g", "h", "i", "i", "j", "k", "l", "l", "m", "n", "o", "p", "q", "q", "r", "s", "s"]; const cells = wallCells(streams, 5); assert.deepEqual([...cells].sort((x, y) => x - y), Array.from({ length: 25 }, (_, i) => i), "a permutation"); const at = (c) => [Math.floor(c / 5), c % 5]; for (let i = 0; i < 25; i += 1) { for (let j = i + 1; j < 25; j += 1) { if (streams[i] !== streams[j]) continue; const [a, b] = at(cells[i]); const [c, d] = at(cells[j]); assert.notEqual(Math.abs(a - c) + Math.abs(b - d), 1, `${i} and ${j} touch`); } } assert.ok(cells.filter((c, i) => c !== i).length <= 12, "few tiles move"); assert.deepEqual(wallCells(streams, 5), cells, "deterministic"); assert.deepEqual(wallCells(Array.from({ length: 9 }, (_, i) => `s${i}`), 3), Array.from({ length: 9 }, (_, i) => i)); // Unavoidable: one stream on every tile. assert.equal(wallCells(Array(4).fill("x"), 2).length, 4); }); test("wallPlan cells: tile i is laid in its cell; the single compose's grid origin is the top-left cell", () => { const base = { tiles: 9, build: 3, durations: Array(9).fill(1), fps: 30, width: 320, height: 180 }; const plain = wallPlan(base); const cells = [4, 1, 2, 3, 0, 5, 6, 7, 8]; const moved = wallPlan({ ...base, cells }); assert.deepEqual(moved.layout[0], plain.layout[4]); assert.deepEqual(moved.layout[4], plain.layout[0]); assert.deepEqual(wallPlan({ ...base, cells: null }), plain); const tiles = Array.from({ length: 9 }, (_, i) => ({ file: `/t/${i}.mp4`, seconds: 1 })); const settings = resolveMontage({ montage: { wall: { tiles: 9 } } }); const g = (plan) => { const a = wallComposeArgs({ tiles, plan, render: { width: 320, height: 180, fps: 30, palette: PALETTE }, settings, first: false, last: true, encode: [], outPath: "/o" }); return a[a.indexOf("-filter_complex") + 1]; }; const pad = (graph) => graph.match(/xstack=inputs=9:layout=([^:]+):fill=[^,]+,pad=320:180:(\d+):(\d+)/); const [, l0, x0, y0] = pad(g(plain)); const [, l1, x1, y1] = pad(g(moved)); assert.deepEqual([x1, y1], [x0, y0]); assert.equal(l1.split("|")[0], l0.split("|")[4]); }); test("wallTileLabel and wallTileArgs: year, number or both; today's year label unchanged; a gain on the tile's sound", () => { assert.equal(wallTileLabel("year", { number: 52, year: 2025 }), "2025"); assert.equal(wallTileLabel("number", { number: 52, year: 2025 }), "#52"); assert.equal(wallTileLabel("both", { number: 52, year: 2025 }), "#52 · 2025"); assert.equal(wallTileLabel("both", { number: null, year: 2025 }), "2025"); assert.equal(wallTileLabel(null, { number: 1, year: 2025 }), null); const base = { raw: "/r.mp4", from: 1, to: 2, tileW: 100, tileH: 56, fps: 30, font: "/f.ttf", render: { palette: PALETTE }, encode: ["-c:v", "x"], outPath: "/o.mp4" }; const byYear = wallTileArgs({ ...base, year: 2025 }); assert.deepEqual(wallTileArgs({ ...base, text: "2025" }), byYear); assert.match(byYear.join(" "), /text='2025'.*\[v\] -map \[v\] -map 0:a/); const both = wallTileArgs({ ...base, text: "#52 · 2025", gainDb: 4.5 }); const graph = both[both.indexOf("-filter_complex") + 1]; assert.match(graph, /text='#52 · 2025'/); assert.match(graph, /;\[0:a\]volume=4\.5dB,alimiter=limit=0\.891:level=0:latency=1\[a\]$/); assert.equal(both[both.indexOf("-map", both.indexOf("-map") + 1) + 1], "[a]"); }); test("loudness: the gain to the target, held to ±20 dB, none for silence; ebur128's summary read; a leveled segment's chain", () => { assert.equal(loudnessGain(-30, -16), 14); assert.equal(loudnessGain(-8.5, -16), -7.5); assert.equal(loudnessGain(-39, -16), 20, "held to +20"); assert.equal(loudnessGain(-50, -16), 0, "near-silence is not raised"); assert.equal(loudnessGain(-70, -16), 0); assert.equal(loudnessGain(null, -16), 0); const log = "[Parsed_ebur128_0 @ 0x1] t: 1.9 M: -20 S: -21 I: -25.0 LUFS\n[Parsed_ebur128_0 @ 0x1] Summary:\n\n Integrated loudness:\n I: -21.8 LUFS\n Threshold: -31.8 LUFS\n"; assert.equal(parseIntegratedLoudness(log), -21.8); assert.equal(parseIntegratedLoudness("Summary:\n I: -inf LUFS"), null); assert.equal(parseIntegratedLoudness("nothing"), null); assert.equal(levelFilters(-3.25), "volume=-3.25dB,alimiter=limit=0.891:level=0:latency=1"); const g = montagePiecesGraph({ pieces: [{ f0: 0, f1: 90, zoom: 1 }], fps: 30, box: { w: 320, h: 180 }, bg: "#000000", gainDb: 6 }); assert.equal(g.parts.at(-1), `[mac]apad=whole_dur=3,atrim=end=3,volume=6dB,alimiter=limit=0.891:level=0:latency=1,afade=t=in:d=${DECLICK},afade=t=out:st=2.985:d=${DECLICK}[ma]`); const plain = montagePiecesGraph({ pieces: [{ f0: 0, f1: 90, zoom: 1 }], fps: 30, box: { w: 320, h: 180 }, bg: "#000000" }); assert.equal(plain.parts.at(-1), `[mac]apad=whole_dur=3,atrim=end=3,afade=t=in:d=${DECLICK},afade=t=out:st=2.985:d=${DECLICK}[ma]`); }); test("planMontage: an exclusive wall's clips keep their number for their label", () => { const tl = Array.from({ length: 12 }, (_, i) => clip(`s${i + 1}`, { montage: { n: i + 41 } })); const plan = planMontage(tl, resolveMontage({ montage: { wall: { tiles: 9, clips: "tail", exclusive: true } } })); assert.equal(plan.get("s12").number, 52); assert.equal(planMontage(tl.map((e) => ({ ...e, montage: {} })), resolveMontage({ montage: { wall: { tiles: 9, clips: "tail", exclusive: true } } })).get("s12").number, 12); }); /** A segment's integrated loudness, LUFS. */ function lufs(file) { const r = spawnSync("ffmpeg", ["-nostdin", "-hide_banner", "-i", file, "-vn", "-af", "ebur128", "-f", "null", "-"]); return parseIntegratedLoudness(String(r.stderr)); } test("render: loudness -- four clips 26 dB apart come out within 1 LU of the target", { skip: !have && "needs ffmpeg" }, async () => { const amps = [0.03, 0.1, 0.3, 0.6]; const { root, manifestPath } = await fixture({ tighten: "phrase", loudness: { target: -18 } }, { amp: (i) => amps[i - 1] }); try { await buildVideo({ manifestPath, opts: { noNetwork: true } }); const seg = path.join(root, "out", "sourced", "segments"); const before = []; for (const id of IDS) { const rec = JSON.parse(await readFile(path.join(seg, `${id}.cut.json`), "utf8")).montage.loudness; before.push(rec.measured); assert.equal(rec.target, -18); assert.ok(Math.abs(rec.measured + rec.gain + 18) < 0.01, JSON.stringify(rec)); const got = lufs(path.join(seg, `${id}.mp4`)); assert.ok(Math.abs(got + 18) <= 1, `${id}: ${got} LUFS`); } assert.ok(Math.max(...before) - Math.min(...before) > 20, `the sources spread ${before}`); } finally { await rm(root, { recursive: true, force: true }); } }); test("render: a tail wall keeps one stream's repeats apart, labels its tiles, levels them", { skip: !have && "needs ffmpeg" }, async () => { const montage = { tighten: "phrase", loudness: { target: -18 }, wall: { tiles: 9, build: 2, clips: "tail", label: "both", spread: "stream" }, }; // s4–s12 are the tiles; s5/s6, s8/s9 and s11/s12 are three streams' repeats. const { root, manifestPath } = await wallFixture(montage, { stream: (k) => (k >= 4 ? `st${Math.floor((k - 1) / 3)}-${(k - 1) % 3 === 0 ? "a" : "b"}` : `solo${k}`) }); try { const r = await buildVideo({ manifestPath, opts: { noNetwork: true } }); const seg = path.join(root, "out", "sourced", "segments"); const wall = JSON.parse(await readFile(path.join(seg, "montage-wall.cut.json"), "utf8")).montageWall; const m = JSON.parse(await readFile(manifestPath, "utf8")); const streamOf = new Map(m.timeline.map((e) => [e.id, clipStream(e)])); const at = (c) => [Math.floor(c / 3), c % 3]; for (let i = 0; i < 9; i += 1) { for (let j = i + 1; j < 9; j += 1) { if (streamOf.get(wall.tiles[i]) !== streamOf.get(wall.tiles[j])) continue; const [a, b] = at(wall.cells[i]); const [c, d] = at(wall.cells[j]); assert.notEqual(Math.abs(a - c) + Math.abs(b - d), 1, `${wall.tiles[i]} and ${wall.tiles[j]} touch`); } } assert.deepEqual(Object.keys(wall.loudness).sort(), [...wall.tiles].sort(), "each tile clip measured once"); for (const v of Object.values(wall.loudness)) assert.equal(v.target, -18); const tile = path.join(seg, "montage-wall", "s12.mp4"); assert.ok(Math.abs(lufs(tile) + 18) <= 1.5, `tile ${lufs(tile)}`); assert.deepEqual((await verifyBuild(manifestPath)).problems, []); assert.ok(r.out); } finally { await rm(root, { recursive: true, force: true }); } }); // ---- release 33 silent-tile: a near-silent cut is a mislocated phrase ------------------------- test("nearSilent and median: under −40 LUFS, unmeasurable, or 15 LU under the run's median", () => { assert.equal(SILENT_LUFS, -40); assert.equal(nearSilent(-53.7), true); assert.equal(nearSilent(-38.6), false); assert.equal(nearSilent(-38.6, -21), true, "17.6 LU under the median"); assert.equal(nearSilent(-30, -21), false); assert.equal(nearSilent(null), true); assert.equal(median([3, 1, 2]), 2); assert.equal(median([4, 1, 3, 2]), 2.5); assert.equal(median([]), null); // Near-silence is never raised. assert.equal(loudnessGain(-45, -16), 0); assert.equal(loudnessGain(-38.6, -16), 20); }); /** dB frames every 5 ms: speech (−20 dB) over [a, b) seconds, silence (−100) elsewhere, `len` seconds long. */ const envOf = (len, spans) => Float64Array.from({ length: Math.round(len / 0.005) }, (_, k) => (spans.some(([a, b]) => k * 0.005 >= a && k * 0.005 < b) ? -20 : -100)); test("relocateBySound: a phrase estimated into the silence after a long cue lands on the speech that ends there", () => { // A 7.8 s cue of speech from 1.1 s to 9.4 s, silence after; the even-spread estimate put "slow news" at 9.7. const env = envOf(12, [[1.1, 9.4]]); const t = relocateBySound(env, { start: 0, est: 9.7, len: 1.2 }); // Nearest the estimate with three quarters of it speech: ending at most 0.3 s into the silence. assert.ok(t >= 9.4 - 1.2 - 0.006 && t <= 9.4 - 1.2 + 0.301, `${t}`); // The excerpt's own start is added. assert.ok(Math.abs(relocateBySound(env, { start: 355, est: 364.7, len: 1.2 }) - (355 + t)) <= 0.006); // Speech either side: the nearest wins. const two = envOf(12, [[0.5, 3], [6, 9]]); // (Up to a quarter of the stretch may be the silence beside the speech: real speech has gaps.) assert.ok(Math.abs(relocateBySound(two, { start: 0, est: 4.5, len: 1 }) - 6) <= 0.251); assert.ok(Math.abs(relocateBySound(two, { start: 0, est: 3.6, len: 1 }) - 2) <= 0.251); assert.equal(relocateBySound(envOf(5, []), { start: 0, est: 2, len: 1 }), null, "no speech"); assert.equal(relocateBySound(envOf(0.5, [[0, 0.5]]), { start: 0, est: 0, len: 1 }), null, "shorter than the phrase"); }); test("shiftAllowed: a consensus shift into a pause is refused", () => { // Excerpt from est − 0.8: speech 0.6–1.6 s into it, then silence. const env = envOf(2.4, [[0.6, 1.6]]); assert.equal(shiftAllowed(env, { pre: 0.8, shift: 0.1 }), true); assert.equal(shiftAllowed(env, { pre: 0.8, shift: 0.9 }), false, "into the silence after"); assert.equal(shiftAllowed(env, { pre: 0.8, shift: -0.1 }), true); assert.equal(shiftAllowed(envOf(2.4, []), { pre: 0.8, shift: 0.3 }), true, "silence to silence is no drop"); }); /** One clip of six seconds: a tone (speech) over `speech` [a, b), silence elsewhere; one long cue; montage on. */ async function oneClip({ speech, cues, montage, shiftTs = 0 }) { const root = await mkdtemp(path.join(os.tmpdir(), "rtv-silent-")); await mkdir(path.join(root, "media"), { recursive: true }); const full = path.join(root, "media", "full.mp4"); const r = spawnSync("ffmpeg", [ "-v", "error", "-y", "-f", "lavfi", "-i", `color=c=0x808080:s=320x180:r=${FPS}:d=6`, "-f", "lavfi", "-i", `aevalsrc='0.4*sin(2*PI*330*t)*between(t,${speech[0]},${speech[1]})+0.002*sin(2*PI*50*t)':s=48000:d=6`, "-c:v", "libx264", "-preset", "ultrafast", "-c:a", "aac", "-shortest", full, ]); assert.equal(r.status, 0, String(r.stderr)); let media = "media/full.mp4"; if (shiftTs) { // A section cut that keeps its source's clock: content from shiftTs on, its picture starting shiftTs in. const cut = path.join(root, "media", "cut.mp4"); const c = spawnSync("ffmpeg", ["-v", "error", "-y", "-ss", String(shiftTs), "-i", full, "-c:v", "libx264", "-preset", "ultrafast", "-c:a", "aac", "-output_ts_offset", String(shiftTs), cut]); assert.equal(c.status, 0, String(c.stderr)); media = "media/cut.mp4"; } await writeFile(path.join(root, "media", "c.json"), JSON.stringify({ cues })); const manifestPath = path.join(root, "video.manifest.json"); await writeFile(manifestPath, JSON.stringify({ slug: "demo", title: "Demo", render: { ...RENDER, montage }, timeline: [ { id: "c1", type: "clip", src: media, cues: "media/c.json", start: shiftTs ? 1.1 : 0.1, end: shiftTs ? 4.9 : 5.9, title: "C", channelTitle: "Demo", montage: { n: 1, date: "20260922", match: "slow news week" } }, { id: "c2", type: "clip", src: "media/full.mp4", cues: "media/c.json", start: shiftTs ? 1.1 : 0.1, end: shiftTs ? 4.9 : 5.9, title: "D", channelTitle: "Demo", montage: { n: 2, date: "20260923", match: "slow news week" } }, ], })); return { root, manifestPath }; } test("render: a cut measured near-silent is relocated onto the speech and leveled, not raised from silence", { skip: !have && "needs ffmpeg" }, async () => { // Speech 0.4–3.6 s, then silence; one long cue to 5.6 s ending "…slow news week": the estimate sits in the silence. const { root, manifestPath } = await oneClip({ speech: [0.4, 3.6], cues: [{ start: 0.4, end: 5.6, text: "rest up you know it is kind of a slow news week" }], montage: { tighten: "phrase", phrasePad: 0.3, loudness: { target: -18 } }, }); try { await buildVideo({ manifestPath, opts: { noNetwork: true } }); const seg = path.join(root, "out", "sourced", "segments"); const rec = JSON.parse(await readFile(path.join(seg, "c1.cut.json"), "utf8")); const loud = rec.montage.loudness; assert.ok(loud.relocated, JSON.stringify(rec.montage)); assert.ok(loud.relocated.from > 3.6, `estimated in the silence: ${loud.relocated.from}`); assert.ok(loud.relocated.to < 3.6 && loud.relocated.to > 1.5, `relocated onto the speech: ${loud.relocated.to}`); assert.match(loud.relocated.why, /^measured (-?[\d.]+|no) LUFS$/); assert.equal(rec.montage.found, "sound"); assert.ok(loud.measured > -40, `now ${loud.measured}`); assert.ok(Math.abs(lufs(path.join(seg, "c1.mp4")) + 18) <= 1, "leveled"); } finally { await rm(root, { recursive: true, force: true }); } }); test("render: a window whose picture starts late is cut on its own clock", { skip: !have && "needs ffmpeg" }, async () => { // c1's file is c2's from 1.0 s on, its timestamps kept (start_time 1.0): the same source seconds. const { root, manifestPath } = await oneClip({ speech: [1.5, 4.5], cues: [{ start: 1.5, end: 2.5, text: "it is a slow" }, { start: 2.5, end: 3.5, text: "news week folks" }], montage: { tighten: "phrase", phrasePad: 0.3 }, shiftTs: 1, }); try { await buildVideo({ manifestPath, opts: { noNetwork: true } }); const seg = path.join(root, "out", "sourced", "segments"); const [a, b] = await Promise.all(["c1", "c2"].map(async (id) => JSON.parse(await readFile(path.join(seg, `${id}.cut.json`), "utf8")))); assert.ok(Math.abs(a.start - b.start) <= 0.05 && Math.abs(a.end - b.end) <= 0.05, `${a.start}–${a.end} vs ${b.start}–${b.end}`); // The same sound: the two segments' loudness agrees. assert.ok(Math.abs(lufs(path.join(seg, "c1.mp4")) - lufs(path.join(seg, "c2.mp4"))) <= 1); } finally { await rm(root, { recursive: true, force: true }); } }); test("wall compose: every tile's tpad is fed by fps (ffmpeg 7.1's tpad pads nothing after a trim without it)", () => { // On 7.1 (Debian trixie, the umtool image) `trim,setpts,tpad` pads neither the start nor the clone at // the end, so the single wall came out 23 frames short; `fps` before tpad gives it a frame rate to pad // by, and on CFR input changes no frame on 9.x. const tiles = Array.from({ length: 9 }, (_, i) => ({ file: `/t/${i}.mp4`, seconds: 1.2 })); const render = { width: 320, height: 180, fps: 30, palette: PALETTE }; const graphs = [ wallComposeArgs({ tiles, plan: wallPlan({ tiles: 9, build: 3, durations: Array(9).fill(1.2), fps: 30, width: 320, height: 180 }), render, settings: resolveMontage({ montage: { wall: { tiles: 9 } } }), first: false, last: true, encode: [], outPath: "/o" }), wallComposeArgs({ tiles, plan: wallPlan({ tiles: 9, build: 3, durations: Array(9).fill(1.2), fps: 30, width: 320, height: 180, groups: "double", leads: Array(9).fill(0.12) }), render, settings: resolveMontage({ montage: { wall: { tiles: 9, groups: "double" } } }), first: false, last: true, encode: [], outPath: "/o" }), ].map((a) => a[a.indexOf("-filter_complex") + 1]); for (const g of graphs) { const tpads = g.match(/[^,;\]]*,tpad=/g) ?? []; assert.equal(tpads.length, 18, "two per tile"); for (const t of tpads) assert.equal(t, "fps=30,tpad="); } });