Compare commits

..
Author SHA1 Message Date
shinyobjectz 7ea66741a0 raea cut drops a phrase the transcriber squeezed into one instant
Three or more words, each 30 ms or less, starting within 50 ms: a phrase heard
twice and its copy timed at one instant. Body Shop's take said "Sign up for the
news, sign up for the newsletter"; its words put "up for the news sign" at
10.32-10.34 s, raea cut took the CTA line from that "sign", and the clip
started inside "up": "...hours of it for the newsletter" (12-05, run 28).
words() drops such runs, so the line is found where it was said and captions
never show the phantom words.
2026-12-05 13:23:13 -08:00
shinyobjectz dbee528778 faces.json's reader in its own file: native.ts under the 500-line limit 2026-12-05 13:15:43 -08:00
shinyobjectz bad441493e raea cut reads a take's jump cuts through ffmpeg, on every core
raea media cuts decodes with openh264 on a Linux box, on one core: 38 s for a
3.5-minute light copy and 66 s for a 6-minute one, the first raea cut on each
take of a run (12-05, run 28). ffmpegCuts reads the luma at 160x90 through the
ffmpeg CLI and scores each frame as raea media cuts does: the same cuts on
three Body Shop light copies and a made take with two, in 5.8 s, 8.1 s and
0.5 s against 38 s, 65 s and 3.2 s. Where ffmpeg can't read the take, the
engine reads it.
2026-12-05 13:10:49 -08:00
shinyobjectz 14a10fc2b0 raea cut takes each clip's face from footage/faces.json, and imports linesIn
A box has no raea-perceive, so perception.json's face lookup (a still and
raea-perceive per clip, redone for every earlier clip on each --append) found
no face there and still cost each still's decode: a step of 13 raea cut calls
ran past a box step's 3 minutes (12-05). raea cloud's prep already writes each
take's faces about once a second into footage/faces.json; perception() now
reads the face from it when it holds the take, and falls back to a still
elsewhere.

