commit 743f1ef4ba1d53f3c155ae58ecfc58ed70b7bd82
parent ab7a62731740d6db2a96b5cf224aa6da9c36244b
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 2 Nov 2026 17:20:30 -0500
umtool trailer: a gapped beat crossfaded into the next -- every run's picture on one timebase
The gapped run's concat puts its picture on the default timebase and xfade
refuses two (found cutting the merged kf3e beat on the Kirsche copy: ffmpeg
-22). With any gapped run, each run's picture is `settb=AVTB`; a plan with no
gaps keeps its graph byte for byte. The real-encode test now crossfades a
gapped beat into the next and measures 7.7 s.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 17 insertions(+), 8 deletions(-)
diff --git a/umtool/report-to-video/trailer-gaps.test.mjs b/umtool/report-to-video/trailer-gaps.test.mjs
@@ -94,14 +94,17 @@ test("the graph: the gapped run's cuts as a gap filter with its own labels, the
assert.match(graph, /\[r0v\]split=2\[gr0vs0\]\[gr0vs1\]/);
assert.match(graph, /\[gr0vs0\]trim=start=0:end=2,setpts=PTS-STARTPTS\[gr0vp0\]/);
assert.match(graph, /\[gr0vs1\]trim=start=4:end=8,setpts=PTS-STARTPTS\[gr0vp1\]/);
- assert.match(graph, /concat=n=2:v=1:a=0\[v0\]/);
+ assert.match(graph, /concat=n=2:v=1:a=0\[g0v\]/);
+ // Every picture on one timebase: xfade refuses two (the gapped run's concat is on the default one).
+ assert.match(graph, /\[g0v\]settb=AVTB\[v0\]/);
+ assert.match(graph, /\[m1v\]trim=[^;]*,setpts=PTS-STARTPTS,settb=AVTB\[v1\]/);
assert.match(graph, /afade=t=out:st=1\.975:d=0\.025/);
assert.match(graph, /concat=n=2:v=0:a=1\[a0\]/);
// The crossfade into the next beat starts 0.3 s before the gapped beat's KEPT end (6 s).
assert.match(graph, /\[v0\]\[v1\]xfade=transition=fade:duration=0\.300000:offset=5\.700000\[xv1\]/);
});
-test("a real encode: a gapped beat cut from a synthesized master runs its kept seconds", { timeout: 60_000 }, async (t) => {
+test("a real encode: a gapped beat cut from a synthesized master, crossfaded into the next, runs its kept seconds", { timeout: 60_000 }, async (t) => {
try {
execFileSync("ffmpeg", ["-version"], { stdio: "ignore" });
} catch {
@@ -113,13 +116,15 @@ test("a real encode: a gapped beat cut from a synthesized master runs its kept s
const master = path.join(dir, "m.mp4");
execFileSync("ffmpeg", ["-nostdin", "-v", "error", "-y", "-f", "lavfi", "-i", "testsrc=size=160x90:rate=30:duration=12", "-f", "lavfi", "-i", "sine=frequency=440:duration=12",
"-map", "0:v", "-map", "1:a", "-c:v", "libx264", "-preset", "ultrafast", "-g", "15", "-pix_fmt", "yuv420p", "-c:a", "aac", "-ar", "48000", "-ac", "2", master]);
- const schedule = { version: 1, kind: "deck", fps: 30, transition: 0, total: 12, segments: [{ id: "c", type: "clip", start: 0, duration: 12, end: 12 }] };
- const records = new Map([["c", { id: "c", start: 10, end: 22 }]]);
- const p = planTrailer({ schedule, records, beats: parseBeats([{ id: "c", start: 11, end: 19, gaps: [{ from: 13, to: 16 }] }]), xfade: 0, snap: false });
+ const schedule = { version: 1, kind: "deck", fps: 30, transition: 0, total: 12, segments: [{ id: "c", type: "clip", start: 0, duration: 6, end: 6 }, { id: "d", type: "clip", start: 6, duration: 6, end: 12 }] };
+ const records = new Map([["c", { id: "c", start: 10, end: 16 }], ["d", { id: "d", start: 50, end: 56 }]]);
+ // A gapped beat crossfaded into the next: 5 s less its 1 s gap, then 4 s, less the 0.3 s crossfade.
+ const p = planTrailer({ schedule, records, beats: parseBeats([{ id: "c", start: 10.5, end: 15.5, gaps: [{ from: 12, to: 13 }] }, { id: "d", start: 51, end: 55 }]), xfade: 0.3, snap: false });
+ assert.equal(p.total, 7.7);
const out = path.join(dir, "t.mp4");
execFileSync("ffmpeg", trailerArgs({ plan: p, master, render: { fps: 30, crf: 35, preset: "ultrafast", audioBitrate: "64k", audioRate: 48000, audioChannels: 2 }, outPath: out }));
const dur = Number(execFileSync("ffprobe", ["-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0", out], { encoding: "utf8" }).trim());
- close(dur, 5, 0.1);
+ close(dur, 7.7, 0.1);
} finally {
await rm(dir, { recursive: true, force: true });
}
diff --git a/umtool/report-to-video/trailer.mjs b/umtool/report-to-video/trailer.mjs
@@ -521,6 +521,9 @@ export function trailerArgs({ plan, master, render, outPath, threads = TRAILER_D
const half = 0.5 / fps;
const src = filterPath(master);
const parts = [];
+ // A gapped run's concat puts its picture on the default timebase (1/1000000), and
+ // xfade wants both inputs on one: with any gapped run, every run's picture is put there.
+ const tb = runs.some((r) => r.cuts?.length) ? ",settb=AVTB" : "";
runs.forEach((r, i) => {
const a = r.start / fps;
const n = r.count;
@@ -528,7 +531,7 @@ export function trailerArgs({ plan, master, render, outPath, threads = TRAILER_D
const seek = Math.max(0, a - PRE_ROLL);
parts.push(`movie=filename=${src}:seek_point=${seek.toFixed(6)}:streams=dv+da:dec_threads=${threads}[m${i}v][m${i}a]`);
const cut = r.cuts?.length;
- parts.push(`[m${i}v]trim=start=${Math.max(0, a - half).toFixed(6)}:end=${(a + n / fps - half).toFixed(6)},setpts=PTS-STARTPTS[${cut ? `r${i}v` : `v${i}`}]`);
+ parts.push(`[m${i}v]trim=start=${Math.max(0, a - half).toFixed(6)}:end=${(a + n / fps - half).toFixed(6)},setpts=PTS-STARTPTS${cut ? "" : tb}[${cut ? `r${i}v` : `v${i}`}]`);
parts.push(
`[m${i}a]atrim=start=${a.toFixed(6)}:end=${(a + n / fps).toFixed(6)},asetpts=PTS-STARTPTS,` +
`apad=whole_dur=${d},atrim=end=${d}[${cut ? `r${i}a` : `a${i}`}]`,
@@ -537,7 +540,8 @@ export function trailerArgs({ plan, master, render, outPath, threads = TRAILER_D
// segment (gaps.mjs gapFilterParts: hard cuts, the sound faded either side).
if (cut) {
const gaps = r.cuts.map((c) => ({ from: (c.start - r.start) / fps, to: (c.start + c.count - r.start) / fps }));
- parts.push(...gapFilterParts({ gaps, seconds: n / fps, vIn: `[r${i}v]`, aIn: `[r${i}a]`, vOut: `[v${i}]`, aOut: `[a${i}]`, tag: `r${i}` }).parts);
+ parts.push(...gapFilterParts({ gaps, seconds: n / fps, vIn: `[r${i}v]`, aIn: `[r${i}a]`, vOut: `[g${i}v]`, aOut: `[a${i}]`, tag: `r${i}` }).parts);
+ parts.push(`[g${i}v]settb=AVTB[v${i}]`);
}
});
const keptOf = (r) => (r.kept ?? r.count) / fps;