commit f79e27bd85d98757d79d604fb8ddaec327e30ddf
parent d4ebf3b0779c0ea84ce63681cb58dbec5d46b7b6
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Thu, 5 Nov 2026 16:11:12 -0500
umtool: a video entry is levelled to the cut (its narration's level when it has no render.loudness), its boost limited under -1 dBFS
Measured on the Puss in Boots finale: the source is -8.8 LUFS, the bass boost
took it to -4 with +8 dBFS peaks, and the AAC encoder squashed it (lows +2 dB,
mids -3 dB). Now videoLoudnessTarget levels it to the cut (-21 LUFS: the post
items' narration; the post before it measures -20.2) and alimiter keeps a
boost's peaks under full scale: bassier, not louder.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
4 files changed, 61 insertions(+), 17 deletions(-)
diff --git a/umtool/docs/report-video.md b/umtool/docs/report-video.md
@@ -437,8 +437,12 @@ cut's own transition into it. There is **no fade at its end**: as the LAST entry
final frame** -- `render.endFade` is not applied, and nothing is appended after it.
**Its sound** is levelled like a clip's: the bass boost first, the span measured through it (ebur128),
-one gain toward the cut's loudness target (`render.loudness`, when it has one) -- so a boosted video
-is as loud as the cut and louder in the lows; `audio.gain` after that, as a clip's `audio.gain` is.
+one gain toward the cut's level (`videoLoudnessTarget`): `render.loudness`'s target when it has one,
+else the level the cut's own voice sits at -- its post items' narration (`render.postNarration.lufs`,
+default −21 LUFS) or a narrated card's (−17.7) -- so a hot meme (the Puss in Boots clip is −8.8 LUFS)
+does not jump 9 dB out of the cut, and a boosted video is bassier, not louder; `audio.gain` after that, as a clip's `audio.gain` is; a boosted or gained sound is limited under
+−1 dBFS (`alimiter`), because the AAC encoder squashes what goes past full scale (measured: an 8 dB boost
+of the Puss in Boots clip peaked at +8 dBFS and came out with its lows +2 dB and its mids −3 dB).
**Its segment** is `lead + (to − from) + holdLast` (`videoSeconds`), the source span scaled per `fit`,
and is rebuilt only when its key changes (`segments/<id>.video.json`: the file's path, size and mtime,
diff --git a/umtool/report-to-video/build-video.mjs b/umtool/report-to-video/build-video.mjs
@@ -149,7 +149,7 @@ import {
} from "./sources.mjs";
// A clip whose media is a file beside the manifest (`src`, `cues`).
import { clipLabel, createLocalMedia, hasLocalMedia, resolveManifestPath, validateLocalMedia } from "./local-media.mjs";
-import { blackoutEnable, validateVideoEntries, videoBlackouts, videoFit, videoLead, videoMeasureFilter, videoSeconds, videoSegmentGraph, videoSegmentKey, videoSpan } from "./video-entry.mjs";
+import { blackoutEnable, validateVideoEntries, videoBlackouts, videoFit, videoLoudnessTarget, videoLead, videoMeasureFilter, videoSeconds, videoSegmentGraph, videoSegmentKey, videoSpan } from "./video-entry.mjs";
import { createPostChannelResolver, resolvePostLinks } from "./post-links.mjs";
import { ensureWriteDir } from "../lib/report/storage.mjs";
// The deck (`render.chrome`): its geometry, validation and schedule are pure
@@ -2924,7 +2924,7 @@ export async function buildTeaserSegment(entry, { manifestPath, render, outDir,
* Rebuilt only when its key (`<id>.video.json`) changes; every file written
* through a rename, so a take's hard-linked segment is never written through.
*/
-async function buildVideoEntrySegment(entry, render, outDir, baseDir, D) {
+async function buildVideoEntrySegment(entry, render, outDir, baseDir, D, timeline = []) {
const seg = path.join(outDir, "segments", `${entry.id}.mp4`);
const rec = path.join(outDir, "segments", `${entry.id}.video.json`);
const src = resolveManifestPath(baseDir, entry.src, { allowAbsolute: render.allowAbsoluteSrc === true });
@@ -2938,22 +2938,28 @@ async function buildVideoEntrySegment(entry, render, outDir, baseDir, D) {
const span = videoSpan(entry, media.duration);
const lead = videoLead(entry, D);
const seconds = videoSeconds(entry, D, media.duration);
- const target = hasAudio ? loudnessTargetOf(render) : null;
+ const { target: aim, basis } = videoLoudnessTarget(render, timeline, loudnessTargetOf(render));
+ const target = hasAudio ? aim : null;
const key = videoSegmentKey({ entry, file: { size: st.size, mtimeMs: Math.round(st.mtimeMs), seconds: media.duration }, render, lead, target });
const was = await readFile(rec, "utf8").then((t) => JSON.parse(t), () => null);
if (was?.key === key && (await exists(seg))) {
EMIT("note", { id: entry.id, message: `${entry.id}: video segment cached (${entry.src} ${span.from.toFixed(2)}–${span.to.toFixed(2)})` });
return seg;
}
- // Even loudness, as a clip's (render.look.loudness): the span measured THROUGH the bass boost, one gain.
- let level = null;
- if (target != null) {
+ // Even loudness, as a clip's: the span measured THROUGH the bass boost, one gain toward the cut's level
+ // (videoLoudnessTarget: render.loudness, else the level its narration sits at) -- a boost makes it
+ // bassier, not louder; a limiter keeps the peaks under full scale.
+ const measure = async (af) => {
const { stderr } = await execFileP(FFMPEG, [
"-nostdin", "-hide_banner", "-ss", span.from.toFixed(3), "-to", span.to.toFixed(3), "-i", src.file,
- "-vn", "-af", `${videoMeasureFilter(entry)},ebur128`, "-f", "null", "-",
+ "-vn", "-af", `${af},ebur128`, "-f", "null", "-",
], { maxBuffer: 1 << 26 }).catch((e) => ({ stderr: e.stderr ?? "" }));
- const measured = parseIntegratedLoudness(stderr);
- level = { measured, gain: loudnessGain(measured, target), target };
+ return parseIntegratedLoudness(stderr);
+ };
+ let level = null;
+ if (target != null) {
+ const measured = await measure(videoMeasureFilter(entry));
+ level = { measured, gain: loudnessGain(measured, target), target, basis };
}
const graph = videoSegmentGraph({ entry, render, seconds, lead, hasAudio, gainDb: level?.gain ?? null, span });
const tmp = `${seg}.tmp-${process.pid}.mp4`;
@@ -6801,7 +6807,7 @@ export async function buildVideo({ manifestPath, opts = {}, out, only, fetchOnly
// A video entry (video-entry.mjs): keyed like a post item, every file written through a rename.
if (entry.type === "video") {
EMIT("card", { id: entry.id, i, n: entries.length });
- return buildVideoEntrySegment(entry, render, outDir, manifestDir, D);
+ return buildVideoEntrySegment(entry, render, outDir, manifestDir, D, manifest.timeline);
}
if (entry.type !== "teaser" && entry.type !== "clip" && entry.type !== "post") {
await detachSegmentFiles(path.join(outDir, "segments"), entry.id);
diff --git a/umtool/report-to-video/video-entry.mjs b/umtool/report-to-video/video-entry.mjs
@@ -24,14 +24,17 @@
// fade (`render.endFade` is skipped), nothing after it.
//
// Its sound is levelled like a clip's: the bass boost first, the whole span
-// measured with it (ebur128), one gain toward `render.look.loudness`'s target
-// when the cut has one; `audio.gain` after that levelling, as a clip's
-// `audio.gain` is. Fades only where the join needs them: the fade up after
+// measured with it (ebur128), one gain toward the cut's level
+// (`videoLoudnessTarget`: `render.loudness`, else its narration's level); `audio.gain` after that levelling, as a
+// clip's `audio.gain` is; a boost's peaks limited under −1 dBFS. Fades only where the join needs them: the fade up after
// the entrance's black, none at its end.
//
// A LEAF: no imports from build-video.mjs (it imports this), so umtool's
// writers and Play read the same rules.
+import { NARRATION_DEFAULTS } from "./narration.mjs";
+import { POST_NARRATION_DEFAULTS } from "./post-narration.mjs";
+
const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
const fin = (v) => typeof v === "number" && Number.isFinite(v);
@@ -47,7 +50,9 @@ export const VIDEO_HOLD_MAX = 10;
/** The bass boost: a low shelf at this frequency and width (ffmpeg `bass`). */
export const VIDEO_BASS = Object.freeze({ f: 100, w: 0.7 });
/** Bumped when the segment's drawing or sound changes, so every key changes with it. */
-export const VIDEO_SEGMENT_V = 1;
+export const VIDEO_SEGMENT_V = 2;
+/** The ceiling a boosted video's sound is limited to: −1 dBFS. */
+export const VIDEO_LIMIT = 0.891;
/** The keys a video entry is SET by (umtool set / timeline add-video). */
export const VIDEO_SET_KEYS = Object.freeze(["src", "from", "to", "fit", "audio.bass", "audio.gain", "enter", "enter.out", "enter.in", "holdLast", "deck", "title", "note"]);
@@ -199,6 +204,8 @@ export function videoSegmentGraph({ entry, render, seconds, lead = 0, hasAudio =
...(bass ? [`bass=g=${n(bass)}:f=${VIDEO_BASS.f}:w=${VIDEO_BASS.w}`] : []),
...(gainDb ? [`volume=${n(gainDb)}dB`] : []),
...(gain ? [`volume=${n(gain)}dB`] : []),
+ // A boost's peaks under full scale (−1 dBFS): the encoder squashes what goes past it.
+ ...(bass > 0 || gain > 0 ? [`alimiter=limit=${VIDEO_LIMIT}:level=false`] : []),
...(en && en.in > 0 ? [`afade=t=in:st=0:d=${n(en.in)}`] : []),
...(ms > 0 ? [`adelay=${ms}:all=1`] : []),
`apad=whole_dur=${n(seconds)}`,
@@ -208,6 +215,23 @@ export function videoSegmentGraph({ entry, render, seconds, lead = 0, hasAudio =
return `${v};${a}`;
}
+/**
+ * The loudness (LUFS) a video entry's sound is levelled to: the cut's target
+ * (`render.loudness`, `loudnessTarget` the caller resolved) when it has one;
+ * else the level the cut's own voice sits at -- its post items' narration
+ * (`render.postNarration.lufs`, default −21) when it has post items, a
+ * narrated card's (−17.7) otherwise -- so a hot meme does not jump out of the
+ * cut. `{ target, basis }`.
+ */
+export function videoLoudnessTarget(render, timeline = [], loudnessTarget = null) {
+ if (fin(loudnessTarget)) return { target: loudnessTarget, basis: "render.loudness" };
+ if ((timeline ?? []).some((e) => e?.type === "post")) {
+ const l = render?.postNarration?.lufs;
+ return { target: fin(l) ? l : POST_NARRATION_DEFAULTS.lufs, basis: "render.postNarration.lufs" };
+ }
+ return { target: NARRATION_DEFAULTS.lufs, basis: "narration" };
+}
+
/** The audio chain the loudness is measured through: the bass boost, as the segment plays it. */
export function videoMeasureFilter(entry) {
const { bass } = videoAudio(entry);
diff --git a/umtool/report-to-video/video-entry.test.mjs b/umtool/report-to-video/video-entry.test.mjs
@@ -12,7 +12,7 @@ import test from "node:test";
import {
applyVideoPatch, blackoutEnable, validateVideoEntries, validateVideoEntry, videoBlackouts, videoDip, videoEnter,
- videoHidesChrome, videoLead, videoSeconds, videoSegmentGraph, videoSegmentKey, videoSpan,
+ videoHidesChrome, videoLead, videoLoudnessTarget, videoSeconds, videoSegmentGraph, videoSegmentKey, videoSpan,
} from "./video-entry.mjs";
import { deckSchedule, dipOf, estimatedDuration, hidesDeck, resolveDeck } from "./deck.mjs";
import { chromeOverlayChain, cutJoins } from "./build-video.mjs";
@@ -72,6 +72,9 @@ test("its graph: fit, the bass before the level, the fade up after the lead, no
// Bass first, then the measured level.
assert.ok(g.indexOf("bass=g=8:f=100:w=0.7") < g.indexOf("volume=-2.5dB"));
assert.match(g, /adelay=400:all=1/);
+ // A boost's peaks limited, after the level; none for a plain video.
+ assert.ok(g.indexOf("alimiter=limit=0.891:level=false") > g.indexOf("volume=-2.5dB"));
+ assert.doesNotMatch(videoSegmentGraph({ entry: { ...FIN, audio: undefined }, render, seconds: 14.46, lead: 0.4, span }), /alimiter/);
const cover = videoSegmentGraph({ entry: { ...FIN, fit: "cover", enter: "cut" }, render, seconds: 14.06, lead: 0, span });
assert.match(cover, /force_original_aspect_ratio=increase,crop=1920:1080/);
assert.doesNotMatch(cover, /fade=t=in|tpad|adelay/);
@@ -159,3 +162,10 @@ test("applyVideoPatch: dotted keys, enter forms, clearing, refusing a key it doe
// The original is untouched.
assert.deepEqual(FIN.audio, { bass: 8 });
});
+
+test("its level: the cut's target, else the level its narration sits at", () => {
+ assert.deepEqual(videoLoudnessTarget({}, [], -14), { target: -14, basis: "render.loudness" });
+ assert.deepEqual(videoLoudnessTarget({}, [{ type: "post" }]), { target: -21, basis: "render.postNarration.lufs" });
+ assert.deepEqual(videoLoudnessTarget({ postNarration: { lufs: -19 } }, [{ type: "post" }]), { target: -19, basis: "render.postNarration.lufs" });
+ assert.deepEqual(videoLoudnessTarget({}, [{ type: "clip" }]), { target: -17.7, basis: "narration" });
+});