From 3e929cfee86bf00f01b3bd86b5feb0714257dffe Mon Sep 17 00:00:00 2001 From: shane Date: Sat, 5 Dec 2026 16:07:12 -0800 Subject: [PATCH] raea check: run-28 and local 3D noise fixes (doubtful face, line level, untold blotching) (#344) * raea check: a doubtful face as tall as the faces beside it is still a face #343 made a cut face the reader is under 80% sure of a warning, for Elfster's hand at the edge. Body Shop's interviewer, cut by the frame's edge, read 0.74 and 0.61 too, and was demoted with it. The hand was 0.64 of the height of the faces beside it, the interviewer 0.98: a doubtful face is now a warning only when it is also under 0.75 of the other faces' height (or there's no other face). * raea check: a line's level is read where it's said, not where its transcript put it The levels check measured a line inside its words. Elfster's "Santa gift you've ever gotten?" was timed 0.8 s late by its transcriber, in the silence after it, and read -28 dB where the speech ran at -10: a line the mix had evened was called 19 dB under the others (12-05, run 28). A line's level is now the louder of its in-words level and its whole clip's; a short word in a quiet clip keeps its own. * raea check: blotching whose cause can't be told is an error only past an encoder's A 3D shot rendered at master quality read 0.010 (BLOTCHY is 0.009) from its shadows' own dithered edge, outside a raea project where the cause can't be told, and was an error whose fix (master quality) it already had. VideoToolbox's patches measured 0.012-0.014: under 0.012, an untold cause is a warning. * raea check: no face, place or caption reading on a render that has no footage or sound A local 3D shot's render check waited on a scene reader for faces and on a transcript of a file with no audio track: the footage cut's rules, on a shot raea drew whole. Its manifest says what it holds: with no video on any frame, frames and place have nothing to read; with no sound clip, captions has nothing said. * raea check: a file with no sound track says nothing A silent shot's say, never and CTA rules waited on a transcript raea words refused to make (no audio track). A file whose probe shows no sound track has no words, so the brief's lines are read off the screen alone. * raea check: a playable's missing orientation says what the brief's one shape means A playable brief asking for 9:16 left orientation unset in brief.ts, the check asked for a landscape composition, and the agent built a letterboxed stand-in. The fix now says: one shape in the brief is its orientation, written in brief.ts, never a stand-in of the other shape. --------- Co-authored-by: shinyobjectz --- apps/check/src/picture.rs | 14 ++++++++++++-- apps/check/src/tests.rs | 4 ++++ sdk/goal/src/facts.ts | 9 ++++++++- sdk/goal/src/media.ts | 16 ++++++++++++++++ sdk/goal/src/packs/captions.ts | 4 ++-- sdk/goal/src/packs/frames.ts | 26 +++++++++++++++++++------- sdk/goal/src/packs/place.ts | 4 ++-- sdk/goal/src/packs/playable.ts | 2 +- sdk/goal/src/packs/sound.ts | 10 +++++++++- sdk/goal/test/cut.test.ts | 6 ++++-- sdk/goal/test/frames.test.ts | 29 +++++++++++++++++++++++++++++ sdk/goal/test/sound.test.ts | 12 +++++++++++- 12 files changed, 117 insertions(+), 19 deletions(-) diff --git a/apps/check/src/picture.rs b/apps/check/src/picture.rs index 2c45973e..5b0715d6 100644 --- a/apps/check/src/picture.rs +++ b/apps/check/src/picture.rs @@ -15,6 +15,16 @@ pub(crate) const MOST: f32 = 4.0; pub(crate) const RUN: usize = 4; pub(crate) const BACK: usize = 4; pub(crate) const BLOTCHY: f64 = 0.009; +/// The least blotching an encoder's patches have been measured at (the VideoToolbox exports' 0.012): a score between +/// BLOTCHY and this, whose cause can't be told, is a warning, never an error (12-05: a 3D shot rendered at master +/// quality read 0.010, from its shadows' own dithered edge, and was an error whose fix, master quality, it already had) +pub(crate) const BLOTCHED: f64 = 0.012; + +/// How a finding whose cause can't be told stands: an error when more than a fifth of the samples blotch and the worst +/// is past BLOTCHED, else a warning +pub(crate) fn untold_level(share: f64, worst: f64) -> u8 { + if share > 0.2 && worst >= BLOTCHED { 1 } else { 2 } +} pub(crate) fn blotch_score(y: &[u8], w: usize, h: usize) -> Option { let (bw, bh) = (w / 8, h / 8); @@ -190,8 +200,8 @@ pub(crate) fn blotching_from(video: &str, probe: &Probe, scores: &[Option], let own = if a.0.before > 0 { format!("; {} of the samples show the footage's own too, which stays", a.0.before) } else { String::new() }; (if a.0.worse as f64 / a.0.of.max(1) as f64 > 0.2 { 1 } else { 2 }, first.or(Some(at)), format!("the encode added blocky patches in dark areas: {} of {} samples are blotchier than the composition draws them unencoded; render with --quality master, which gives the darks the bits they need{own}", a.0.worse, a.0.of)) } - Some(Err(why)) => (if share > 0.2 { 1 } else { 2 }, Some(at), format!("{found}; whether the encode made them or the picture holds them couldn't be told ({why}): render with --quality master if the encode starved the darks")), - None => (if share > 0.2 { 1 } else { 2 }, Some(at), format!("{found}: the encode starved the near-blacks, or the footage holds them; render with --quality master, and check a render made in a raea project to tell which")), + Some(Err(why)) => (untold_level(share, worst), Some(at), format!("{found}; whether the encode made them or the picture holds them couldn't be told ({why}): render with --quality master if the encode starved the darks")), + None => (untold_level(share, worst), Some(at), format!("{found}: the encode starved the near-blacks, or the footage holds them; render with --quality master, and check a render made in a raea project to tell which")), }; issues.push(Issue { rule: "blotching", p, at, says }); } else if seen > 0 { diff --git a/apps/check/src/tests.rs b/apps/check/src/tests.rs index f2c6a01d..dc0f51b8 100644 --- a/apps/check/src/tests.rs +++ b/apps/check/src/tests.rs @@ -51,6 +51,10 @@ fn flat_dark_is_clean_and_stepped_dark_is_blotchy() { (20.0 - (x * x + y * y).sqrt() / 24.0).max(6.0) as u8 }).collect(); assert!(blotch_score(&rings, w, h).unwrap() < BLOTCHY / 2.0); + // a cause that can't be told: an error only past an encoder's measured blotching, on more than a fifth of samples + assert_eq!(untold_level(1.0, 0.010), 2); + assert_eq!(untold_level(1.0, 0.09), 1); + assert_eq!(untold_level(0.1, 0.09), 2); assert_eq!(x264_crf(b"..\x05x264 - core 165 r3222 - H.264/MPEG-4 AVC codec - options: cabac=1 rc=crf mbtree=1 crf=12.0 qcomp=0.60"), Some(12.0)); assert_eq!(x264_crf(b"Lavf61 VideoToolbox"), None); } diff --git a/sdk/goal/src/facts.ts b/sdk/goal/src/facts.ts index caca2a15..df589299 100644 --- a/sdk/goal/src/facts.ts +++ b/sdk/goal/src/facts.ts @@ -16,7 +16,14 @@ export type Clip = { key?: string; from: number; to: number; src: string; at: nu /** a text on a frame, in render pixels: its layout box and its ink */ export type ManifestText = { text: string; box?: number[]; ink?: number[]; opacity?: number; size?: number } /** `raea render --manifest`: the frames with their texts, and the sound's clips */ -export type Manifest = { width?: number; height?: number; fps?: number; length?: number; frames?: { frame: number; text?: ManifestText[] }[]; sounds?: { fps?: number; clips?: Clip[] } } +export type Manifest = { width?: number; height?: number; fps?: number; length?: number; frames?: { frame: number; text?: ManifestText[]; videos?: unknown[] }[]; sounds?: { fps?: number; clips?: Clip[] } } + +/** whether a render shows footage, as far as its manifest says (a video on some frame): a 3D shot or motion graphics + * drawn whole by raea has no one in it for a scene reader to find, and its texts are the manifest's own (12-05: a + * local 3D shot's check waited on a scene reader for faces it couldn't have). No manifest: it may, so it's read */ +export const footageIn = (m: Manifest | null) => !m || (m.frames ?? []).some((fr) => (fr.videos?.length ?? 0) > 0) +/** whether a render plays any sound, as far as its manifest says: with none, nothing is said to be captioned */ +export const soundIn = (m: Manifest | null) => !m || (m.sounds?.clips?.length ?? 0) > 0 export interface FileFacts { /** as the project names it (relative to its folder) */ diff --git a/sdk/goal/src/media.ts b/sdk/goal/src/media.ts index 23c9f5e5..50d3fde2 100644 --- a/sdk/goal/src/media.ts +++ b/sdk/goal/src/media.ts @@ -62,6 +62,19 @@ export function shape(file: string): { width: number; height: number; fps: numbe return null } +/** whether a file has a sound track (ffprobe's audio streams); null when no probe could read it */ +export function audible(file: string): boolean | null { + for (const [cmd, pre] of [[RAEA, ["media", "ffprobe"]], ["ffprobe", []]] as const) { + const r = spawnSync(cmd, [...pre, "-v", "error", "-select_streams", "a", "-show_entries", "stream=index", "-of", "json", file], { encoding: "utf8" }) + // a file the probe couldn't read isn't known to be silent + if (r.status !== 0) continue + try { + return (JSON.parse(r.stdout ?? "").streams ?? []).length > 0 + } catch {} + } + return null +} + /** the level every 10 ms, in dB, of 16 kHz mono 16-bit samples */ export function levelsOf(pcm: Int16Array): number[] { const hop = 160 @@ -179,6 +192,9 @@ const firstLine = (s: string | null | undefined) => (s ?? "").split("\n").map((l export async function words(file: string, anyAge = false): Promise { const kept = anyAge ? [`${stem(file)}.words.json`, `${file}.words.json`].find(existsSync) : freshBeside(file, "words.json") if (kept) return readWords(kept) + // a file with no sound track says nothing: the brief's lines are then read off the screen alone (12-05: a silent shot's + // say, never and CTA rules waited on a transcript `raea words` refused to make) + if (audible(file) === false) return [] const out = `${stem(file)}.words.json` if (!farm()) { const r = spawnSync(RAEA, ["words", file, "-o", out], { encoding: "utf8" }) diff --git a/sdk/goal/src/packs/captions.ts b/sdk/goal/src/packs/captions.ts index 32df4543..cb67023d 100644 --- a/sdk/goal/src/packs/captions.ts +++ b/sdk/goal/src/packs/captions.ts @@ -15,7 +15,7 @@ // error (words dropped: "when they get"). Fillers (um, uh) aren't counted. // Letters are compared, not words: the reader often drops a caption's spaces ("Createyour GiftExchangehere."). import { check, found } from "raea/check" -import type { FileFacts } from "../facts.ts" +import { soundIn, type FileFacts } from "../facts.ts" import type { Word } from "../media.ts" import type { TextLine } from "./place.ts" import { asDigits, digitsIn } from "./numbers.ts" @@ -298,7 +298,7 @@ export async function placedWords(f: FileFacts): Promise { export default check( { id: "captions", text: "everything said is captioned, and every caption says exactly what's heard there, no word added, changed or left out", over: "file", at: ["render", "publish", "done"], needs: ["words", "scene"] }, async (f) => { - if (!f.made || f.kind !== "video") return + if (!f.made || f.kind !== "video" || !soundIn(f.manifest)) return // numbers in words and in digits read alike on both sides (numbers.ts) const heard = asDigits(await f.words()) if (!heard.length) return diff --git a/sdk/goal/src/packs/frames.ts b/sdk/goal/src/packs/frames.ts index feffb28f..183e4e42 100644 --- a/sdk/goal/src/packs/frames.ts +++ b/sdk/goal/src/packs/frames.ts @@ -8,12 +8,14 @@ // frame's height or more) touching an edge or a split screen's seam: a second or more is an error, shorter a // warning. The reader takes a hand or a bag at the edge for a face now and then (12-05, run 28: Elfster's "face cut by // the left edge" was a hand at 0.79 then 0.65, where the people in the shot read 0.92 and over), so a run it's less -// than FACE_SURE sure of is a warning, never an error. A split screen with a face in one half only is a warning. +// than FACE_SURE sure of, and smaller than FACE_LIKE of the other faces in its frames, is a warning, never an error +// (the hand was 0.64 of the faces beside it; Body Shop's interviewer, cut by the edge at 0.74 and 0.61, was 0.98 of +// them, and stays an error). A split screen with a face in one half only is a warning. // A face at the edge that's meant (someone walking out of shot) is said, with its reason, in OUT.despite.txt beside // the video: its findings are then warnings. import { existsSync, readFileSync } from "node:fs" import { check, found } from "raea/check" -import type { FileFacts } from "../facts.ts" +import { footageIn, type FileFacts } from "../facts.ts" import { RATE, stem, type Faces } from "../media.ts" import { quote } from "../text.ts" @@ -22,6 +24,8 @@ export const FACE_MIN = 0.05 /** a cut face is an error only when the reader is this sure, over its run, that it's a face (a face's score; 1 when the * reader gives none) */ export const FACE_SURE = 0.8 +/** a doubtful face at least this share of the height of the other faces in its frame is taken as a face all the same */ +export const FACE_LIKE = 0.75 /** least font sizes, in pixels of a frame 1080 wide (its shorter side): the Direct Response skill's table */ export const TEXT_ERROR = 40 export const TEXT_WARN = 48 @@ -49,8 +53,9 @@ const near = (a: Split, b: Split) => a.axis === b.axis && Math.abs(a.at - b.at) const big = (fr: NonNullable) => fr.faces.filter((f) => f[3] >= fr.h * FACE_MIN) /** what cuts a face in a frame (an edge of the frame, or a split screen's seam), with how sure the reader is it's a face */ -function cutBy(fr: NonNullable, splits: Split[]): { by: string; score: number } | null { - for (const [x, y, fw, fh, s] of big(fr)) { +function cutBy(fr: NonNullable, splits: Split[]): { by: string; score: number; like: number | null } | null { + const faces = big(fr) + for (const [x, y, fw, fh, s] of faces) { const score = Number.isFinite(s) ? s : 1 const by = x <= 1 ? "the left edge" @@ -62,7 +67,11 @@ function cutBy(fr: NonNullable, splits: Split[]): { by: string; score: nu return (a < sp.at - 2 && b > sp.at + 2) || Math.abs(b - sp.at) <= 3 || Math.abs(a - sp.at) <= 3 }) ? "the split screen's seam" : null - if (by) return { by, score } + if (!by) continue + // its height against the middle of the other faces' heights (null with no other face to go by) + const others = faces.filter((f) => f[0] !== x || f[1] !== y).map((f) => f[3]).sort((a, b) => a - b) + const like = others.length ? fh / others[Math.floor(others.length / 2)] : null + return { by, score, like } } return null } @@ -96,7 +105,9 @@ export function cutFaces(frames: Faces[], rate = RATE): Finding[] { const from = i / rate const to = j / rate const sure = hits.slice(i, j).reduce((n, h) => n + (h?.score ?? 0), 0) / (j - i) - const doubt = sure < FACE_SURE ? ` (the reader is ${Math.round(sure * 100)}% sure it's a face: look)` : "" + const likes = hits.slice(i, j).map((h) => h?.like).filter((l): l is number => l != null) + const like = likes.length ? likes.reduce((n, l) => n + l, 0) / likes.length : null + const doubt = sure < FACE_SURE && (like === null || like < FACE_LIKE) ? ` (the reader is ${Math.round(sure * 100)}% sure it's a face: look)` : "" out.push({ level: to - from >= 1 && !doubt ? "error" : "warn", kind: "face-cut", at: from, until: to, says: `a face${doubt} is cut by ${by} from ${from.toFixed(1)} s to ${to.toFixed(1)} s: reframe on the person (both eyes, mouth and chin inside the picture)${by.includes("seam") ? ", or cut between two singles" : " or cut away"}` }) } const split = held.map((ss) => ss[0] ?? null) @@ -158,7 +169,8 @@ export default check( if (!f.made || f.kind !== "video") return const say = (x: Finding) => found({ level: x.level, says: x.says, seconds: x.at === null ? undefined : x.until === undefined ? x.at : [x.at, x.until] }) if (f.manifest) for (const x of smallText(f.manifest)) say(x) - // the text's sizes are said even where the faces wait for a scene reader + // the text's sizes are said even where the faces wait for a scene reader; a render with no footage has no faces + if (!footageIn(f.manifest)) return const why = despite(f.abs) for (const x of cutFaces((await f.scene()).faces, RATE)) say(why && x.kind === "face-cut" ? { ...x, level: "warn", says: `${x.says} (despite: ${why})` } : x) }, diff --git a/sdk/goal/src/packs/place.ts b/sdk/goal/src/packs/place.ts index 25c95576..9dc47975 100644 --- a/sdk/goal/src/packs/place.ts +++ b/sdk/goal/src/packs/place.ts @@ -15,7 +15,7 @@ // top-left in pixels and in shares of the frame, and what each covers. import path from "node:path" import { check, found } from "raea/check" -import type { FileFacts } from "../facts.ts" +import { footageIn, type FileFacts } from "../facts.ts" import { RATE } from "../media.ts" import { quote } from "../text.ts" @@ -306,7 +306,7 @@ export function placeReport(file: string, scenes: Scene[], size: [number, number export default check( { id: "place", text: "no text over a face, hands or what the shot is about where a clear place of its size exists", over: "file", at: ["render", "publish", "done"], needs: ["scene"] }, async (f) => { - if (!f.made || f.kind !== "video" || !f.manifest?.frames?.length) return + if (!f.made || f.kind !== "video" || !f.manifest?.frames?.length || !footageIn(f.manifest)) return const { scenes } = await f.scene() for (const x of textOver(f.manifest, scenes, RATE)) found({ level: x.level, says: x.says, seconds: x.at === null ? undefined : x.until === undefined ? x.at : [x.at, x.until] }) }, diff --git a/sdk/goal/src/packs/playable.ts b/sdk/goal/src/packs/playable.ts index 5ab9b575..aa39330e 100644 --- a/sdk/goal/src/packs/playable.ts +++ b/sdk/goal/src/packs/playable.ts @@ -65,7 +65,7 @@ export const playablePack = check({ id: "playable", text: "each network's p const asked: ("portrait" | "landscape")[] = want === "both" ? ["portrait", "landscape"] : [want] const missing = asked.filter((s) => !shapes.has(s)) for (const s of missing) - found({ says: `${p.game} registers no ${s} composition (it has ${m.compositions.map((c) => `${c.id} ${c.width}x${c.height}`).join(", ") || "none"})`, about: [p.game], fix: want === "both" ? "register a portrait and a landscape composition of the game, the host plays the one nearest the screen; or say orientation in the brief" : undefined }) + found({ says: `${p.game} registers no ${s} composition (it has ${m.compositions.map((c) => `${c.id} ${c.width}x${c.height}`).join(", ") || "none"})`, about: [p.game], fix: want === "both" ? "if the brief asks for one shape only (9:16, or portrait), that's its orientation: write `orientation: \"portrait\"` (or \"landscape\") in brief.ts's playable goal and export again, never a stand-in of the other shape; if the brief names no shape, register a portrait and a landscape composition of the game (the host plays the one nearest the screen)" : undefined }) for (const pg of m.pages.filter((x) => x.bytes > CAP)) found({ says: `${pg.file} is ${Math.round(pg.bytes / 1024)} KB, over the ${CAP / 1024} KB cap`, about: [pg.file] }) const written = new Set(m.pages.map((x) => x.network)) for (const net of [...networksOf(p), "preview"].filter((n) => !written.has(n))) found({ says: `no ${net} page in the last export`, about: [`${OUT}/${nameOf(p)}-${net}`] }) diff --git a/sdk/goal/src/packs/sound.ts b/sdk/goal/src/packs/sound.ts index c00ec34e..54239162 100644 --- a/sdk/goal/src/packs/sound.ts +++ b/sdk/goal/src/packs/sound.ts @@ -81,6 +81,14 @@ export function speechLevel(l: Levels, a: number, b: number, words: Word[]): num return pct(frames, SPEECH_Q) } +/** a line's level: its speech level inside its words, or over the whole clip where that's louder. A transcript's words + * can sit in the pause beside the speech (12-05, run 28: Elfster's "Santa gift you've ever gotten?" timed 0.8 s late, + * in the silence after it was said, read -28 dB where the speech ran at -10, and a line the mix had evened was called + * "19 dB under the cut's other lines"); a clip that's mostly pause around a short word keeps its word's level. */ +export function lineLevel(l: Levels, a: number, b: number, words: Word[]): number { + return Math.max(speechLevel(l, a, b, words), speechLevel(l, a, b, [])) +} + /** the nearest time to `t` (within NEAR, never past `limit` on the clip's inside) that is a gap: 40 ms around it at * least GAP dB under the speech level and inside no word */ /** the level under which a take is quiet enough to cut in: GAP under the speech, or near the take's own floor */ @@ -251,7 +259,7 @@ export async function soundOf(f: FileFacts): Promise<{ findings: Finding[]; voic // a line is a clip a word is said in: one with none, or only a transcriber's broken timing (a "word" 90 s long, // 12-05 run 12), is a pause or a reaction, never "a line 51 dB under the others" const said = words.filter((w) => w.end - w.start <= WORD_MAX && w.end > c.at && w.start < c.at + dur) - if (said.length) heard.push({ clip: c, kind, level: speechLevel(l, c.at, c.at + dur, said) + (c.gainDb ?? 0) }) + if (said.length) heard.push({ clip: c, kind, level: lineLevel(l, c.at, c.at + dur, said) + (c.gainDb ?? 0) }) } else { const l = f.levels(c.at, c.at + Math.min(dur, kind === "sfx" ? 2 : 20), file) const level = kind === "sfx" ? pct(l.db, 0.98) : pct(l.db.filter((x) => x > -70), 0.5) diff --git a/sdk/goal/test/cut.test.ts b/sdk/goal/test/cut.test.ts index 5d670702..11d0e0af 100644 --- a/sdk/goal/test/cut.test.ts +++ b/sdk/goal/test/cut.test.ts @@ -85,10 +85,12 @@ test("a delivered cut is held to its words and shape", async () => { expect(of(r2, "say", S2)).toHaveLength(1) expect(of(r2, "cta", S2)).toHaveLength(1) expect(r2.passed).toBe(false) - // words from before the file's last change say nothing about it now: heard again, which waits here (no transcriber) + // words from before the file's last change say nothing about it now: it's heard again, and the stand-in clip has no + // sound track, so it says nothing and the brief's phrase is missing (12-05: never a wait on a transcript of silence) touch(`${d}/${S1}`, 60) const r3 = await run(d) - expect(r3.waits.some((w) => w.check === "say" && w.file === S1)).toBe(true) + expect(r3.waits.some((w) => w.check === "say" && w.file === S1)).toBe(false) + expect(of(r3, "say", S1)).toHaveLength(1) }) test("the wrong shape is named", async () => { diff --git a/sdk/goal/test/frames.test.ts b/sdk/goal/test/frames.test.ts index e669e6a0..1161fa49 100644 --- a/sdk/goal/test/frames.test.ts +++ b/sdk/goal/test/frames.test.ts @@ -15,6 +15,14 @@ test("the frames pack's measures", () => { f = cutFaces([fr([[0, 598, 41, 82, 0.79]]), fr([[0, 594, 40, 84, 0.65]]), fr([whole])]) assert.deepEqual(f.map((x) => [x.level, x.at, x.until]), [["warn", 0, 1]]) assert.match(f[0].says, /72% sure it's a face/) + // beside a person's face 130 px tall the hand (0.63 of it) is still doubted; Body Shop's interviewer, cut by the edge + // at 0.74 and 0.61 but as tall as the face beside him (0.98), is a face: an error + const guest = [260, 300, 110, 130, 0.95] + f = cutFaces([fr([[0, 598, 41, 82, 0.79], guest]), fr([[0, 594, 40, 84, 0.65], guest]), fr([guest])]) + assert.deepEqual(f.map((x) => x.level), ["warn"]) + f = cutFaces([fr([[0, 280, 100, 128, 0.74], guest]), fr([[0, 282, 98, 127, 0.61], guest]), fr([guest])]) + assert.deepEqual(f.map((x) => [x.level, x.at, x.until]), [["error", 0, 1]]) + assert.doesNotMatch(f[0].says, /sure/) // a split screen: a lone line held; a caption's box (two lines close together) isn't one assert.deepEqual(splitsOf(fr([], [["h", 480, 0.8]])), [{ axis: "h", at: 480 }]) assert.deepEqual(splitsOf(fr([], [["h", 446, 0.8], ["h", 513, 0.8]])), []) @@ -33,3 +41,24 @@ test("the frames pack's measures", () => { assert.deepEqual(smallText(m(1080, 64)), []) }) + +test("a render with no footage, or no sound, has no faces to read and nothing said to caption", async () => { + const { footageIn, soundIn } = await import("../src/facts.ts") + // 12-05: a local 3D shot (no video on any frame, no sound) waited on a scene reader for faces it couldn't have + const shot = { frames: [{ frame: 0, videos: [], text: [] }], sounds: { clips: [] } } + assert.equal(footageIn(shot), false) + assert.equal(soundIn(shot), false) + assert.equal(footageIn({ frames: [{ frame: 0 }, { frame: 1, videos: [{ src: "take.mp4" }] }] }), true) + assert.equal(footageIn(null), true, "no manifest: it may show footage") +}) + +test("a file with no sound track has no words, so the brief's lines are read off the screen", async () => { + const { audible, words } = await import("../src/media.ts") + const { execFileSync } = await import("node:child_process") + const { mkdtempSync } = await import("node:fs") + const dir = mkdtempSync(`${(await import("node:os")).tmpdir()}/silent-`) + const f = `${dir}/silent.mp4` + execFileSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", "color=c=black:s=64x64:d=1", "-c:v", "libx264", "-pix_fmt", "yuv420p", f]) + assert.equal(audible(f), false) + assert.deepEqual(await words(f), []) +}) diff --git a/sdk/goal/test/sound.test.ts b/sdk/goal/test/sound.test.ts index da997d75..10ba1de2 100644 --- a/sdk/goal/test/sound.test.ts +++ b/sdk/goal/test/sound.test.ts @@ -2,7 +2,7 @@ import { test } from "bun:test" import assert from "node:assert/strict" import type { Clip } from "../src/facts.ts" import type { Levels } from "../src/media.ts" -import { balance, busOf, editPoints, joined, nearestGap, soundOf, type Heard } from "../src/packs/sound.ts" +import { balance, busOf, editPoints, joined, lineLevel, nearestGap, soundOf, type Heard } from "../src/packs/sound.ts" test("the sound pack's measures", async () => { // the sound pack's measures, on made-up takes @@ -126,3 +126,13 @@ test("a take that plays straight on across two clips is one clip: its seam is no assert.equal(joined([{ ...a, fadeOut: 0.2 }, b], 30).length, 2) assert.equal(joined([a, { ...b, src: "/w/footage/Other.mp4" }], 30).length, 2) }) + +test("a line whose words a transcriber timed in the pause beside it is measured where it's said", () => { + // 12-05, run 28: speech at -10 dB from 0.8 to 2.0 s, silence after; the words timed 2.0-3.0 s, in the silence + const l: Levels = { start: 0, db: Array.from({ length: 400 }, (_, i) => (i >= 80 && i < 200 ? -10 : -60)) } + const late = [{ text: "Santa", start: 2.0, end: 2.4 }, { text: "gift", start: 2.4, end: 3.0 }] + assert.equal(lineLevel(l, 0, 4, late), -10) + // a short word in a long quiet clip keeps its word's level + const word = { start: 0, db: Array.from({ length: 400 }, (_, i) => (i >= 100 && i < 130 ? -12 : -60)) } + assert.equal(lineLevel(word, 0, 4, [{ text: "yes", start: 1.0, end: 1.3 }]), -12) +})