commit 14e1d0d743fcda610bb8c68f9645319f47b7be0a
parent e28ee6a4d127288df9dfb4ba4a02da6025687dd6
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sun, 1 Nov 2026 23:07:05 -0500
umtool trailer: each clip beat's edges moved into the nearest pause -- its end forward (through its sentence when one ends within 1 s) far enough that the crossfade is in the quiet, its start back into the pause before it (report-to-video/pauses.mjs snapEdge, one pause rule shared with the bench's quietPoints and sentenceEdges' endsWithTerminal); the pauses are the master's silences over the segment and the gaps between the recording's timed words (clip-words.mjs: words.json, a whisper transcript, else the captions' <c> word starts); never more than 1 s, past the master's crossfades, the cut record's end, a gap's join or into the next piece; each move a note naming the word, `--no-snap` keeps the edges as written; the plan and record's source seconds now count the clip's gaps (sourceAtOffset); tested on Ember draft-24's pre-fix beats (fixture)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
13 files changed, 1734 insertions(+), 31 deletions(-)
diff --git a/umtool/docs/cli.md b/umtool/docs/cli.md
@@ -57,7 +57,7 @@ Inbox cannot disagree about what is wrong with one.
| `takes make <project> [--recipe FILE] [--only ID,ID] [--force]` · `takes make <project> --all-styles [--group G] [--at S --dur S \| --full]` | a recipe's takes, one at a time (default `takes/recipe.json`); every montage style, one take each (Make all styles); **exit 1** if any failed |
| `takes styles [--json]` · `takes effects <project> [--json]` · `takes pick <project> <take> [--anyway] [--pin \| --unpin] [--json]` | the montage styles; the overlay effects the cut offers (`render.chrome.fx` presets: the Takes page's **Effect** list); **Use this take** — refused (exit 1) when the project changed since the take was made, until `--anyway`; `--pin` keeps the pick when newer takes are built (each whole-cut take of the manifest is otherwise its group's pick once built), `--unpin` lets go ([report-video.md](report-video.md#takes-alternative-renders-judged-side-by-side)) |
| `takes ls <project> [--json]` · `takes relabel <project> <take> <label…>` · `takes supersede <project> <take> [--by <take>]` · `takes supersede <project> <take> --clear` · `takes delete <project> <take> [--dry-run] [--force]` | **take housekeeping** (the Takes page's ✎, **Mark superseded**, **Delete take**): first the working cut's line (`Latest: draft-22 · 28:03 · +N edits since`, and the edits in words; `--json`: `working`), then the takes with latest / picked (pinned) / superseded / RENDERING; a label fixed in `take.json` (an undo point of the take's own); a take folded away as superseded (verdicts.json, nothing deleted); a take deleted. Relabel and delete are refused (**exit 1**) while the take renders or a live render is made from it ([knobs.md](knobs.md#takes-relabel-supersede-delete)) |
-| `trailer <project> --take <t> (--beats FILE \| --beats-json JSON) [--intro] [--finale S] [--xfade 0.3] [--out NAME] [--dry-run] [--json]` | a **trailer cut from the take's finished master**: spans of the master's own frames (the deck shows the whole timeline), clip beats in source seconds mapped by the take's build records, crossfaded, the take's encode, in the heavy slot; writes `takes/<t>/out/<slug>.trailer.mp4` and `.trailer.json`; **exit 1** on a refusal ([report-video.md](report-video.md#trailer-from-the-master)) |
+| `trailer <project> --take <t> (--beats FILE \| --beats-json JSON) [--intro] [--finale S] [--xfade 0.3] [--no-snap] [--out NAME] [--dry-run] [--json]` | a **trailer cut from the take's finished master**: spans of the master's own frames (the deck shows the whole timeline), clip beats in source seconds mapped by the take's build records, each clip beat's end moved forward into the next pause (through its sentence when one ends within 1 s) and its start back into the one before, so the crossfade lands in quiet, each move said (`--no-snap`: the edges as written), crossfaded, the take's encode, in the heavy slot; writes `takes/<t>/out/<slug>.trailer.mp4` and `.trailer.json`; **exit 1** on a refusal ([report-video.md](report-video.md#trailer-from-the-master)) |
| `trailer-beats <project> [ls] [--json]` · `add <clip> [<from>-<to>] [--at N] [--label L]` · `add-raw <at> <dur>` · `set <n> <from>-<to>` · `remove <n>` · `move <n> --to <m>` · `order` · `limit <s\|m:ss\|x\|instagram\|shorts\|tiktok>` · `xfade <s>` · `intro on\|off` · `candidates [--add]` | **the trailer's beats** (`promo/trailer-beats.json`, the Trailer page's file, what `trailer --beats` reads): each beat's length, the running length against the platform limit (X 2:20 by default), beats outside their clip's window, the cut's order, the walk's ★ clips ([knobs.md](knobs.md#the-trailers-beats)) |
| `rulings <project> [--json]` · `rulings <project> import [--dry-run] [--json]` · `rulings <project> set <clip\|key> keep\|cut\|not-him\|read-aloud [--reason R] [--match M]` · `rulings <project> clear <clip\|key>` | a montage's **clip rulings** (`montage-rulings.json`, the clip deck's): each clip and its ruling and the next render's kept clips; the earlier rulings in the seed's `edits.json`, once; one ruling set or cleared. A render leaves out every clip ruled cut, not-him or read-aloud ([report-video.md](report-video.md#ruling-the-clips)) |
| `fetch <project> --body` · `fetch <project> --dry-run [--json]` · `fetch <project> [--wait] [--json]` · `fetch <project> --status [--json]` · `… [--reason R]` · `… --refetch <clipId>[,…]` · `… --refetch-video <slug>/<id>` | **Fetch windows** (the Cut tab's and the clip deck's button): every clip's window asked of the editor as ONE fetch-windows batch — `--body` prints the body and asks nobody; `--dry-run` the editor's plan (groups per platform, cached, in flight, unresolved); no flag starts it (one paced job per platform queue), `--wait` follows the jobs to their end and names each window a job failed; `--status` follows the last run's jobs once. Clips the montage rulings leave out are not asked for. `--refetch <clipId>[,<clipId>…]` evicts the cached windows that OVERLAP those clips' fetch spans first (the editor's `evict-clips` `{slug, id, covering}`, one job per video, waited for), then fetches as usual — for windows known bad (cut from a corrupt saved video); `--refetch-video <slug>/<id>` does it for every window the project asks of that video; with `--dry-run` the eviction is a dry run too and names what it would remove. Every run is recorded in `<project>/fetch-runs.json` (a refetch's evictions under `refetch`). Needs WORKER_TOKEN (else the editor's env files) and the editor at ARCHILYZER_EDITOR_URL. **Exit 1** when a job failed or the editor refused ([report-video.md](report-video.md#fetching-the-windows-and-stand-ins)) |
diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md
@@ -536,7 +536,10 @@ default; Instagram 1:30, a Short 3:00, TikTok 10:00, or seconds) with the traile
longer in the cut, and whether the beats are in the cut's order. A beat is `{id, start, end, label?}` (source
seconds of a clip) or `{at, dur}` (master seconds), numbered from 1 as `umtool trailer` numbers them. The file keeps
its shape (an array, until a setting makes it `{limit, xfade, intro, beats}`, which `--beats` reads too) and its
-indent; one that does not parse is never written over; a write over a newer file is a 409.
+indent; one that does not parse is never written over; a write over a newer file is a 409. The lengths are the beats as
+written: `umtool trailer` then moves each clip beat's edges into the nearest pauses (up to 1 s each way, said per
+edge; `--no-snap` keeps them), so a trailer can come out a few tenths of a second per beat longer than the running
+length here ([report-video.md](report-video.md#trailer-from-the-master)).
| | In umtool | From a terminal | Route |
|---|---|---|---|
diff --git a/umtool/docs/report-video.md b/umtool/docs/report-video.md
@@ -1309,7 +1309,7 @@ its log says so, rather than refused as emptied.
### Trailer from the master
`umtool trailer <project> --take <t> (--beats FILE | --beats-json JSON) [--intro] [--finale S]
-[--xfade 0.3] [--out NAME] [--dry-run] [--json]` cuts a trailer out of a finished take's master
+[--xfade 0.3] [--no-snap] [--out NAME] [--dry-run] [--json]` cuts a trailer out of a finished take's master
(`takes/<t>/out/<slug>.mp4`). The trailer is the master's own frames, so the deck's rail, dates,
pips and running tallies show the whole video's timeline, and a viewer can see the full version
has more. Nothing is rendered again: it is one ffmpeg pass over the finished file.
@@ -1327,12 +1327,30 @@ A beat is either:
A clip beat is mapped with the take's build records. `out/sourced/schedule.json` gives the
segment's start in the cut. `out/sourced/segments/<id>.cut.json` gives the source second the
segment really starts at (snapped to a silence, room included). Source second *s* plays at master
-second `segment.start + (s − cut.start)`. `--intro` opens on the master's brand intro.
+second `segment.start + (s − cut.start)`, less the clip's gaps before it; the source seconds the
+plan and the record print count the gaps too (`gaps.mjs` sourceAtOffset). `--intro` opens on the master's brand intro.
`--finale S` closes on the master's last *S* seconds, where the finale's timeline is.
- **The master's own crossfades.** Each join of the master is a `render.transition`-second
dissolve. If a beat's edge falls inside one, the edge is moved in, but only until the trailer's
own crossfade hides what is left. Each moved edge is printed as a note.
+- **Edges into pauses.** The trailer's crossfade overlaps a beat's last `--xfade` seconds with
+ the next beat's first, so an edge just after a word starts fades the word out, and one before a
+ sentence's last word cuts it. Each clip beat's END moves forward into the next pause, far enough
+ that the fade is in the quiet (`pause.from + xfade`, or the pause's end when it is shorter, never
+ past the next word's start). When the recording's words are known and a sentence ends (. ? !)
+ within 1 s of the edge, the end goes through that sentence first. Each START moves back into
+ the pause before it (`pause.to − xfade`). A hard cut (`--xfade 0`, or the trailer's first start
+ and last end) wants 0.1 s of quiet. The pauses are the master's silences over the segment (the
+ build's `detectSilence`, the take's `render.silenceMinDur`/`silenceRelDb`) and the gaps between
+ timed words. The words come from `clip-words.mjs`: the corpus's `words.json`, else a whisper
+ `transcript.json`, else the caption track's `<c>` word starts; never a cue spread by its
+ characters. An edge never moves more than 1 s (`SNAP_MAX_SHIFT`, `pauses.mjs`), past the
+ master's crossfades, the cut record's end, a gap's join, or into the piece next to it in the
+ master. Each move is a note naming the word, e.g. `beat 8 tr3: end 3011.20 → 3012.09 (pause
+ after "type.", the sentence's end)`. So is an edge left where it was because its pause is too
+ far. `--no-snap` keeps the edges as written. A raw beat, the intro and the finale are never
+ moved. The record keeps each move (`snapped`) and whether snapping was on (`snap`).
- **Seamless runs.** If a piece starts inside the piece before it, or where it ends, the two are
one run of the master with no crossfade, and no frame plays twice. This happens with the intro
and a first beat in the first clip, and with a last beat and the finale.
diff --git a/umtool/lib/report/benchZoom.mjs b/umtool/lib/report/benchZoom.mjs
@@ -10,6 +10,8 @@
// cached window (what the waveform shows at fit -- today's view); `vis` the
// stretch of it shown now.
+import { pausePoints } from "umtool-report-to-video/pauses";
+
/** The closest the waveform zooms: a quarter of a second across its width. */
export const MIN_ZOOM_SPAN = 0.25;
/** One step of + / − (and of a wheel notch, scaled by its delta). */
@@ -99,22 +101,14 @@ export function tickLabel(t, step) {
/**
* The gaps between words, as places an edge or a gap's edge can go: for each
* pause between consecutive words (or cues), its middle; and every measured
- * silence's middle. Sorted, deduplicated within 20 ms. In [from, to].
+ * silence's middle. Sorted, deduplicated within 20 ms. In [from, to]. The
+ * pause arithmetic is report-to-video/pauses.mjs's (pausePoints), the one the
+ * trailer lands its crossfades by.
*
* @param {{ words?: Array<{ start: number, end: number }> | null, silences?: Array<{ from: number, to: number }> | null }} o
* @param {number} from
* @param {number} to
*/
export function quietPoints({ words = null, silences = null }, from, to) {
- const pts = [];
- const ws = (words ?? []).filter((w) => fin(w.start) && fin(w.end)).sort((a, b) => a.start - b.start);
- for (let i = 1; i < ws.length; i += 1) {
- if (ws[i].start >= ws[i - 1].end) pts.push((ws[i - 1].end + ws[i].start) / 2);
- }
- for (const s of silences ?? []) if (fin(s.from) && fin(s.to)) pts.push((s.from + s.to) / 2);
- const out = [];
- for (const p of pts.filter((x) => x >= from && x <= to).sort((a, b) => a - b)) {
- if (!out.length || p - out[out.length - 1] > 0.02) out.push(round4(p));
- }
- return out;
+ return pausePoints({ words, silences }, from, to);
}
diff --git a/umtool/lib/report/sentenceEdges.mjs b/umtool/lib/report/sentenceEdges.mjs
@@ -24,6 +24,8 @@
//
// Pure: no DOM, no React. Absolute source seconds throughout, like the bench.
+import { endsSentence as textEndsSentence } from "umtool-report-to-video/pauses";
+
/** A pause this long between two cues is a sentence boundary, punctuation or not. */
export const SENTENCE_GAP = 1.5;
@@ -33,11 +35,9 @@ export const SNAP_RADIUS = 0.6;
/** Two boundaries closer than this are one (a cue's end and the next one's start). */
const SAME = 0.05;
-const TERMINAL = /[.?!]["')\]”’]*\s*$/;
-
-/** Does this text close a sentence by its punctuation? */
+/** Does this text close a sentence by its punctuation? (report-to-video/pauses.mjs endsSentence: one rule.) */
export function endsWithTerminal(text) {
- return TERMINAL.test(String(text ?? ""));
+ return textEndsSentence(text);
}
const fin = (v) => typeof v === "number" && Number.isFinite(v);
diff --git a/umtool/lib/report/trailerCli.mjs b/umtool/lib/report/trailerCli.mjs
@@ -3,7 +3,7 @@
// report-to-video/trailer.mjs; this is the command line around it.
//
// umtool trailer <project> --take <t> (--beats FILE | --beats-json JSON)
-// [--intro] [--finale S] [--xfade 0.3] [--out NAME] [--dry-run] [--json]
+// [--intro] [--finale S] [--xfade 0.3] [--no-snap] [--out NAME] [--dry-run] [--json]
// umtool trailer <project> --candidates [--json] the walk's ★ clips as beats
import { readFile } from "node:fs/promises";
import path from "node:path";
@@ -23,13 +23,16 @@ import {
export const TRAILER_USAGE = [
"usage: umtool trailer <project> --take <t> (--beats FILE | --beats-json JSON)",
- ` [--intro] [--finale S] [--xfade ${TRAILER_XFADE_DEFAULT}] [--out NAME] [--dry-run] [--json]`,
+ ` [--intro] [--finale S] [--xfade ${TRAILER_XFADE_DEFAULT}] [--no-snap] [--out NAME] [--dry-run] [--json]`,
"",
"A trailer cut from the take's finished master (takes/<t>/out/<slug>.mp4): spans of the master's own",
"frames, so the deck's rail, dates and tallies show the whole video's timeline. Nothing is rendered again.",
"A beat is { \"id\": \"<clip>\", \"start\": <source s>, \"end\": <source s> } (mapped to the master by the",
"take's build records) or { \"at\": <master s>, \"dur\": <s> }. --intro opens on the master's brand intro;",
"--finale S closes on its last S seconds. Joined with S-second crossfades (--xfade 0: hard cuts),",
+ "each clip beat's end moved forward into the next pause (through its sentence when one ends within 1 s)",
+ "and its start back into the one before, so the crossfade lands in quiet -- the master's silences and the",
+ "recording's words; never past the segment's own clip, each move said (--no-snap: the edges as written).",
"encoded with the take's render settings, in the heavy slot. Writes takes/<t>/out/<slug>.trailer.mp4",
"(--out NAME: that name there; a path: exactly there) and <name>.trailer.json beside it, what was cut.",
"--dry-run prints the mapping and writes nothing.",
@@ -52,7 +55,7 @@ function parse(args) {
if (valued.has(a)) {
if (i + 1 >= args.length) throw new CliError(`${a} needs a value`);
flags[a] = args[++i];
- } else if (["--intro", "--json", "--dry-run", "--help", "--candidates"].includes(a)) flags[a] = "";
+ } else if (["--intro", "--json", "--dry-run", "--help", "--candidates", "--no-snap"].includes(a)) flags[a] = "";
else throw new CliError(`unknown flag ${a}`);
} else positional.push(a);
}
@@ -150,6 +153,8 @@ export async function trailerCommand(args, { reportsRoot = REPORTS_ROOT, log = c
xfade: seconds(p, "--xfade", TRAILER_XFADE_DEFAULT),
out: p.flags["--out"] ?? null,
dryRun: p.has("--dry-run"),
+ snap: !p.has("--no-snap"),
+ ...(deps.measure ? { measure: deps.measure } : {}),
...(deps.run ? { run: deps.run } : {}),
...(deps.probe ? { probe: deps.probe } : {}),
slot: (fn) => {
diff --git a/umtool/report-to-video/clip-words.mjs b/umtool/report-to-video/clip-words.mjs
@@ -0,0 +1,114 @@
+// A CLIP'S WORDS, for where its edges may go (pauses.mjs; 2026-11-02).
+//
+// What the trailer (and the clip editor's pause snap) reads to know where a
+// recording's words start and what they say, in SOURCE seconds, from the
+// corpus beside the recording -- the first of:
+//
+// data/<id>/words.json the word-timings sidecar (common
+// wordTimings-server.ts): timed words
+// data/<id>/transcript.json a whisper transcript's tokens (montage.mjs
+// whisperWords): timed words
+// the English caption track YouTube's en-orig `<c>` word timings (the
+// cue record's `vttFile`, else transcript.en-orig.vtt,
+// else transcript.en.vtt): each word's START only
+//
+// Never a cue spread by its characters (fx.mjs fxWordsOf): those places are
+// made up, and a pause read off them is not a pause. A clip from a file beside
+// the manifest, a recording the corpus does not hold, or one with none of the
+// three: null -- the caller goes by the silences alone.
+//
+// Reads only. Plain ESM.
+import { readFile } from "node:fs/promises";
+import path from "node:path";
+import { resolveVideoDir } from "yt-dlp-transcript-common/lib/videoDir-server.mjs";
+import { hasLocalMedia } from "./local-media.mjs";
+import { whisperWords } from "./montage.mjs";
+
+const fin = (v) => typeof v === "number" && Number.isFinite(v);
+
+/** `hh:mm:ss.mmm` (or `mm:ss.mmm`) as seconds. */
+function clockSeconds(s) {
+ const parts = String(s).split(":").map(Number);
+ return parts.reduce((acc, n) => acc * 60 + n, 0);
+}
+
+const ENTITIES = { " ": " ", "&": "&", "<": "<", ">": ">", """: '"', "'": "'", "'": "'" };
+const decode = (s) => String(s).replace(/&(?:nbsp|amp|lt|gt|quot|apos|#39);/g, (m) => ENTITIES[m] ?? m);
+
+/**
+ * A word-timed caption track's words: `{ start, text }` for each word YouTube
+ * timed with `<hh:mm:ss.mmm><c> word</c>` (the first on a line at its cue's
+ * start). The rolling track repeats each line without its tags: those are
+ * skipped, as is a word timed twice. Empty for a track without word timing.
+ *
+ * @param {string} vtt
+ * @returns {Array<{ start: number, text: string }>}
+ */
+export function vttWordStarts(vtt) {
+ const seen = new Set();
+ const out = [];
+ let cueStart = null;
+ const push = (start, text) => {
+ const t = decode(text).replace(/\s+/g, " ").trim();
+ if (!t || !fin(start)) return;
+ const key = `${start.toFixed(3)}|${t}`;
+ if (seen.has(key)) return;
+ seen.add(key);
+ out.push({ start, text: t });
+ };
+ for (const line of String(vtt ?? "").split(/\r?\n/)) {
+ const head = line.match(/^((?:\d+:)?\d{2}:\d{2}\.\d{3})\s+-->\s+/);
+ if (head) {
+ cueStart = clockSeconds(head[1]);
+ continue;
+ }
+ if (!line.includes("<c>") || cueStart === null) continue;
+ push(cueStart, line.split("<")[0]);
+ for (const m of line.matchAll(/<((?:\d+:)?\d{2}:\d{2}\.\d{3})><c>([^<]*)<\/c>/g)) push(clockSeconds(m[1]), m[2]);
+ }
+ return out.sort((a, b) => a.start - b.start);
+}
+
+/**
+ * The clip's recording's words in [from, to] (source seconds), and where they
+ * came from: `{ words, timed, from }`, or null (see the header).
+ *
+ * @param {{ channel?: string, video?: string, src?: string }} entry
+ * @param {{ channelSlug?: string } | null | undefined} provenance
+ * @param {number} from
+ * @param {number} to
+ * @param {{ channelsDir: string | null }} o
+ * @returns {Promise<{ words: Array<{ start: number, end?: number, text: string }>, timed: boolean, from: "words.json" | "transcript.json" | "captions" } | null>}
+ */
+export async function clipWords(entry, provenance, from, to, { channelsDir }) {
+ if (!channelsDir || !entry?.video || hasLocalMedia(entry)) return null;
+ const slug = entry.channel ?? provenance?.channelSlug;
+ if (!slug) return null;
+ const dir = await resolveVideoDir(channelsDir, slug, entry.video).catch(() => null);
+ if (!dir) return null;
+ const json = (name) => readFile(path.join(dir, name), "utf8").then((t) => JSON.parse(t), () => null);
+ const inSpan = (w) => w.start >= from && w.start <= to;
+
+ const sidecar = await json("words.json");
+ if (Array.isArray(sidecar?.words) && sidecar.words.length) {
+ const words = sidecar.words
+ .map((w) => ({ start: Number(w?.start), end: Number(w?.end), text: String(w?.w ?? w?.word ?? w?.text ?? "") }))
+ .filter((w) => fin(w.start) && fin(w.end) && inSpan(w));
+ if (words.length) return { words, timed: true, from: "words.json" };
+ }
+ const whisper = await json("transcript.json");
+ const ww = whisper ? whisperWords(whisper, from, to) : null;
+ if (ww?.length) {
+ const words = ww.map((w) => ({ start: w.start, end: w.end, text: w.text })).filter(inSpan);
+ if (words.length) return { words, timed: true, from: "transcript.json" };
+ }
+ const cues = await json("transcript.cues.json");
+ const names = [...new Set([typeof cues?.vttFile === "string" ? path.basename(cues.vttFile) : null, "transcript.en-orig.vtt", "transcript.en.vtt"].filter(Boolean))];
+ for (const name of names) {
+ const text = await readFile(path.join(dir, name), "utf8").catch(() => null);
+ if (!text) continue;
+ const words = vttWordStarts(text).filter(inSpan);
+ if (words.length) return { words, timed: false, from: "captions" };
+ }
+ return null;
+}
diff --git a/umtool/report-to-video/fixtures/ember-draft-24-trailer.json b/umtool/report-to-video/fixtures/ember-draft-24-trailer.json
@@ -0,0 +1,881 @@
+{
+ "about": "The minimum of EmberParadox 'in her own words' take draft-24 that the trailer's edge snapping is tested on: the beats as they were before the operator's hand fix (night1101 trailer-beats.pre-words.json), each clip's segment in the master (out/sourced/schedule.json, transition 0.4, 30 fps), its cut record (segments/<id>.cut.json), the master's silences within 2.5 s of each beat edge (cut-points.mjs detectSilence with the take's render settings, master seconds), and the caption words near each edge (clip-words.mjs: YouTube's en-orig word starts, source seconds; none for a recording transcribed without them).",
+ "fps": 30,
+ "transition": 0.4,
+ "total": 1790,
+ "order": [
+ "b01",
+ "c01",
+ "tr3",
+ "u01",
+ "kr1",
+ "bk3"
+ ],
+ "beats": [
+ {
+ "id": "b01",
+ "start": 1816.29,
+ "end": 1818.65
+ },
+ {
+ "id": "c01",
+ "start": 216.6,
+ "end": 220.95
+ },
+ {
+ "id": "tr3",
+ "start": 2988.36,
+ "end": 3011.2
+ },
+ {
+ "id": "u01",
+ "start": 9476.7,
+ "end": 9484.95
+ },
+ {
+ "id": "kr1",
+ "start": 4814.95,
+ "end": 4818.1
+ },
+ {
+ "id": "bk3",
+ "start": 119,
+ "end": 123.3
+ },
+ {
+ "id": "tr3",
+ "start": 3011.95,
+ "end": 3017.63
+ }
+ ],
+ "clips": {
+ "b01": {
+ "segment": {
+ "id": "b01",
+ "type": "clip",
+ "start": 25.9,
+ "end": 34.6
+ },
+ "record": {
+ "start": 1815.979,
+ "end": 1824.65
+ },
+ "silences": [
+ {
+ "s": 25.9,
+ "e": 26.35
+ },
+ {
+ "s": 27.02,
+ "e": 27.166
+ },
+ {
+ "s": 27.465,
+ "e": 27.628
+ },
+ {
+ "s": 27.828,
+ "e": 27.933
+ },
+ {
+ "s": 28.07,
+ "e": 28.165
+ },
+ {
+ "s": 28.528,
+ "e": 28.631
+ },
+ {
+ "s": 28.755,
+ "e": 28.9
+ },
+ {
+ "s": 28.981,
+ "e": 29.102
+ },
+ {
+ "s": 29.326,
+ "e": 29.465
+ },
+ {
+ "s": 29.671,
+ "e": 30.091
+ },
+ {
+ "s": 30.968,
+ "e": 31.061
+ }
+ ],
+ "words": [
+ {
+ "start": 1816.48,
+ "text": "Men"
+ },
+ {
+ "start": 1816.799,
+ "text": "only."
+ },
+ {
+ "start": 1817.279,
+ "text": "Okay."
+ },
+ {
+ "start": 1817.679,
+ "text": "Well,"
+ },
+ {
+ "start": 1817.919,
+ "text": "I'm"
+ },
+ {
+ "start": 1818.24,
+ "text": "not"
+ },
+ {
+ "start": 1818.399,
+ "text": "a"
+ },
+ {
+ "start": 1818.559,
+ "text": "man."
+ },
+ {
+ "start": 1818.72,
+ "text": "So,"
+ },
+ {
+ "start": 1818.96,
+ "text": "I'm"
+ },
+ {
+ "start": 1819.12,
+ "text": "curious"
+ },
+ {
+ "start": 1819.36,
+ "text": "what"
+ },
+ {
+ "start": 1819.52,
+ "text": "the"
+ },
+ {
+ "start": 1819.6,
+ "text": "question"
+ },
+ {
+ "start": 1819.76,
+ "text": "is."
+ },
+ {
+ "start": 1820.159,
+ "text": "How"
+ },
+ {
+ "start": 1820.32,
+ "text": "much"
+ },
+ {
+ "start": 1820.399,
+ "text": "of"
+ },
+ {
+ "start": 1820.559,
+ "text": "the"
+ },
+ {
+ "start": 1820.72,
+ "text": "domestic"
+ }
+ ],
+ "timed": false,
+ "wordsFrom": "captions"
+ },
+ "c01": {
+ "segment": {
+ "id": "c01",
+ "type": "clip",
+ "start": 600.633,
+ "end": 607.4
+ },
+ "record": {
+ "start": 216.588,
+ "end": 223.329
+ },
+ "silences": [
+ {
+ "s": 600.633,
+ "e": 600.793
+ },
+ {
+ "s": 601.287,
+ "e": 601.412
+ },
+ {
+ "s": 602.579,
+ "e": 602.843
+ },
+ {
+ "s": 602.909,
+ "e": 603.008
+ },
+ {
+ "s": 603.539,
+ "e": 603.644
+ },
+ {
+ "s": 604.047,
+ "e": 604.152
+ },
+ {
+ "s": 604.684,
+ "e": 604.801
+ },
+ {
+ "s": 604.919,
+ "e": 605.243
+ },
+ {
+ "s": 605.345,
+ "e": 605.452
+ },
+ {
+ "s": 606.136,
+ "e": 606.255
+ },
+ {
+ "s": 606.64,
+ "e": 606.733
+ },
+ {
+ "s": 606.824,
+ "e": 607.364
+ }
+ ],
+ "words": [
+ {
+ "start": 216.07999999999998,
+ "text": "It"
+ },
+ {
+ "start": 216.4,
+ "text": "is."
+ },
+ {
+ "start": 216.72,
+ "text": "And"
+ },
+ {
+ "start": 216.959,
+ "text": "yes,"
+ },
+ {
+ "start": 217.28,
+ "text": "I"
+ },
+ {
+ "start": 217.519,
+ "text": "use"
+ },
+ {
+ "start": 217.76,
+ "text": "a"
+ },
+ {
+ "start": 217.92000000000002,
+ "text": "voice"
+ },
+ {
+ "start": 218.239,
+ "text": "changer."
+ },
+ {
+ "start": 218.799,
+ "text": "If"
+ },
+ {
+ "start": 218.959,
+ "text": "you"
+ },
+ {
+ "start": 219.12,
+ "text": "don't"
+ },
+ {
+ "start": 219.2,
+ "text": "like"
+ },
+ {
+ "start": 219.36,
+ "text": "it,"
+ },
+ {
+ "start": 219.599,
+ "text": "you"
+ },
+ {
+ "start": 219.68,
+ "text": "know"
+ },
+ {
+ "start": 219.84,
+ "text": "where"
+ },
+ {
+ "start": 220,
+ "text": "the"
+ },
+ {
+ "start": 220.159,
+ "text": "[ __ ]"
+ },
+ {
+ "start": 220.4,
+ "text": "door"
+ },
+ {
+ "start": 220.64,
+ "text": "is."
+ },
+ {
+ "start": 221.12,
+ "text": "Stop"
+ },
+ {
+ "start": 221.36,
+ "text": "giving"
+ },
+ {
+ "start": 221.519,
+ "text": "me"
+ },
+ {
+ "start": 221.68,
+ "text": "[ __ ]"
+ },
+ {
+ "start": 221.92000000000002,
+ "text": "about"
+ },
+ {
+ "start": 222,
+ "text": "it,"
+ },
+ {
+ "start": 222.239,
+ "text": "please."
+ },
+ {
+ "start": 222.56,
+ "text": "Thank"
+ },
+ {
+ "start": 222.72,
+ "text": "you."
+ }
+ ],
+ "timed": false,
+ "wordsFrom": "captions"
+ },
+ "kr1": {
+ "segment": {
+ "id": "kr1",
+ "type": "clip",
+ "start": 1409.567,
+ "end": 1423.133
+ },
+ "record": {
+ "start": 4814.643,
+ "end": 4828.15
+ },
+ "silences": [
+ {
+ "s": 1409.567,
+ "e": 1410.017
+ },
+ {
+ "s": 1412.903,
+ "e": 1413.277
+ },
+ {
+ "s": 1414.047,
+ "e": 1414.167
+ }
+ ],
+ "words": [
+ {
+ "start": 4813.864,
+ "text": "This"
+ },
+ {
+ "start": 4814.065,
+ "text": "is"
+ },
+ {
+ "start": 4814.985,
+ "text": "This"
+ },
+ {
+ "start": 4815.144,
+ "text": "is"
+ },
+ {
+ "start": 4815.264,
+ "text": "a"
+ },
+ {
+ "start": 4815.344,
+ "text": "man"
+ },
+ {
+ "start": 4815.704,
+ "text": "who"
+ },
+ {
+ "start": 4815.864,
+ "text": "lied"
+ },
+ {
+ "start": 4816.184,
+ "text": "to"
+ },
+ {
+ "start": 4816.304,
+ "text": "everyone"
+ },
+ {
+ "start": 4816.864,
+ "text": "about"
+ },
+ {
+ "start": 4817.184,
+ "text": "being"
+ },
+ {
+ "start": 4817.425,
+ "text": "a"
+ },
+ {
+ "start": 4817.505,
+ "text": "woman."
+ },
+ {
+ "start": 4818.224,
+ "text": "When"
+ },
+ {
+ "start": 4818.425,
+ "text": "he"
+ },
+ {
+ "start": 4818.545,
+ "text": "was"
+ },
+ {
+ "start": 4818.784,
+ "text": "asked"
+ },
+ {
+ "start": 4819.144,
+ "text": "about"
+ },
+ {
+ "start": 4819.344,
+ "text": "his"
+ },
+ {
+ "start": 4819.505,
+ "text": "voice"
+ },
+ {
+ "start": 4819.824,
+ "text": "changer,"
+ },
+ {
+ "start": 4820.224,
+ "text": "he"
+ },
+ {
+ "start": 4820.344,
+ "text": "would"
+ },
+ {
+ "start": 4820.505,
+ "text": "do"
+ }
+ ],
+ "timed": false,
+ "wordsFrom": "captions"
+ },
+ "tr3": {
+ "segment": {
+ "id": "tr3",
+ "type": "clip",
+ "start": 742.567,
+ "end": 772.6
+ },
+ "record": {
+ "start": 2987.989,
+ "end": 3017.995
+ },
+ "silences": [
+ {
+ "s": 742.567,
+ "e": 743.017
+ },
+ {
+ "s": 743.258,
+ "e": 743.544
+ },
+ {
+ "s": 743.687,
+ "e": 743.789
+ },
+ {
+ "s": 744.92,
+ "e": 745.346
+ },
+ {
+ "s": 763.326,
+ "e": 763.942
+ },
+ {
+ "s": 764.481,
+ "e": 764.859
+ },
+ {
+ "s": 765.482,
+ "e": 766.021
+ },
+ {
+ "s": 766.379,
+ "e": 766.84
+ },
+ {
+ "s": 767.624,
+ "e": 767.97
+ },
+ {
+ "s": 768.771,
+ "e": 768.963
+ },
+ {
+ "s": 769.732,
+ "e": 770.359
+ },
+ {
+ "s": 771.816,
+ "e": 771.925
+ },
+ {
+ "s": 772.022,
+ "e": 772.6
+ }
+ ],
+ "words": [
+ {
+ "start": 2988.36,
+ "text": "So,"
+ },
+ {
+ "start": 2988.84,
+ "text": "actual"
+ },
+ {
+ "start": 2989.44,
+ "text": "trans"
+ },
+ {
+ "start": 2989.88,
+ "text": "people,"
+ },
+ {
+ "start": 2990.64,
+ "text": "I've"
+ },
+ {
+ "start": 3009.28,
+ "text": "every"
+ },
+ {
+ "start": 3010.24,
+ "text": "[ __ ]"
+ },
+ {
+ "start": 3011.4,
+ "text": "type."
+ },
+ {
+ "start": 3012.16,
+ "text": "You"
+ },
+ {
+ "start": 3012.32,
+ "text": "don't"
+ },
+ {
+ "start": 3012.6,
+ "text": "like"
+ },
+ {
+ "start": 3012.84,
+ "text": "it?"
+ },
+ {
+ "start": 3013.44,
+ "text": "[ __ ]"
+ },
+ {
+ "start": 3014.2,
+ "text": "deal"
+ },
+ {
+ "start": 3015.68,
+ "text": "Autogynephiliac"
+ },
+ {
+ "start": 3018.08,
+ "text": "[ __ ]"
+ }
+ ],
+ "timed": false,
+ "wordsFrom": "captions"
+ },
+ "u01": {
+ "segment": {
+ "id": "u01",
+ "type": "clip",
+ "start": 1090.1,
+ "end": 1110.133
+ },
+ "record": {
+ "start": 9443.54,
+ "end": 9485.32,
+ "gaps": [
+ {
+ "from": 9451.607,
+ "to": 9452.607
+ },
+ {
+ "from": 9455.94,
+ "to": 9476.707
+ }
+ ]
+ },
+ "silences": [
+ {
+ "s": 1098.569,
+ "e": 1099.235
+ },
+ {
+ "s": 1099.868,
+ "e": 1099.999
+ },
+ {
+ "s": 1100.882,
+ "e": 1101.067
+ },
+ {
+ "s": 1101.12,
+ "e": 1101.218
+ },
+ {
+ "s": 1101.317,
+ "e": 1101.608
+ },
+ {
+ "s": 1103.302,
+ "e": 1103.411
+ },
+ {
+ "s": 1103.764,
+ "e": 1103.855
+ },
+ {
+ "s": 1107.3,
+ "e": 1107.877
+ },
+ {
+ "s": 1108.257,
+ "e": 1108.362
+ },
+ {
+ "s": 1109.068,
+ "e": 1109.189
+ },
+ {
+ "s": 1109.384,
+ "e": 1109.477
+ },
+ {
+ "s": 1109.563,
+ "e": 1110.133
+ }
+ ]
+ },
+ "bk3": {
+ "segment": {
+ "id": "bk3",
+ "type": "clip",
+ "start": 1641.333,
+ "end": 1684.467
+ },
+ "record": {
+ "start": 77.558,
+ "end": 123.97,
+ "gaps": [
+ {
+ "from": 96.992,
+ "to": 100.258
+ }
+ ]
+ },
+ "silences": [
+ {
+ "s": 1676.554,
+ "e": 1677.02
+ },
+ {
+ "s": 1677.379,
+ "e": 1677.582
+ },
+ {
+ "s": 1677.836,
+ "e": 1677.937
+ },
+ {
+ "s": 1678.442,
+ "e": 1678.547
+ },
+ {
+ "s": 1678.711,
+ "e": 1678.825
+ },
+ {
+ "s": 1678.998,
+ "e": 1679.476
+ },
+ {
+ "s": 1680.069,
+ "e": 1680.193
+ },
+ {
+ "s": 1680.377,
+ "e": 1680.485
+ },
+ {
+ "s": 1681.497,
+ "e": 1682.065
+ },
+ {
+ "s": 1682.713,
+ "e": 1682.827
+ },
+ {
+ "s": 1683.279,
+ "e": 1683.499
+ },
+ {
+ "s": 1683.919,
+ "e": 1684.132
+ },
+ {
+ "s": 1684.141,
+ "e": 1684.251
+ }
+ ],
+ "words": [
+ {
+ "start": 116.72,
+ "text": "it's"
+ },
+ {
+ "start": 117.28,
+ "text": "supposed"
+ },
+ {
+ "start": 117.6,
+ "text": "to"
+ },
+ {
+ "start": 117.84,
+ "text": "be"
+ },
+ {
+ "start": 118,
+ "text": "horrifying."
+ },
+ {
+ "start": 119.03999999999999,
+ "text": "It's"
+ },
+ {
+ "start": 119.439,
+ "text": "not"
+ },
+ {
+ "start": 119.84,
+ "text": "supposed"
+ },
+ {
+ "start": 120.159,
+ "text": "to"
+ },
+ {
+ "start": 120.399,
+ "text": "be"
+ },
+ {
+ "start": 120.64,
+ "text": "sexy."
+ },
+ {
+ "start": 121.6,
+ "text": "It's"
+ },
+ {
+ "start": 121.92,
+ "text": "not"
+ },
+ {
+ "start": 122.159,
+ "text": "supposed"
+ },
+ {
+ "start": 122.479,
+ "text": "to"
+ },
+ {
+ "start": 122.64,
+ "text": "be"
+ },
+ {
+ "start": 122.719,
+ "text": "a"
+ },
+ {
+ "start": 122.96,
+ "text": "fetish."
+ },
+ {
+ "start": 124,
+ "text": "It's"
+ },
+ {
+ "start": 124.399,
+ "text": "not"
+ },
+ {
+ "start": 124.64,
+ "text": "supposed"
+ },
+ {
+ "start": 124.96,
+ "text": "to"
+ }
+ ],
+ "timed": false,
+ "wordsFrom": "captions"
+ }
+ }
+}
diff --git a/umtool/report-to-video/package.json b/umtool/report-to-video/package.json
@@ -56,6 +56,7 @@
"./narration-review": "./narration-review.mjs",
"./narration-store": "./narration-store.mjs",
"./package.json": "./package.json",
+ "./pauses": "./pauses.mjs",
"./post-links": "./post-links.mjs",
"./presets": "./presets.mjs",
"./prune-frames": "./prune-frames.mjs",
diff --git a/umtool/report-to-video/pauses.mjs b/umtool/report-to-video/pauses.mjs
@@ -0,0 +1,241 @@
+// THE PAUSES IN A STRETCH OF SPEECH, and an edge moved into one (2026-11-02).
+//
+// A cut that lands on a word is heard as a cut-off sentence; a crossfade that
+// lands on one fades it out. This is the one place that says where the quiet
+// is and where an edge goes in it, for every caller that moves an edge to a
+// pause: the trailer (trailer.mjs, each beat's crossfade landed in silence),
+// the bench waveform's marks between words (lib/report/benchZoom.mjs
+// quietPoints) and the clip editor's "snap edge to the nearest pause".
+//
+// A PAUSE is a span `{ from, to }` (seconds, any clock -- the caller's) where
+// nobody speaks: a measured silence (cut-points.mjs detectSilence, `{ s, e }`,
+// or `{ from, to }`), or the gap between two TIMED words (a words file, a
+// whisper transcript) at least PAUSE_MIN_GAP long. Overlapping ones merge.
+//
+// WORDS `{ start, end?, text }`: a timed word has an `end`; a caption's word
+// (YouTube's en-orig `<c>` timings) has only its `start`. Both say where a
+// word starts and what it says -- what decides that an edge finishes a
+// sentence, and names the word an edge was moved past. Only timed words add
+// pauses: a start-only word list has no gaps to read.
+//
+// AN EDGE INTO A PAUSE (snapEdge). `room` is how much quiet the edge wants on
+// its own side: a crossfade's length (its fade runs over the beat's last
+// `room` seconds, or its first), or SNAP_HARD_ROOM for a hard cut.
+//
+// end forward, into the first pause after the words it should finish,
+// at `pause.from + room` (the whole fade in the quiet) or the pause's
+// end when it is shorter -- never past the next word's start. When
+// the words are known, the words it finishes are the one in progress
+// at the edge, or -- when a sentence ends within `maxShift` of the
+// edge (. ? !) -- through that sentence's last word.
+// start back, into the last pause that starts before it, at `pause.to −
+// room` (the whole fade-in in the quiet) or the pause's start.
+// nearest the middle of the pause nearest the edge.
+//
+// Bounded: never more than `maxShift` (SNAP_MAX_SHIFT), never past `lo`/`hi`
+// (the caller's span: a segment's, a clip's). An edge already where it should
+// be does not move. What moved and why comes back to be said.
+//
+// PURE: no fs, no ffmpeg, no DOM -- the browser imports it (benchZoom.mjs).
+
+/** A gap between two timed words this long is a pause (seconds): the build's silencedetect minimum. */
+export const PAUSE_MIN_GAP = 0.09;
+/** The furthest an edge is moved to reach a pause (seconds). */
+export const SNAP_MAX_SHIFT = 1;
+/** The quiet a hard cut (no crossfade) wants on its side of the edge (seconds). */
+export const SNAP_HARD_ROOM = 0.1;
+/** A word sounds for at least this long after its start (seconds): a pause that starts sooner is the one before it. */
+export const MIN_WORD = 0.1;
+
+const fin = (v) => typeof v === "number" && Number.isFinite(v);
+const round4 = (v) => Math.round(v * 10000) / 10000;
+
+const TERMINAL = /[.?!]["')\]”’]*\s*$/;
+
+/** Does this text close a sentence by its punctuation (. ? !, closing quotes or brackets allowed after)? */
+export function endsSentence(text) {
+ return TERMINAL.test(String(text ?? ""));
+}
+
+/** A word list as `{ start, end?, text }`, finite starts only, in order. Accepts `w` / `word` for the text. */
+export function normWords(words) {
+ return (words ?? [])
+ .map((w) => ({
+ start: Number(w?.start),
+ ...(fin(Number(w?.end)) && w?.end !== null && w?.end !== undefined ? { end: Number(w.end) } : {}),
+ text: String(w?.text ?? w?.w ?? w?.word ?? ""),
+ }))
+ .filter((w) => fin(w.start))
+ .sort((a, b) => a.start - b.start);
+}
+
+/**
+ * The gaps between consecutive TIMED words at least `minGap` long (0: every
+ * gap, a zero-width one where two words touch). Words without an end add none.
+ *
+ * @param {Array<{ start: number, end?: number }>} words
+ * @param {number} [minGap]
+ * @returns {Array<{ from: number, to: number }>}
+ */
+export function wordGaps(words, minGap = 0) {
+ const ws = (words ?? []).filter((w) => fin(w?.start) && fin(w?.end)).sort((a, b) => a.start - b.start);
+ const out = [];
+ for (let i = 1; i < ws.length; i += 1) {
+ const gap = ws[i].start - ws[i - 1].end;
+ if (gap >= 0 && gap >= minGap) out.push({ from: ws[i - 1].end, to: ws[i].start });
+ }
+ return out;
+}
+
+/** A silence as `{ from, to }`: detectSilence's `{ s, e }` or already `{ from, to }`; null when it is not one. */
+function spanOf(x) {
+ const from = fin(x?.from) ? x.from : fin(x?.s) ? x.s : null;
+ const to = fin(x?.to) ? x.to : fin(x?.e) ? x.e : null;
+ return from !== null && to !== null && to > from ? { from, to } : null;
+}
+
+/**
+ * The pauses: measured silences and the gaps between timed words, merged
+ * where they overlap or touch, in order, those meeting [from, to].
+ *
+ * @param {{ words?: Array<{ start: number, end?: number }> | null, silences?: Array<{ s?: number, e?: number, from?: number, to?: number }> | null }} o
+ * @param {{ from?: number, to?: number, minGap?: number }} [range]
+ * @returns {Array<{ from: number, to: number }>}
+ */
+export function pauseSpans({ words = null, silences = null }, { from = -Infinity, to = Infinity, minGap = PAUSE_MIN_GAP } = {}) {
+ const all = [...(silences ?? []).map(spanOf).filter(Boolean), ...wordGaps(words ?? [], minGap).filter((g) => g.to > g.from)]
+ .sort((a, b) => a.from - b.from);
+ const out = [];
+ for (const p of all) {
+ const last = out[out.length - 1];
+ if (last && p.from <= last.to + 1e-6) last.to = Math.max(last.to, p.to);
+ else out.push({ ...p });
+ }
+ return out.filter((p) => p.to >= from && p.from <= to).map((p) => ({ from: round4(p.from), to: round4(p.to) }));
+}
+
+/**
+ * The places an edge or a gap's edge can go, as points: the middle of every
+ * pause between consecutive words (or cues; touching ones too) and of every
+ * measured silence. Sorted, deduplicated within 20 ms. In [from, to]. (The
+ * bench waveform's marks: benchZoom.mjs quietPoints.)
+ *
+ * @param {{ words?: Array<{ start: number, end: number }> | null, silences?: Array<{ from: number, to: number }> | null }} o
+ * @param {number} from
+ * @param {number} to
+ */
+export function pausePoints({ words = null, silences = null }, from, to) {
+ const pts = wordGaps(words ?? [], 0).map((g) => (g.from + g.to) / 2);
+ for (const s of silences ?? []) if (fin(s?.from) && fin(s?.to)) pts.push((s.from + s.to) / 2);
+ const out = [];
+ for (const p of pts.filter((x) => x >= from && x <= to).sort((a, b) => a - b)) {
+ if (!out.length || p - out[out.length - 1] > 0.02) out.push(round4(p));
+ }
+ return out;
+}
+
+/**
+ * @typedef {{ at: number, from: number, moved: boolean, side: "start" | "end" | "nearest",
+ * pause?: { from: number, to: number }, word?: string, sentence?: boolean, bounded?: boolean,
+ * reason?: "fits" | "none" | "far" | "bound" }} Snap
+ */
+
+/**
+ * One edge moved into a pause (see the header). `at` is where it goes; with
+ * `moved` false it stays, and `reason` says why: "fits" (already in quiet
+ * enough), "none" (no pause on that side), "far" (the pause is more than
+ * `maxShift` away), "bound" (only past `lo`/`hi`). `word` names the word the
+ * edge now sits after (an end) or before (a start); `sentence` says an end
+ * was carried to a sentence's last word; `bounded` that it stopped at `lo`/`hi`
+ * inside the pause.
+ *
+ * @param {number} t the edge
+ * @param {"start" | "end" | "nearest"} side
+ * @param {{ pauses: Array<{ from: number, to: number }>, words?: Array<{ start: number, end?: number, text?: string }> | null,
+ * room?: number, maxShift?: number, lo?: number, hi?: number }} o
+ * @returns {Snap}
+ */
+export function snapEdge(t, side, { pauses, words = null, room = SNAP_HARD_ROOM, maxShift = SNAP_MAX_SHIFT, lo = -Infinity, hi = Infinity }) {
+ const ps = [...(pauses ?? [])].filter((p) => fin(p?.from) && fin(p?.to) && p.to > p.from).sort((a, b) => a.from - b.from);
+ const ws = normWords(words);
+ const stay = (reason, extra = {}) => ({ at: t, from: t, moved: false, side, reason, ...extra });
+ if (side === "nearest") {
+ let best = null;
+ for (const p of ps) {
+ const mid = (p.from + p.to) / 2;
+ if (mid < lo - 1e-9 || mid > hi + 1e-9) continue;
+ if (!best || Math.abs(mid - t) < Math.abs(best.mid - t)) best = { p, mid };
+ }
+ if (!best) return stay("none");
+ if (t >= best.p.from && t <= best.p.to) return stay("fits", { pause: best.p });
+ if (Math.abs(best.mid - t) > maxShift + 1e-9) return stay("far", { pause: best.p });
+ return { at: round4(best.mid), from: t, moved: true, side, pause: best.p };
+ }
+
+ if (side === "end") {
+ // The words the edge finishes: the one in progress, or through a sentence
+ // that ends within maxShift. A pause that starts before that word has
+ // sounded (MIN_WORD) is the quiet before it, not after.
+ let after = -Infinity;
+ let sentence = false;
+ const k = lastIndex(ws, (w) => w.start < t - 1e-6);
+ if (k >= 0) {
+ let target = k;
+ if (!endsSentence(ws[k].text)) {
+ for (let j = k + 1; j < ws.length && ws[j].start <= t + maxShift; j += 1) {
+ if (endsSentence(ws[j].text)) {
+ target = j;
+ sentence = true;
+ break;
+ }
+ }
+ }
+ after = ws[target].start + MIN_WORD;
+ }
+ // Already in quiet enough -- the whole fade in one pause -- and no
+ // sentence to finish: it stays.
+ if (!sentence) {
+ const holds = ps.find((x) => x.from <= t - room + 1e-6 && x.to >= t - 1e-6);
+ if (holds) return stay("fits", { pause: holds, ...(lastWordBefore(ws, holds.from) ? { word: lastWordBefore(ws, holds.from) } : {}) });
+ }
+ const p = ps.find((x) => x.to > t + 1e-6 && x.from >= after - 1e-6);
+ if (!p) return stay("none");
+ const next = ws.find((w) => w.start > p.from + 1e-6);
+ const cap = Math.min(p.to, next ? next.start : Infinity);
+ const target = Math.max(t, Math.min(p.from + room, cap));
+ const word = lastWordBefore(ws, p.from);
+ const said = { pause: p, ...(word ? { word } : {}), ...(sentence ? { sentence } : {}) };
+ if (target - t <= 1e-3) return stay("fits", said);
+ if (target - t > maxShift + 1e-9) return stay("far", said);
+ if (target > hi + 1e-9) {
+ if (hi > t + 1e-3 && hi >= p.from - 1e-9) return { at: round4(hi), from: t, moved: true, side, ...said, bounded: true };
+ return stay("bound", said);
+ }
+ return { at: round4(target), from: t, moved: true, side, ...said };
+ }
+
+ // start: back into the last pause that starts before it.
+ const i = lastIndex(ps, (x) => x.from < t - 1e-6);
+ if (i < 0) return stay("none");
+ const p = ps[i];
+ const target = Math.min(t, Math.max(p.to - room, p.from));
+ const first = ws.find((w) => w.start >= p.from - 1e-6);
+ const said = { pause: p, ...(first ? { word: first.text } : {}) };
+ if (t - target <= 1e-3) return stay("fits", said);
+ if (t - target > maxShift + 1e-9) return stay("far", said);
+ if (target < lo - 1e-9) {
+ if (lo < t - 1e-3 && lo <= p.to + 1e-9) return { at: round4(lo), from: t, moved: true, side, ...said, bounded: true };
+ return stay("bound", said);
+ }
+ return { at: round4(target), from: t, moved: true, side, ...said };
+}
+
+function lastIndex(list, pred) {
+ for (let i = list.length - 1; i >= 0; i -= 1) if (pred(list[i])) return i;
+ return -1;
+}
+
+function lastWordBefore(ws, t) {
+ const i = lastIndex(ws, (w) => w.start < t - 1e-6);
+ return i >= 0 ? ws[i].text : null;
+}
diff --git a/umtool/report-to-video/pauses.test.mjs b/umtool/report-to-video/pauses.test.mjs
@@ -0,0 +1,123 @@
+// pauses.mjs: where the quiet is in a stretch of speech, and an edge moved
+// into it -- forward for an end (through its sentence), back for a start,
+// to the nearest for the clip editor; bounded, and said.
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import {
+ MIN_WORD, PAUSE_MIN_GAP, SNAP_HARD_ROOM, SNAP_MAX_SHIFT, endsSentence, normWords, pausePoints, pauseSpans, snapEdge, wordGaps,
+} from "./pauses.mjs";
+
+const close = (a, b, eps = 1e-3) => assert.ok(Math.abs(a - b) <= eps, `${a} ≉ ${b}`);
+
+test("the constants: a pause is the build's silencedetect minimum, an edge moves at most a second", () => {
+ assert.equal(PAUSE_MIN_GAP, 0.09);
+ assert.equal(SNAP_MAX_SHIFT, 1);
+ assert.equal(SNAP_HARD_ROOM, 0.1);
+ assert.equal(MIN_WORD, 0.1);
+});
+
+test("endsSentence: . ? ! with closing quotes or brackets after; a comma does not", () => {
+ for (const t of ["man.", "it?", "stop!", 'said."', "end.)", "so.” "]) assert.ok(endsSentence(t), t);
+ for (const t of ["So,", "[ __ ]", "every", "", null]) assert.ok(!endsSentence(t), String(t));
+});
+
+test("wordGaps: gaps between TIMED words at least minGap long; start-only words add none", () => {
+ const ws = [{ start: 0, end: 0.4 }, { start: 0.45, end: 0.9 }, { start: 1.3, end: 1.6 }, { start: 1.6, end: 2 }];
+ assert.deepEqual(wordGaps(ws, PAUSE_MIN_GAP), [{ from: 0.9, to: 1.3 }]);
+ assert.equal(wordGaps(ws, 0).length, 3, "every gap, the touching one too");
+ assert.deepEqual(wordGaps([{ start: 0 }, { start: 1 }], 0), []);
+});
+
+test("pauseSpans: silences ({s,e} or {from,to}) and word gaps, merged where they touch, in range", () => {
+ const p = pauseSpans({
+ silences: [{ s: 5, e: 5.4 }, { from: 1, to: 1.2 }, { s: 5.3, e: 5.6 }, { s: 9, e: 8 }],
+ words: [{ start: 0, end: 1.1 }, { start: 1.5, end: 2 }, { start: 3, end: 3.5 }],
+ });
+ assert.deepEqual(p, [{ from: 1, to: 1.5 }, { from: 2, to: 3 }, { from: 5, to: 5.6 }]);
+ assert.deepEqual(pauseSpans({ silences: [{ s: 1, e: 2 }, { s: 7, e: 8 }] }, { from: 3, to: 9 }), [{ from: 7, to: 8 }]);
+});
+
+test("pausePoints: the middle of every word gap (touching words too) and silence, deduplicated within 20 ms", () => {
+ const pts = pausePoints({ words: [{ start: 0, end: 1 }, { start: 1, end: 2 }, { start: 2.5, end: 3 }], silences: [{ from: 2.1, to: 2.4 }] }, 0, 10);
+ assert.deepEqual(pts, [1, 2.25]);
+});
+
+test("normWords: w / word / text, starts in order, an end only when there is one", () => {
+ assert.deepEqual(normWords([{ w: "b", start: 2, end: 2.3 }, { word: "a", start: 1 }, { text: "x", start: Number.NaN }]), [
+ { start: 1, text: "a" }, { start: 2, end: 2.3, text: "b" },
+ ]);
+});
+
+// The speech of the tests below: "... every [ __ ] type. You don't ..." --
+// a pause between "[ __ ]" and "type." and another after "type.".
+const WORDS = [
+ { start: 9.28, text: "every" }, { start: 10.24, text: "[ __ ]" }, { start: 11.4, text: "type." }, { start: 12.16, text: "You" }, { start: 12.32, text: "don't" },
+];
+const PAUSES = [{ from: 10.9, to: 11.44 }, { from: 11.8, to: 12.26 }];
+
+test("an end is carried through its sentence when it ends within maxShift, into the pause after it, at from + room", () => {
+ const r = snapEdge(11.2, "end", { pauses: PAUSES, words: WORDS, room: 0.3 });
+ assert.equal(r.moved, true);
+ // 11.8 + 0.3 = 12.1, under the pause's end and "You" (12.16).
+ close(r.at, 12.1);
+ assert.equal(r.word, "type.");
+ assert.equal(r.sentence, true);
+ // Without the words it is already in quiet: it stays.
+ const bare = snapEdge(11.2, "end", { pauses: PAUSES, room: 0.3 });
+ assert.equal(bare.moved, false);
+ assert.equal(bare.reason, "fits");
+});
+
+test("an end never passes the next word's start, nor the pause's end", () => {
+ // A pause shorter than the fade: the edge goes to its end.
+ const short = snapEdge(1.05, "end", { pauses: [{ from: 1.1, to: 1.25 }], words: [{ start: 0.6, text: "man." }, { start: 1.3, text: "So," }], room: 0.3 });
+ close(short.at, 1.25);
+ // A word the captions start inside the pause: the edge stops there.
+ const capped = snapEdge(1.05, "end", { pauses: [{ from: 1.1, to: 1.6 }], words: [{ start: 0.6, text: "is." }, { start: 1.3, text: "Stop" }], room: 0.3 });
+ close(capped.at, 1.3);
+});
+
+test("a pause that starts before the last word has sounded (MIN_WORD) is the quiet before it, not after", () => {
+ // "man." starts at 28.48; a dip at 28.53 is inside it, so the edge goes to the pause after "So,".
+ const r = snapEdge(28.57, "end", {
+ pauses: [{ from: 28.53, to: 28.63 }, { from: 28.76, to: 28.9 }],
+ words: [{ start: 28.48, text: "man." }, { start: 28.64, text: "So," }, { start: 28.88, text: "I'm" }],
+ room: 0.3,
+ });
+ close(r.at, 28.88);
+ assert.equal(r.word, "So,");
+});
+
+test("bounded: more than maxShift away stays (far); past hi stops at hi inside the pause, or stays (bound)", () => {
+ const far = snapEdge(10, "end", { pauses: [{ from: 11.2, to: 12 }], room: 0.3 });
+ assert.deepEqual([far.moved, far.reason, far.at], [false, "far", 10]);
+ const held = snapEdge(10, "end", { pauses: [{ from: 10.2, to: 11 }], room: 0.3, hi: 10.35 });
+ assert.deepEqual([held.moved, held.bounded, held.at], [true, true, 10.35]);
+ const bound = snapEdge(10, "end", { pauses: [{ from: 10.5, to: 11 }], room: 0.3, hi: 10.4 });
+ assert.deepEqual([bound.moved, bound.reason], [false, "bound"]);
+ const none = snapEdge(10, "end", { pauses: [{ from: 8, to: 9 }], room: 0.3 });
+ assert.equal(none.reason, "none");
+});
+
+test("a start goes back into the last pause before it, at to − room, bounded by lo", () => {
+ const ps = [{ from: 6.4, to: 6.85 }];
+ const r = snapEdge(6.78, "start", { pauses: ps, words: [{ start: 6.72, text: "I" }, { start: 7.04, text: "am" }], room: 0.3 });
+ close(r.at, 6.55);
+ assert.equal(r.word, "I");
+ // Room enough after it already: it stays.
+ assert.equal(snapEdge(6.5, "start", { pauses: ps, room: 0.3 }).reason, "fits");
+ // lo: stops there inside the pause.
+ const lo = snapEdge(6.78, "start", { pauses: ps, room: 0.3, lo: 6.7 });
+ assert.deepEqual([lo.at, lo.bounded], [6.7, true]);
+ assert.equal(snapEdge(6.78, "start", { pauses: [{ from: 5, to: 5.4 }], room: 0.3 }).reason, "far");
+});
+
+test("nearest: the middle of the pause nearest the edge, within maxShift and the bounds (the clip editor's snap)", () => {
+ const ps = [{ from: 1, to: 1.2 }, { from: 2, to: 2.6 }, { from: 5, to: 5.2 }];
+ close(snapEdge(1.9, "nearest", { pauses: ps }).at, 2.3);
+ close(snapEdge(1.4, "nearest", { pauses: ps }).at, 1.1);
+ assert.equal(snapEdge(2.1, "nearest", { pauses: ps }).reason, "fits");
+ assert.equal(snapEdge(3.6, "nearest", { pauses: ps, maxShift: 1 }).reason, "far");
+ close(snapEdge(1.4, "nearest", { pauses: ps, lo: 1.5 }).at, 2.3);
+});
diff --git a/umtool/report-to-video/trailer-snap.test.mjs b/umtool/report-to-video/trailer-snap.test.mjs
@@ -0,0 +1,186 @@
+// trailer.mjs: each clip beat's edges into the pauses (pauses.mjs), on the
+// beats of the Ember draft-24 trailer as they were BEFORE the operator moved
+// their ends by hand (fixtures/ember-draft-24-trailer.json: the take's own
+// schedule, cut records, master silences and caption words around the edges,
+// no corpus read). The cut-off sentences that started it: b01 "man.", c01
+// "door is." and kr1 "woman." faded out, and tr3 ended before "type.". Also:
+// bounded by the segment's own clip and the max shift, `--no-snap`, and the
+// source labels counted past a clip's gaps.
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import path from "node:path";
+import test from "node:test";
+
+import { MIN_WORD, SNAP_MAX_SHIFT } from "./pauses.mjs";
+import { makeTrailer, parseBeats, planTrailer, trailerPauses } from "./trailer.mjs";
+
+const EMBER = JSON.parse(readFileSync(new URL("./fixtures/ember-draft-24-trailer.json", import.meta.url), "utf8"));
+
+/** The fixture as a take's build: the brand intro, its clips in the cut's order, a closing segment after them. */
+function emberBuild() {
+ const segments = [
+ { id: "brand-intro", type: "intro", start: 0, end: 4.733 },
+ ...EMBER.order.map((id) => EMBER.clips[id].segment),
+ { id: "closer", type: "clip", start: EMBER.total - 10, end: EMBER.total },
+ ];
+ return {
+ schedule: { version: 1, kind: "deck", fps: EMBER.fps, transition: EMBER.transition, total: EMBER.total, segments },
+ records: new Map(EMBER.order.map((id) => [id, { version: 1, id, ...EMBER.clips[id].record }])),
+ manifest: { timeline: EMBER.order.map((id) => ({ type: "clip", id, video: id })), provenance: {} },
+ master: "master.mp4",
+ render: { fps: 30 },
+ };
+}
+
+/** trailerPauses over the fixture: its silences for a segment, its words for a clip (as clip-words.mjs gives them). */
+function emberPauses(build, beats) {
+ return trailerPauses({
+ build, beats,
+ silences: async (_file, _render, scan) => {
+ const id = EMBER.order.find((k) => Math.abs(EMBER.clips[k].segment.start - scan.from) < 1e-6);
+ return id ? EMBER.clips[id].silences : [];
+ },
+ words: async (entry, _prov, from, to) => {
+ const c = EMBER.clips[entry.id];
+ if (!c?.words) return null;
+ return { words: c.words.filter((w) => w.start >= from && w.start <= to), timed: !!c.timed, from: c.wordsFrom };
+ },
+ });
+}
+
+const BEATS = parseBeats(EMBER.beats);
+const build = emberBuild();
+const pauses = await emberPauses(build, BEATS);
+const plan = (o = {}) => planTrailer({ schedule: build.schedule, records: build.records, beats: BEATS, intro: true, xfade: 0.3, pauses, ...o });
+const SNAPPED = plan();
+const PLAIN = plan({ snap: false });
+
+/** A beat's piece (the n-th of the beats, 1-based; the intro is piece 0). */
+const piece = (p, n) => p.pieces[n];
+/** Its clip's words in MASTER seconds, as the plan saw them. */
+const wordsOf = (id) => pauses.get(id).words;
+const silencesOf = (id) => EMBER.clips[id].silences;
+const inSilence = (id, t) => silencesOf(id).some((s) => t >= s.s - 1e-3 && t <= s.e + 1e-3);
+
+test("the fixture: the beats before the hand fix, b01 c01 tr3 u01 kr1 bk3 tr3", () => {
+ assert.deepEqual(BEATS.map((b) => b.id), ["b01", "c01", "tr3", "u01", "kr1", "bk3", "tr3"]);
+ assert.equal(BEATS[2].end, 3011.2);
+});
+
+test("tr3's first beat ends after \"type.\" -- carried through the sentence, into the pause after it, before \"You\"", () => {
+ const p = piece(SNAPPED, 3);
+ assert.equal(p.id, "tr3");
+ const ws = wordsOf("tr3");
+ const type = ws.find((w) => w.text === "type.");
+ const you = ws.find((w) => w.text === "You");
+ assert.ok(p.master.end >= type.start + MIN_WORD, `ends ${p.master.end}, "type." starts ${type.start}`);
+ assert.ok(p.master.end <= you.start + 1 / 30, `ends ${p.master.end}, "You" starts ${you.start}`);
+ assert.ok(inSilence("tr3", p.master.end));
+ assert.ok(p.source.end > 3011.4 + MIN_WORD);
+ // The unsnapped plan ended before "type." started.
+ assert.ok(piece(PLAIN, 3).master.end < type.start);
+ assert.ok(SNAPPED.notes.includes('beat 3 tr3: end 3011.20 → 3012.09 (pause after "type.", the sentence\'s end)'), SNAPPED.notes.join("\n"));
+ assert.equal(p.snapped.end.after, "type.");
+ assert.ok(Math.abs(p.snapped.end.from - 765.778) < 1e-3 && Math.abs(p.snapped.end.to - 766.667) < 1e-3, JSON.stringify(p.snapped.end));
+});
+
+test("b01, c01 and kr1 end in a pause, after their last word has sounded; each move said", () => {
+ for (const [n, id, last] of [[1, "b01", "man."], [2, "c01", "is."], [5, "kr1", "woman."]]) {
+ const p = piece(SNAPPED, n);
+ assert.equal(p.id, id);
+ assert.ok(inSilence(id, p.master.end), `${id} ends at ${p.master.end}, in no silence`);
+ const w = wordsOf(id).filter((x) => x.text === last).at(-1);
+ assert.ok(p.master.end > w.start + MIN_WORD, `${id}: "${last}" at ${w.start}`);
+ assert.ok(p.master.end > piece(PLAIN, n).master.end, `${id} moved forward`);
+ assert.ok(p.master.end - piece(PLAIN, n).master.end <= SNAP_MAX_SHIFT + 1 / 30);
+ }
+ const said = SNAPPED.notes.join("\n");
+ assert.match(said, /beat 1 b01: end 1818\.65 → 1818\.95 \(pause after "So,"\)/);
+ assert.match(said, /beat 2 c01: end 220\.95 → 221\.09 \(pause after "is\."\)/);
+ assert.match(said, /beat 5 kr1: end 4818\.10 → 4818\.21 \(pause after "woman\."\)/);
+ // c01's fade (its last 0.3 s) holds no word's start: "door is." is heard whole.
+ const c01 = piece(SNAPPED, 2);
+ assert.ok(!wordsOf("c01").some((w) => w.start > c01.master.end - 0.3 + 1e-6 && w.start < c01.master.end - 1e-6));
+});
+
+test("starts go back into the pause before them, never across a gap's join or into the master's crossfade", () => {
+ // kr1 starts on "This", now in the pause before it.
+ const kr1 = piece(SNAPPED, 5);
+ assert.ok(kr1.master.start < piece(PLAIN, 5).master.start);
+ assert.match(SNAPPED.notes.join("\n"), /beat 5 kr1: start 4814\.95 → 4814\.81 \(pause before "This"\)/);
+ // u01 starts at its gap's join: the silence across the jump cut is no reason to play what the gap took out.
+ const u01 = piece(SNAPPED, 4);
+ assert.equal(u01.master.start, piece(PLAIN, 4).master.start);
+ assert.ok(u01.source.start >= 9476.7 - 0.02, `u01 starts at source ${u01.source.start}`);
+ // Every clip piece stays out of the master's own crossfades as far as the trailer's hides them.
+ for (const p of SNAPPED.pieces.filter((x) => x.kind === "clip")) {
+ const seg = build.schedule.segments.find((s) => s.id === p.id);
+ assert.ok(p.master.start >= seg.start + EMBER.transition - 0.3 - 1e-3, `${p.id} start`);
+ assert.ok(p.master.end <= seg.end - EMBER.transition + 0.3 + 1e-3, `${p.id} end`);
+ }
+});
+
+test("bounded by the max shift and the segment's own clip, on a made-up clip", () => {
+ const schedule = {
+ fps: 30, transition: 0.5, total: 40,
+ segments: [{ id: "a", type: "clip", start: 0, end: 20 }, { id: "c", type: "clip", start: 19.5, end: 30 }, { id: "z", type: "clip", start: 29.5, end: 40 }],
+ };
+ const records = new Map([["c", { start: 100, end: 110 }]]);
+ const one = (beat, ps) => planTrailer({ schedule, records, beats: parseBeats([beat]), xfade: 0.3, pauses: new Map([["c", { pauses: ps, words: null }]]) });
+ // A pause whose quiet (a hard end's SNAP_HARD_ROOM into it) is 1.1 s after the end: too far, said.
+ const far = one({ id: "c", start: 102, end: 105 }, [{ from: 25.5, to: 26 }]);
+ assert.equal(far.pieces[0].master.end, 24.5);
+ assert.match(far.notes.join("\n"), /beat 1 c: end 105\.00 kept — the pause is more than 1\.00 s away/);
+ // A pause running past the segment's own end (the cut record's 110 is master 29.5): it stops there.
+ const edge = one({ id: "c", start: 102, end: 109.7 }, [{ from: 29.3, to: 30 }]);
+ assert.ok(edge.pieces[0].master.end <= 29.5 + 1e-6);
+ // The last piece has no trailer crossfade out: a hard end wants SNAP_HARD_ROOM of quiet.
+ const hard = one({ id: "c", start: 102, end: 105 }, [{ from: 24.6, to: 25.4 }]);
+ assert.ok(Math.abs(hard.pieces[0].master.end - 24.7) < 1 / 30 + 1e-6);
+});
+
+test("--no-snap: every edge as written, no pause measured", async () => {
+ for (const p of PLAIN.pieces) assert.equal(p.snapped, undefined);
+ assert.ok(!PLAIN.notes.some((n) => /→|kept —/.test(n)));
+ assert.deepEqual(plan({ pauses: null }).pieces.map((p) => p.master), PLAIN.pieces.map((p) => p.master));
+ // makeTrailer --no-snap never measures.
+ const dir = await mkdtemp(path.join(tmpdir(), "trailer-snap-"));
+ try {
+ const takeDir = path.join(dir, "takes", "t1");
+ await mkdir(path.join(takeDir, "out", "sourced", "segments"), { recursive: true });
+ await writeFile(path.join(takeDir, "video.manifest.json"), JSON.stringify({ slug: "s", render: { fps: 30 }, timeline: build.manifest.timeline }));
+ await writeFile(path.join(takeDir, "out", "sourced", "schedule.json"), JSON.stringify(build.schedule));
+ for (const [id, rec] of build.records) await writeFile(path.join(takeDir, "out", "sourced", "segments", `${id}.cut.json`), JSON.stringify(rec));
+ let measured = 0;
+ const measure = async (b, beats) => {
+ measured += 1;
+ return emberPauses(b, beats);
+ };
+ const common = { takeDir, beats: BEATS, intro: true, dryRun: true, probe: async () => EMBER.total, measure };
+ const off = await makeTrailer({ ...common, snap: false });
+ assert.equal(measured, 0);
+ assert.equal(off.record.snap, false);
+ const on = await makeTrailer(common);
+ assert.equal(measured, 1);
+ assert.equal(on.plan.pieces[3].master.end, SNAPPED.pieces[3].master.end);
+ } finally {
+ await rm(dir, { recursive: true, force: true });
+ }
+});
+
+test("the source labels count a clip's gaps: u01 and bk3 say the seconds they play, not a gap's length early", () => {
+ // u01's gaps take 21.77 s out before its beat; bk3's 3.27 s.
+ const u01 = piece(PLAIN, 4);
+ const bk3 = piece(PLAIN, 6);
+ assert.ok(Math.abs(u01.source.start - 9476.7) < 1 / 30 + 0.02, `u01 ${u01.source.start}`);
+ assert.ok(Math.abs(u01.source.end - 9484.95) < 1 / 30 + 0.02, `u01 ${u01.source.end}`);
+ assert.ok(Math.abs(bk3.source.start - 119) < 1 / 30 + 0.02, `bk3 ${bk3.source.start}`);
+ assert.ok(Math.abs(bk3.source.end - 123.3) < 1 / 30 + 0.02, `bk3 ${bk3.source.end}`);
+ // The master span is the same as ever (it was always right).
+ const rec = build.records.get("u01");
+ const seg = build.schedule.segments.find((s) => s.id === "u01");
+ const gapsBefore = rec.gaps.reduce((n, g) => n + (g.to - g.from), 0);
+ assert.ok(Math.abs(u01.master.start - (seg.start + 9476.7 - rec.start - gapsBefore)) < 1 / 30 + 1e-6);
+});
diff --git a/umtool/report-to-video/trailer.mjs b/umtool/report-to-video/trailer.mjs
@@ -32,6 +32,23 @@
// start D − x into its segment and the master's blend is under the trailer's.
// Pulled-in edges are said, never silent (`notes`).
//
+// EDGES INTO PAUSES (2026-11-02). The trailer's own crossfade overlaps a
+// beat's last `xfade` seconds with the next beat's first: an edge a tenth of
+// a second after a word starts fades that word out ("man.", "door is."), and
+// one before a sentence's last word cuts it ("every [ __ ]" without "type.").
+// So once the master's crossfades are kept out (above), each clip beat's END
+// moves forward into the next pause -- through the sentence when one ends
+// within SNAP_MAX_SHIFT -- far enough that the fade is in the quiet, and its
+// START back into the pause before it (pauses.mjs snapEdge). The pauses are
+// the master's own silences over the segment (cut-points.mjs detectSilence,
+// the build's measure) and the gaps between the recording's timed words; the
+// words (clip-words.mjs: a words file, a whisper transcript, else the
+// captions' word starts) say which sentence an edge is in and name the word
+// it now follows. Never past the segment's own clip (the master's
+// crossfades, the cut record's end, a gap's join), never more than
+// SNAP_MAX_SHIFT; each move is a note, and `--no-snap` leaves the edges as
+// written. A raw beat, the intro and the finale are taken as written.
+//
// The spans are cut frame-accurately (decoded, never stream-copied) in ONE
// ffmpeg pass: each run of the master is a `movie` source inside the
// filtergraph, decoded only when the chain reaches it (separate `-i` inputs
@@ -53,7 +70,11 @@ import path from "node:path";
import { promisify } from "node:util";
import { encodeArgs } from "./build-video.mjs";
-import { offsetIn, recordGaps } from "./gaps.mjs";
+import { clipWords } from "./clip-words.mjs";
+import { DEFAULT_CHANNELS_DIR } from "./cues.mjs";
+import { detectSilence } from "./cut-points.mjs";
+import { offsetIn, recordGaps, sourceAtOffset } from "./gaps.mjs";
+import { SNAP_HARD_ROOM, SNAP_MAX_SHIFT, pauseSpans, snapEdge } from "./pauses.mjs";
const execFileP = promisify(execFile);
const FFMPEG = () => process.env.FFMPEG_BIN ?? "ffmpeg";
@@ -159,8 +180,11 @@ function introSpan(spans) {
* @param {boolean} [a.intro] prepend the master's brand intro
* @param {number|null} [a.finale] append the master's last S seconds
* @param {number} [a.xfade] the trailer's crossfade (0: hard cuts)
+ * @param {Map<string, { pauses: Array<{ from: number, to: number }>, words?: Array<{ start: number, end?: number, text: string }> | null }> | null} [a.pauses]
+ * each clip segment's pauses and words in MASTER seconds (trailerPauses); none: no edge moves to a pause
+ * @param {boolean} [a.snap] move clip beats' edges into pauses (false: `--no-snap`)
*/
-export function planTrailer({ schedule, records, beats, intro = false, finale = null, xfade = TRAILER_XFADE_DEFAULT }) {
+export function planTrailer({ schedule, records, beats, intro = false, finale = null, xfade = TRAILER_XFADE_DEFAULT, pauses = null, snap = true }) {
const { spans, count, D, total, fps } = scheduleSpans(schedule);
if (!Number.isFinite(total) || total <= 0) throw new TrailerError("schedule.json has no total");
if (!Number.isFinite(xfade) || xfade < 0) throw new TrailerError(`--xfade ${xfade}: seconds ≥ 0`);
@@ -208,7 +232,7 @@ export function planTrailer({ schedule, records, beats, intro = false, finale =
if (gaps.some((g) => g.from < e && g.to > s)) {
notes.push(`beat ${n + 1}: ${beat.id} ${beat.start}–${beat.end} spans a gap — it plays the master's jump cut (${fmt(b - a)} s)`);
}
- want.push({ kind: "clip", id: beat.id, beat, rec, seg, a, b });
+ want.push({ kind: "clip", id: beat.id, beat, n: n + 1, rec, seg, gaps, a, b });
});
if (finale != null) {
if (!Number.isFinite(finale) || finale <= 0) throw new TrailerError(`--finale ${finale}: seconds > 0`);
@@ -234,6 +258,8 @@ export function planTrailer({ schedule, records, beats, intro = false, finale =
// Edges pulled out of the master's own crossfades (see the header), then
// put on frames: a start rounded to its frame, the length a whole count.
+ /** The piece before's end in the master, once its edges have moved. */
+ let prevEnd = null;
const pieces = want.map((w, i) => {
const joinIn = i > 0 && !seam[i];
const joinOut = i < n - 1 && !seam[i + 1];
@@ -252,7 +278,60 @@ export function planTrailer({ schedule, records, beats, intro = false, finale =
moved.end = { from: r3(b), to: r3(hi) };
b = hi;
}
+ // Into the pauses (the header's "edges into pauses"): bounded by the
+ // master's crossfades (lo, hi), the cut record's own end (a hold after it
+ // is a frozen frame) and the gap joins either side of the edge.
+ const P = snap && w.kind === "clip" ? pauses?.get(w.id) : null;
+ if (P) {
+ const toMaster = (src) => w.seg.start + offsetIn(src, w.rec.start, w.gaps);
+ const joins = w.gaps.map((g) => toMaster(g.from));
+ const recEnd = toMaster(w.rec.end);
+ const label = (t) => fmt(r3(sourceAtOffset(t - w.seg.start, w.rec.start, w.gaps)));
+ const say = (edge, r, was) => {
+ const where = r.word ? `pause ${edge === "end" ? "after" : "before"} "${r.word}"` : `pause at ${label(r.pause.from)}–${label(r.pause.to)}`;
+ const extra = [r.sentence ? "the sentence's end" : null, r.bounded ? "held at the segment's edge" : null].filter(Boolean).join(", ");
+ notes.push(`beat ${w.n} ${w.id}: ${edge} ${label(was)} → ${label(r.at)} (${where}${extra ? `, ${extra}` : ""})`);
+ };
+ const kept = (edge, r, was, bound) => {
+ // At the segment's own edge already (the master's crossfade, a
+ // join): nothing to say beyond what the crossfade note says.
+ if (r.reason === "bound" && Math.abs(was - bound) < 1e-3) return;
+ const why = r.reason === "far" ? `the pause is more than ${fmt(SNAP_MAX_SHIFT)} s away`
+ : r.reason === "bound" ? "the pause is past the segment's own clip" : `no pause ${edge === "end" ? "after" : "before"} it`;
+ notes.push(`beat ${w.n} ${w.id}: ${edge} ${label(was)} kept — ${why}`);
+ };
+ if (!seam[i + 1]) {
+ const room = xOut > 0 ? xOut : SNAP_HARD_ROOM;
+ // Never into the next piece when it plays on from here in the master.
+ const next = want[i + 1];
+ const nextA = next && next.a >= w.b - 1e-6 ? next.a : Infinity;
+ const hiSnap = Math.min(hi, recEnd, nextA, ...joins.filter((j) => j >= b - 1e-3));
+ const r = snapEdge(b, "end", { pauses: P.pauses, words: P.words, room, maxShift: SNAP_MAX_SHIFT, hi: hiSnap });
+ if (r.moved) {
+ // On the frame at or before it: the frame rounding below never carries it past the word after.
+ const at = Math.max(b, Math.floor(r.at * fps + 1e-6) / fps);
+ moved.snapped = { ...(moved.snapped ?? {}), end: { from: r3(b), to: r3(at), ...(r.word ? { after: r.word } : {}) } };
+ say("end", { ...r, at }, b);
+ b = at;
+ } else if (r.reason !== "fits") kept("end", r, b, hiSnap);
+ }
+ if (!seam[i]) {
+ const room = xIn > 0 ? xIn : SNAP_HARD_ROOM;
+ // Never back into the piece before when it played up to here in the master.
+ const prevB = i > 0 && prevEnd !== null && prevEnd <= w.a + 1e-6 ? prevEnd : -Infinity;
+ const loSnap = Math.max(lo, prevB, ...joins.filter((j) => j <= a + 1e-3));
+ const r = snapEdge(a, "start", { pauses: P.pauses, words: P.words, room, maxShift: SNAP_MAX_SHIFT, lo: loSnap });
+ if (r.moved) {
+ // On the frame at or after it, for the same reason.
+ const at = Math.min(a, Math.ceil(r.at * fps - 1e-6) / fps);
+ moved.snapped = { ...(moved.snapped ?? {}), start: { from: r3(a), to: r3(at), ...(r.word ? { before: r.word } : {}) } };
+ say("start", { ...r, at }, a);
+ a = at;
+ } else if (r.reason !== "fits") kept("start", r, a, loSnap);
+ }
+ }
}
+ prevEnd = b;
const fa = Math.round(a * fps);
const frames = Math.round(b * fps) - fa;
const name = w.kind === "clip" ? w.id : w.kind === "intro" ? "intro" : w.kind === "finale" ? "finale" : `beat ${i + 1}`;
@@ -271,18 +350,21 @@ export function planTrailer({ schedule, records, beats, intro = false, finale =
master: { start: r3(start), end: r3(start + duration), duration: r3(duration) },
frames: { start: fa, count: frames },
...(seam[i] ? { seamless: true } : {}),
+ // The source seconds it plays, its gaps counted: a beat after a gap is
+ // that much later in its source than in its segment.
...(w.kind === "clip"
? {
source: {
- start: r3(w.rec.start + (start - w.seg.start)),
- end: r3(w.rec.start + (start + duration - w.seg.start)),
+ start: r3(sourceAtOffset(start - w.seg.start, w.rec.start, w.gaps)),
+ end: r3(sourceAtOffset(start + duration - w.seg.start, w.rec.start, w.gaps)),
asked: { start: w.beat.start, end: w.beat.end },
},
segment: { start: r3(w.seg.start), end: r3(w.seg.end), cut: { start: w.rec.start, end: w.rec.end } },
}
: {}),
...(w.kind === "raw" ? { asked: { at: w.beat.at, dur: w.beat.dur } } : {}),
- ...(moved.start || moved.end ? { moved } : {}),
+ ...(moved.start || moved.end ? { moved: { ...(moved.start ? { start: moved.start } : {}), ...(moved.end ? { end: moved.end } : {}) } } : {}),
+ ...(moved.snapped ? { snapped: moved.snapped } : {}),
};
if (moved.start) {
notes.push(`${name}: starts at master ${fmt(moved.start.to)}, not ${fmt(moved.start.from)} — the master's crossfade into it runs until ${fmt(w.seg.start + D)}`);
@@ -456,6 +538,52 @@ export async function loadTakeBuild(takeDir) {
return { manifest, slug, render: manifest.render, master, schedule, records };
}
+/**
+ * Each clip beat's segment's pauses and words, in MASTER seconds, for
+ * planTrailer: the master's silences over the segment (`silences`, the
+ * build's detectSilence with the take's render settings) and the recording's
+ * words over the cut (`words`, clip-words.mjs), mapped onto the master by the
+ * cut record -- a word in one of the clip's gaps is not in the master. Once
+ * per segment, however many beats it plays in. A segment whose measure fails
+ * has no pauses: its edges stay.
+ *
+ * @param {object} a
+ * @param {object} a.build loadTakeBuild's
+ * @param {object[]} a.beats parseBeats's
+ * @param {(file: string, render: object, scan: { from: number, to: number }) => Promise<Array<{ s: number, e: number }>>} [a.silences]
+ * @param {(entry: object, provenance: object, from: number, to: number) => Promise<{ words: Array<{ start: number, end?: number, text: string }>, timed: boolean } | null>} [a.words]
+ */
+export async function trailerPauses({
+ build, beats,
+ silences = (file, render, scan) => detectSilence(file, render, scan),
+ words = (entry, provenance, from, to) => clipWords(entry, provenance, from, to, { channelsDir: DEFAULT_CHANNELS_DIR }),
+}) {
+ const { spans } = scheduleSpans(build.schedule);
+ const entries = new Map((build.manifest?.timeline ?? []).filter((e) => e?.id).map((e) => [e.id, e]));
+ const out = new Map();
+ for (const beat of beats) {
+ if (beat.kind !== "clip" || out.has(beat.id)) continue;
+ const seg = spans.get(beat.id);
+ const rec = build.records.get(beat.id);
+ if (!seg || !rec || !Number.isFinite(rec.start) || !Number.isFinite(rec.end)) continue;
+ const gaps = recordGaps(rec);
+ const sil = await silences(build.master, build.render, { from: seg.start, to: seg.end }).catch(() => []);
+ const entry = entries.get(beat.id);
+ const got = entry ? await words(entry, build.manifest?.provenance ?? {}, rec.start - 1, rec.end + 1).catch(() => null) : null;
+ const inGap = (t) => gaps.some((g) => t > g.from && t < g.to);
+ const toMaster = (t) => seg.start + offsetIn(t, rec.start, gaps);
+ const ws = (got?.words ?? [])
+ .filter((w) => !inGap(w.start))
+ .map((w) => ({ start: toMaster(w.start), ...(got.timed && Number.isFinite(w.end) ? { end: toMaster(w.end) } : {}), text: w.text }));
+ out.set(beat.id, {
+ pauses: pauseSpans({ silences: sil, words: ws }, { from: seg.start, to: seg.end }),
+ words: ws,
+ ...(got ? { wordsFrom: got.from ?? null } : {}),
+ });
+ }
+ return out;
+}
+
/** The master's length in seconds (its frames over the fps), or null when it cannot be read. */
export async function probeMasterSeconds(file, fps) {
try {
@@ -498,13 +626,20 @@ export async function runFfmpeg(argv) {
* @param {(file: string, fps: number) => Promise<number|null>} [a.probe]
* @param {(fn: () => Promise<any>) => Promise<any>} [a.slot] the heavy slot around the encode
* @param {() => number} [a.now]
+ * @param {boolean} [a.snap] move clip beats' edges into pauses (false: `--no-snap`)
+ * @param {(build: object, beats: object[]) => Promise<Map<string, any>>} [a.measure] the pauses (trailerPauses; tests stub it)
*/
export async function makeTrailer({
takeDir, beats, intro = false, finale = null, xfade = TRAILER_XFADE_DEFAULT, out = null, dryRun = false,
run = runFfmpeg, probe = probeMasterSeconds, slot = (fn) => fn(), now = Date.now,
+ snap = true, measure = (build, list) => trailerPauses({ build, beats: list }),
}) {
const build = await loadTakeBuild(takeDir);
- const plan = planTrailer({ schedule: build.schedule, records: build.records, beats, intro, finale, xfade });
+ // Checked once without the pauses first: a beat that is refused is refused
+ // before anything is measured.
+ planTrailer({ schedule: build.schedule, records: build.records, beats, intro, finale, xfade, snap: false });
+ const pauses = snap ? await measure(build, beats) : null;
+ const plan = planTrailer({ schedule: build.schedule, records: build.records, beats, intro, finale, xfade, pauses, snap });
const masterSeconds = await probe(build.master, plan.fps);
if (masterSeconds == null) throw new TrailerError(`${path.basename(takeDir)} has no master: ${build.master} cannot be read`);
if (Math.abs(masterSeconds - plan.masterSeconds) > 0.1) {
@@ -526,6 +661,7 @@ export async function makeTrailer({
schedule: path.join(takeDir, "out", "sourced", "schedule.json"),
},
xfade: plan.xfade,
+ snap,
transition: plan.transition,
fps: plan.fps,
encode: { crf: build.render.crf ?? 20, preset: build.render.preset ?? "medium", audioBitrate: build.render.audioBitrate ?? "160k" },
@@ -567,7 +703,8 @@ export function describePlan(plan) {
: p.kind === "raw" ? `${"(master)".padEnd(22)} at ${fmt(p.asked.at)} for ${fmt(p.asked.dur)}`
: `${`(${p.kind})`.padEnd(22)}`;
const span = `master ${clock(p.master.start)}–${clock(p.master.end)}`;
- return `${String(i + 1).padStart(2)}. ${clock(p.at).padStart(6)} ${what.padEnd(48)} ${span} ${fmt(p.master.duration)} s${p.moved ? " (edge moved)" : ""}`;
+ const marks = `${p.moved ? " (edge moved)" : ""}${p.snapped ? " (into a pause)" : ""}`;
+ return `${String(i + 1).padStart(2)}. ${clock(p.at).padStart(6)} ${what.padEnd(48)} ${span} ${fmt(p.master.duration)} s${marks}`;
});
lines.push(`total ${clock(plan.total)} (${fmt(plan.total)} s), ${plan.pieces.length} pieces, crossfade ${fmt(plan.xfade)} s`);
return lines;