native.ts used linesIn (since #338) without importing it, so every raea cut by
lines threw "linesIn is not defined" when run from source.
2026-12-05 12:42:21 -08:00
13 changed files with 166 additions and 67 deletions

No files matched your search

+1 -1
View File
@@ -219,7 +219,7 @@ pub(crate) fn contrast(video: &str, runs: &[Run], w: f64, h: f64, probe: &Probe,
measured += 1;
if ratio < 3.0 {
low += 1;
issues.push(Issue { rule: "contrast", p: 1, at: Some(t), says: format!("{} is {:.2}:1 against what's behind it; make it at least 3:1 (a band, a shadow for separation, or another colour)", quote(&r.text), (ratio * 100.0).floor() / 100.0) });
issues.push(Issue { rule: "contrast", p: 1, at: Some(t), says: format!("{} is {ratio:.1}:1 against what's behind it; make it at least 3:1 (a band, a shadow for separation, or another colour)", quote(&r.text)) });
}
}
if measured > 0 && low == 0 {
+13 -1
View File
@@ -1,7 +1,7 @@
// pace.ts on made-up words and levels: a short run between two long pauses joins a neighbour; level evening measures
// only clips with a second of speech and gives a short clip its own take's gain
import { expect, test } from "bun:test";
import { evenLevels, pace, type Levels } from "../src/pace";
import { evenLevels, linesIn, pace, unsqueezed, type Levels } from "../src/pace";
/** levels at 10 ms: speech (-20 dB) inside each word, quiet (-70 dB) elsewhere, over `seconds` */
function levels(ws: { from: number; to: number }[], seconds: number): Levels {
@@ -66,3 +66,15 @@ test("a line stopping mid-sentence with no pause runs on to its sentence's end;
const r = pace(long, l2, [[0, 2]], { hook: 0 });
expect(r.pieces[0].to).toBeLessThanOrEqual(1.06 + 1 / 30);
});
test("a phrase a transcriber heard twice and squeezed into one instant is dropped, and the line is found where it was said", () => {
// 12-05, run 28: "Sign up for the news, sign up for the newsletter", with "up for the news sign" all at 10.32-10.34 s
const w = (text: string, a: number, b: number) => ({ text, from: a / 1000, to: b / 1000 });
const heard = [w("for", 9280, 9360), w("the", 9360, 9440), w("newsletter.", 9440, 9460), w("Sign", 10080, 10320), w("up", 10320, 10340), w("for", 10320, 10340), w("the", 10320, 10340), w("news", 10320, 10340), w("sign", 10320, 10340), w("up", 10320, 10400), w("for", 10400, 10560), w("the", 10560, 10640), w("newsletter", 10640, 10960)];
const ws = unsqueezed(heard);
expect(ws.map((x) => x.text).join(" ")).toBe("for the newsletter. Sign up for the newsletter");
const { spans } = linesIn(ws, ["sign up for the newsletter"]);
expect(ws[spans[0][0]].from).toBe(10.08);
// two short words together are speech, kept
expect(unsqueezed([w("a", 0, 20), w("cat", 20, 40), w("sat", 300, 500)]).length).toBe(3);
});
+38
View File
@@ -255,6 +255,44 @@ ${Array.from({ length: 40 }, (_, i) => `.u${i} { margin: ${i}px; }`).join("\n")}
}
});
// a take's jump cuts read through the ffmpeg CLI (cutplan.ts ffmpegCuts): where raea media cuts finds them
test.skipIf(spawnSync("ffmpeg", ["-version"]).status !== 0)("raea cut reads a take's jump cuts through ffmpeg, where the engine finds them", async () => {
const { ffmpegCuts } = await import("../src/cutplan.ts");
const dir = mkdtempSync(join(tmpdir(), "raea-ffcuts-"));
try {
const color = (c: string) => ["-f", "lavfi", "-i", `color=c=${c}:s=320x180:r=30:d=2`];
spawnSync("ffmpeg", ["-v", "error", "-y", ...color("red"), ...color("blue"), ...color("green"), "-filter_complex", "[0][1][2]concat=n=3:v=1:a=0", "-c:v", "libx264", "-pix_fmt", "yuv420p", join(dir, "t.mp4")]);
expect(ffmpegCuts(join(dir, "t.mp4"), 0.08)).toEqual([2, 4]);
expect(ffmpegCuts(join(dir, "missing.mp4"), 0.08)).toBeNull();
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
// raea cloud's footage/faces.json (prep's faces, found on its farm): perception.json takes each clip's face from it,
// with no still and no raea-perceive (a box has none). A made clip and made-up faces, never real footage
test.skipIf(spawnSync("ffmpeg", ["-version"]).status !== 0)("raea cut takes each clip's face from footage/faces.json", () => {
const dir = mkdtempSync(join(tmpdir(), "raea-cut-faces-"));
const run = (...a: string[]) => spawnSync("bun", [join(here, "src/native.ts"), bin, ...a], { cwd: dir, encoding: "utf8", env: { ...process.env, RAEA_PERCEIVE: "/nonexistent/raea-perceive" } });
try {
mkdirSync(join(dir, "media"));
mkdirSync(join(dir, "footage"));
spawnSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", "color=c=gray:s=160x120:r=30:d=4", "-c:v", "libx264", "-pix_fmt", "yuv420p", join(dir, "media/take01.mp4")]);
const said: [string, number, number][] = [["Hello", 200, 600], ["there.", 650, 1000], ["This", 1500, 1700], ["is", 1750, 1850], ["the", 1900, 2000], ["second", 2100, 2500], ["line.", 2550, 2900]];
writeFileSync(join(dir, "media/take01.words.json"), JSON.stringify(said.map(([text, start_ms, end_ms]) => ({ text, start_ms, end_ms }))));
// no face by the first clip's middle (0.6 s, nearest 1 s); two at 2 s, by the second's (2.4 s): the larger is kept
const face = [0.25, 0.25, 0.5, 0.5, 0.9];
writeFileSync(join(dir, "footage/faces.json"), JSON.stringify({ take01: { w: 160, h: 120, t: [0, 1, 2, 3], s: [[], [], [[0.1, 0.1, 0.1, 0.1, 0.99], face], [face]] } }));
const r = run("cut", "take01", "hello there", "the second line");
expect(r.stderr).toBe("");
const band = { safe: { top: 220, bottom: 1500 } };
// 160x120 covering 1080x1920 is 16x, centred: x 0.25*160*16 - 740, y 0.25*120*16, w 0.5*160*16, h 0.5*120*16
expect(JSON.parse(readFileSync(join(dir, "perception.json"), "utf8"))).toEqual({ "0": band, "33": { ...band, face: { x: -100, y: 480, w: 1280, h: 960 } } });
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
// a stock talking take (fixtures/CREDITS.md): the face branch of frame and perception.json. The footage fixtures are
// the maintainers' (tools/public-first/private.paths), so a checkout without them skips this
test.skipIf(!existsSync(join(raea, "engine/media/fixtures")))("raea frame and raea cut find the face in a talking take", () => {
+31 -1
View File
@@ -1,5 +1,6 @@
// How raea cut times a take's lines: the take's light copy when raea cloud keeps one, its jump cuts (kept in raea's
// cache) and sound level, and pace.ts's timing, kept off the take's own jump cuts. native.ts gives it the engine.
import { spawnSync } from "node:child_process";
import { createHash } from "node:crypto";
import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
import { homedir, tmpdir } from "node:os";
@@ -11,6 +12,35 @@ export type TakeIO = { at: (p: string) => string; engineRun: (a: string[]) => st
const ms = (s: number) => Math.round(s * 1000) / 1000;
/** A take's jump cuts read through the ffmpeg CLI where there is one: its luma at 160x90, every frame, scored as raea
* media cuts scores them (ffmpeg's select scene: each frame's mean absolute difference from the last, less the
* difference before it, over 100). ffmpeg decodes on every core; the engine's own decoder on a Linux box is openh264 on
* one (12-05: 38 s for a 3.5-minute light copy, 66 s for a 6-minute one, against 4 s for ffmpeg), and a box step has
* 3 minutes. The small picture leaves a hard cut's score where it was and a frame's grain out. null where ffmpeg
* can't read it: the engine reads it then. */
export function ffmpegCuts(file: string, threshold: number): number[] | null {
const [w, h] = [160, 90];
const r = spawnSync("ffmpeg", ["-v", "info", "-nostats", "-i", file, "-an", "-vf", `scale=${w}:${h}:flags=area,format=gray,showinfo`, "-f", "rawvideo", "-"], { maxBuffer: 1 << 30 });
if (r.error || r.status !== 0 || !r.stdout?.length) return null;
// each frame's time, from showinfo's lines in order
const times = [...String(r.stderr).matchAll(/\bn:\s*\d+\s+pts:\s*-?\d+\s+pts_time:(-?[\d.]+)/g)].map((m) => Number(m[1]));
const n = w * h;
const frames = Math.floor(r.stdout.length / n);
if (!frames || times.length !== frames) return null;
const y = r.stdout as Buffer;
const out: number[] = [];
let prev = 0;
for (let f = 1; f < frames; f++) {
let sad = 0;
for (let i = f * n, j = (f - 1) * n, e = i + n; i < e; i++, j++) sad += Math.abs(y[i] - y[j]);
const mafd = sad / n;
const score = Math.min(Math.max(Math.min(mafd, Math.abs(mafd - prev)) / 100, 0), 1);
prev = mafd;
if (score > threshold) out.push(ms(times[f]));
}
return out;
}
/** cutPlan and takeLevels over `io`, each take's levels kept for the run */
export function timing({ at, engineRun, engineJson, isAudio }: TakeIO) {
/** The take to read for timing: its light copy when raea cloud keeps one (.raea-cloud/proxies/NAME.mp4 in the project,
@@ -37,7 +67,7 @@ export function timing({ at, engineRun, engineJson, isAudio }: TakeIO) {
} catch {
kept = "";
}
const cuts = (engineJson(["media", "cuts", file, "--threshold", "0.08"]).cuts as { at: number }[]).map((c) => c.at);
const cuts = ffmpegCuts(file, 0.08) ?? (engineJson(["media", "cuts", file, "--threshold", "0.08"]).cuts as { at: number }[]).map((c) => c.at);
if (kept)
try {
mkdirSync(dirname(kept), { recursive: true });
+37
View File
@@ -0,0 +1,37 @@
// A take's faces from raea cloud's footage/faces.json, for raea cut's perception.json (native.ts perception)
import { readFileSync } from "node:fs";
import { basename, extname } from "node:path";
type Box = { x: number; y: number; w: number; h: number };
/** footage/faces.json in the project (raea cloud's prep: each take's faces about once a second, found on its farm, as
* shares of the take's picture, [x, y, w, h, score] each), read once. A box has no raea-perceive, so a still per clip
* found no face there and cost each `raea cut --append` every earlier clip's lookup again (12-05: a step of 13 cuts ran
* past a box's 3 minutes, and no cut on a box had a face in its perception.json) */
let facesKept: Record<string, { w?: number; h?: number; t?: number[]; s?: number[][][] }> | null | undefined;
function facesFile() {
if (facesKept === undefined)
try {
facesKept = JSON.parse(readFileSync(`${process.cwd()}/footage/faces.json`, "utf8"));
} catch {
facesKept = null;
}
return facesKept;
}
/** The largest face at the sample of faces.json nearest `t` (never one more than 1.5 s away), with the take's size: a
* face, none there (face undefined), or null when faces.json doesn't hold the take */
export function faceKept(file: string, t: number): { face?: Box; sw: number; sh: number } | null {
const take = facesFile()?.[basename(file, extname(file))];
const ts = take?.t, ss = take?.s;
if (!take || !Array.isArray(ts) || !Array.isArray(ss) || !ts.length || !take.w || !take.h) return null;
let k = 0;
ts.forEach((x, i) => {
if (Math.abs(x - t) < Math.abs(ts[k] - t)) k = i;
});
if (Math.abs(ts[k] - t) > 1.5) return null;
const faces = (ss[k] ?? []).filter((f) => Array.isArray(f) && f.length >= 4);
if (!faces.length) return { sw: take.w, sh: take.h };
const [x, y, w, h] = faces.reduce((a, b) => (b[2] * b[3] > a[2] * a[3] ? b : a));
return { face: { x, y, w, h }, sw: take.w, sh: take.h };
}
+11 -6
View File
@@ -10,8 +10,9 @@ import { basename, delimiter, dirname, extname } from "node:path";
import { brandKit, pixelsOf } from "./brand";
import { readSite, stylesOf } from "./scrape";
import { wordsOf } from "./heard";
import { evenLevels, markJumps, speechOf, toSound, type PaceOptions } from "./pace";
import { evenLevels, unsqueezed, linesIn, markJumps, speechOf, toSound, type PaceOptions } from "./pace";
import { timing } from "./cutplan";
import { faceKept } from "./faces";
import { harness, library, show, task } from "./app";
import { fromCwd } from "./show";
import { clothesHost } from "./wardrobe";
@@ -90,9 +91,11 @@ function words(take: string, hear = false): Word[] {
if (!hear) return [];
hearTake(take, file);
}
return (JSON.parse(readFileSync(file, "utf8")) as { text: string; start_ms: number; end_ms: number }[])
.filter((w) => w.text?.trim())
.map((w) => ({ text: w.text.trim(), from: w.start_ms / 1000, to: w.end_ms / 1000 }));
return unsqueezed(
(JSON.parse(readFileSync(file, "utf8")) as { text: string; start_ms: number; end_ms: number }[])
.filter((w) => w.text?.trim())
.map((w) => ({ text: w.text.trim(), from: w.start_ms / 1000, to: w.end_ms / 1000 })),
);
}
/** A tool a clean Mac lacks, found or installed once by raea's tools/ensure.sh (docs/app.feature AP6), which sits in
@@ -275,8 +278,10 @@ function perception(edit: { width: number; height: number; fps: number }, clips:
if (!seen.has(key)) {
let face: Box | undefined;
try {
const f = faceAt(c.file, mid);
const { sw, sh } = probeOf(c.file);
// faces.json's when it holds the take, else a still of it read here
const kept = faceKept(c.file, mid);
const f = kept ? kept.face : faceAt(c.file, mid);
const { sw, sh } = kept ?? probeOf(c.file);
if (f && sw && sh) {
const s = Math.max(edit.width / sw, edit.height / sh);
const [ox, oy] = [(edit.width - sw * s) / 2, (edit.height - sh * s) / 2];
+17
View File
@@ -18,6 +18,23 @@
/** a word in its take's seconds */
export type Word = { text: string; from: number; to: number };
/** A transcript's words less the runs it squeezed: three or more words each SQUEEZED s long or less, all starting within
* 50 ms of the first. No one says three words in 50 ms; a transcriber writes them when it hears a phrase twice and
* times the copy at one instant (12-05, run 28: Body Shop's "Sign up for the news, sign up for the newsletter" came
* as "Sign up for the news sign up for the newsletter" with "up for the news sign" all at 10.32-10.34 s, raea cut took
* the line from that "sign", and the CTA clip started inside "up") */
export const SQUEEZED = 0.03;
export function unsqueezed<W extends Word>(ws: W[]): W[] {
const out: W[] = [];
for (let i = 0; i < ws.length; ) {
let j = i;
while (j < ws.length && ws[j].to - ws[j].from <= SQUEEZED && ws[j].from - ws[i].from <= 0.05) j++;
if (j - i >= 3) i = j;
else out.push(ws[i++]);
}
return out;
}
/** a take's sound level every 10 ms (dB), from `start` seconds */
export type Levels = { start: number; db: number[] };
/** a stretch of quiet in a take: from its first quiet 10 ms to the first sound after it (s) */
+3 -12
View File
@@ -226,7 +226,7 @@ const HOOK_S = 5
* had none, read from its brief's "captions OR a text hook"): a cut with talking and no captions at all is an error,
* and so is a stretch of talking with none up. A text hook may be on screen beside them; it doesn't stand in for them.
* A brief that wants no captions says so, and the render says it with --despite captions WHY */
export function uncaptioned(shown: Shown[], heard: Word[], textUp: (t: number) => boolean = () => false, onCard: (w: Word) => boolean = () => false): Finding[] {
export function uncaptioned(shown: Shown[], heard: Word[], textUp: (t: number) => boolean = () => false): Finding[] {
heard = asDigits(heard)
// a brief's "captions OR a text hook, never both" means not both in one frame (12-03, Shane): the hook may hold the
// opening alone, so words in the first HOOK_S with other text up are covered by it; anywhere later it's no caption
@@ -237,9 +237,7 @@ export function uncaptioned(shown: Shown[], heard: Word[], textUp: (t: number) =
if (said.length < BARE.error.words) return []
const fix = "caption every line from the words file (whole phrases in the brand's caption style); a text hook goes with the captions, never instead of them. If the brief asks for no captions, render with --despite captions WHY"
if (!shown.length) return [{ level: "error", kind: "uncaptioned", at: said[0].start, says: `no captions over the talking: ${said.length} words, ${(said[said.length - 1].end - said[0].start).toFixed(1)} s, and no caption track (captions one after another under ${Math.round(TRACK * 100)}% of what's said, or fewer than ${CARDS} of them). ${fix}` }]
// a word is up when a caption is, or when text the render drew says it there (an end card with the line being said:
// captionsOf takes a frame full of text for a card, not captions; 12-05, run 28's Elfster end cards)
const up = (w: Word) => shown.some((s) => w.end >= s.from - 0.6 && w.start <= s.to + 0.3) || onCard(w)
const up = (w: Word) => shown.some((s) => w.end >= s.from - 0.6 && w.start <= s.to + 0.3)
const out: Finding[] = []
for (let i = 0; i < said.length; ) {
if (up(said[i])) { i++; continue }
@@ -312,13 +310,6 @@ export default check<FileFacts>(
const rate = own ? own.rate : sc!.rate || 2
const shown = captionsOf(frames, rate, heard)
const textUp = (t: number) => (frames[Math.round(t * rate)]?.lines ?? []).some(([, , , , text, score]) => score >= LEAST && letters(text).length >= 4)
// only the render's own texts say a word on screen: the footage's own (a sign, a phone) never caption anything
const onCard = (w: Word) => {
if (!own) return false
const k = letters(w.text)
const at = (t: number) => letters((frames[Math.round(t * rate)]?.lines ?? []).map((l) => l[4]).join(" "))
return k.length > 0 && [w.start, (w.start + w.end) / 2, w.end].some((t) => at(t).includes(k))
}
for (const x of [...uncaptioned(shown, heard, textUp, onCard), ...compare(shown, heard, own ? await placedWords(f) : [])].sort((a, b) => a.at - b.at)) found({ level: x.level, says: x.says, seconds: x.at })
for (const x of [...uncaptioned(shown, heard, textUp), ...compare(shown, heard, own ? await placedWords(f) : [])].sort((a, b) => a.at - b.at)) found({ level: x.level, says: x.says, seconds: x.at })
},
)
+14 -25
View File
@@ -6,9 +6,7 @@
// (no one reads it on a phone), under 48 px a warning.
// faces: frames two a second through the scene reader (raea cloud's farm). A face of a person in the shot (5% of the
// 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.
// warning. 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"
@@ -19,9 +17,6 @@ import { quote } from "../text.ts"
/** a face this share of the frame's height or more is someone in the shot, not a passer-by far behind */
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
/** 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
@@ -48,21 +43,17 @@ export function splitsOf(fr: NonNullable<Faces>): Split[] {
const near = (a: Split, b: Split) => a.axis === b.axis && Math.abs(a.at - b.at) <= 6
const big = (fr: NonNullable<Faces>) => 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<Faces>, splits: Split[]): { by: string; score: number } | null {
for (const [x, y, fw, fh, s] of big(fr)) {
const score = Number.isFinite(s) ? s : 1
const by =
x <= 1 ? "the left edge"
: x + fw >= fr.w - 1 ? "the right edge"
: y <= 1 ? "the top edge"
: y + fh >= fr.h - 1 ? "the bottom edge"
: splits.some((sp) => {
const [a, b] = sp.axis === "h" ? [y, y + fh] : [x, x + fw]
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 }
/** what cuts a face in a frame: an edge of the frame, or a split screen's seam */
function cutBy(fr: NonNullable<Faces>, splits: Split[]): string | null {
for (const [x, y, fw, fh] of big(fr)) {
if (x <= 1) return "the left edge"
if (x + fw >= fr.w - 1) return "the right edge"
if (y <= 1) return "the top edge"
if (y + fh >= fr.h - 1) return "the bottom edge"
for (const sp of splits) {
const [a, b] = sp.axis === "h" ? [y, y + fh] : [x, x + fw]
if ((a < sp.at - 2 && b > sp.at + 2) || Math.abs(b - sp.at) <= 3 || Math.abs(a - sp.at) <= 3) return "the split screen's seam"
}
}
return null
}
@@ -92,12 +83,10 @@ export function cutFaces(frames: Faces[], rate = RATE): Finding[] {
const held = raw.map((ss, i) => ss.filter((s) => (raw[i - 1] ?? []).some((o) => near(s, o)) || (raw[i + 1] ?? []).some((o) => near(s, o))))
const out: Finding[] = []
const hits = frames.map((fr, i) => (fr ? cutBy(fr, held[i]) : null))
for (const [i, j, { by }] of runs(hits, (a, b) => a.by === b.by)) {
for (const [i, j, by] of runs(hits)) {
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)` : ""
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"}` })
out.push({ level: to - from >= 1 ? "error" : "warn", kind: "face-cut", at: from, until: to, says: `a face 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)
for (const [i, j, sp] of runs(split, near)) {
+1 -7
View File
@@ -36,8 +36,6 @@ const SUBJECT_MIN = 0.25
const FACE_IN_SHOT = 0.05
/** a thing this share of the frame's area or more is what the shot shows (a dog at someone's feet, a phone held up) */
const THING_MIN = 0.006
/** words in the shot are hidden (text over them an error) when a text covers this share of them or more */
export const SIGN_HIDDEN = 0.3
/** a text is badly placed when it costs this much or more, and a clear place costs this much less */
export const BAD = 1.6
export const BETTER = 1.2
@@ -125,11 +123,7 @@ function thingsUnder(s: NonNullable<Scene>, b: Box, ours: Box[] = []): string[]
const [x, y, w, h] = [t[0] / s.w, t[1] / s.h, t[2] / s.w, t[3] / s.h]
const ix = Math.max(0, Math.min(b[0] + b[2], x + w) - Math.max(b[0], x))
const iy = Math.max(0, Math.min(b[1] + b[3], y + h) - Math.max(b[1], y))
if (!(ix * iy > 0.12 * Math.min(w * h, b[2] * b[3]))) continue
// words in the shot are covered when a good part of them is hidden; a caption over a sign's top edge leaves them read
// (12-05, run 28: Dutch's "Would" and "this." sat on the edge of a handwritten sign, its words all clear)
if (t[4] === "text") out.add(ix * iy >= SIGN_HIDDEN * w * h ? "words in the shot (a sign)" : "the edge of a sign")
else out.add(t[4] === "person" ? "a person in the shot" : t[4] === "face" ? "a face" : `a ${t[4].replace(/_/g, " ")}`)
if (ix * iy > 0.12 * Math.min(w * h, b[2] * b[3])) out.add(t[4] === "person" ? "a person in the shot" : t[4] === "face" ? "a face" : t[4] === "text" ? "words in the shot (a sign)" : `a ${t[4].replace(/_/g, " ")}`)
}
return [...out]
}
-3
View File
@@ -90,9 +90,6 @@ test("captions are a must: a cut that talks with only a text hook up fails, a ba
expect(uncaptioned(captionsOf(hookThenCaps, 2, said), said, hookUp)).toEqual([])
// text up all through doesn't stand in for captions after the opening
expect(uncaptioned(track, said, () => true).map((x) => x.level)).toEqual(["error"])
// the bare stretch said on an end card the render drew (12-05, run 28's Elfster): the card says it, nothing more
const card = new Set(said.filter((w) => w.start >= 7).map((w) => w.text))
expect(uncaptioned(track, said, () => false, (w) => card.has(w.text))).toEqual([])
// a cut with hardly any talking needs none
expect(uncaptioned([], said.slice(0, 4))).toEqual([])
})
-4
View File
@@ -11,10 +11,6 @@ test("the frames pack's measures", () => {
let f = cutFaces([fr([whole]), fr([edge]), fr([edge]), fr([whole]), fr([edge]), fr([[0, 50, 10, 12, 0.9]])])
assert.deepEqual(f.map((x) => [x.level, x.at, x.until]), [["error", 0.5, 1.5], ["warn", 2, 2.5]])
assert.match(f[0].says, /left edge/)
// a hand at the edge the reader half takes for a face (12-05, run 28: 0.79 then 0.65): a warning that says so
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/)
// 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]])), [])
-7
View File
@@ -41,13 +41,6 @@ test("the place pack's model", async () => {
assert.ok(pa.places[0].top < 400, JSON.stringify(pa.places[0]))
ok("raea make place keeps a caption off the sign in the shot")
// a caption over a sign's top edge, its words all read, is a warning (12-05, run 28's Dutch: "Would" and "this." on
// the edge of a handwritten sign): 30% of the words' box hidden makes it "words in the shot", an error
const signed = { w: 540, h: 960, grid: { cols: 27, rows: 48, people: Array(48).fill("0".repeat(27)) }, faces: [], things: [[60, 520, 420, 70, "text", 0.95], [60, 600, 420, 70, "text", 0.95]] }
const onEdge = textOver(man([t("Would", 400, 950, 280, 110)]), [signed], 1)
assert.ok(onEdge.every((x) => x.level === "warn" && /the edge of a sign/.test(x.says)), JSON.stringify(onEdge))
ok("a caption over a sign's edge is a warning")
// b: a woman filling the frame; a caption over her coat is at most a warning
const b = textOver(man([t("Did you know you", 272, 1344, 536, 88)]), [sc.b], 1)
assert.ok(b.every((x) => x.level === "warn"), JSON.stringify(b))