Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 709a7f6113f8877cda1af911972444a63fa75312
parent 6cfc7f34858376399c14f5fc7b786a25e6cc4d3e
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri, 13 Nov 2026 22:28:35 -0500

clip kit E: hidden regions -- a recording's chat overlay, other accounts on screen

render.censor ([{video, channel?, boxes, style?, strength?, from?, to?}], report-to-video
clip-censor.mjs) hides the same boxes on every clip cut from one recording; a clip's own
`censor` adds boxes (false: none, not even its recording's). A box is [x, y, w, h] of the
source picture or {box, from, to} over a span; blurred, black or pixelated with the post
censor's strengths. Drawn on the source picture first -- before the blur, the zooms and
any framing -- in every clip path (a cut with or without the deck, a short, a desktop
clip, Make a short); on in the uncensored variant (privacy, not TOS). The cut record
names what was hidden.

`umtool censor <p> --video <id> [--channel] --box x,y,w,h[@from-to] … [--style]
[--strength] [--from] [--to] | --clear | --list` (render.censor through the look's
writer); `umtool set <p> <clip> censor.boxes=… censor.style=… censor=false`; the clip
editor's Hide regions (the box in %, every clip of this recording or this clip, the
style, from/to the playhead; op censor-recording). Validated by the writers, the lint and
the build. Another recording's boxes, or none: the segment byte for byte as before
(render test).

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/lib/report/look.d.mts | 2+-
Mcommon/lib/report/look.mjs | 2+-
Mcommon/lib/report/videoAssistOps.test.ts | 2+-
Meditor/CHANGELOG.md | 9+++++++++
Mumtool/bin/umtool.mjs | 2++
Mumtool/components/projects/review/ClipEditor.tsx | 107+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Mumtool/docs/cli.md | 1+
Mumtool/docs/knobs.md | 28++++++++++++++++++++++++++++
Mumtool/e2e/clip-kit.spec.ts | 15+++++++++++++++
Mumtool/lib/cli/groups.mjs | 10++++++++++
Mumtool/lib/cli/verbs.mjs | 5+++++
Aumtool/lib/report/censorCli.mjs | 104+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/clipEditor.mjs | 20+++++++++++++++++++-
Mumtool/lib/report/clipEditorTypes.ts | 8+++++++-
Mumtool/lib/report/clipKit.test.mjs | 30+++++++++++++++++++++++++++++-
Mumtool/lib/report/knobsCli.mjs | 7++++++-
Mumtool/lib/report/look.test.mjs | 2+-
Mumtool/lib/report/manifest.mjs | 3+++
Mumtool/lib/report/shortsBatch.test.mjs | 4++--
Mumtool/report-to-video/build-video.mjs | 32++++++++++++++++++++++++++------
Aumtool/report-to-video/clip-censor.mjs | 164+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/clip-censor.test.mjs | 58++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/clip-kit-render.test.mjs | 43+++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/clip-kit.mjs | 9++++++---
Mumtool/report-to-video/clip-kit.test.mjs | 2+-
Mumtool/report-to-video/lint.mjs | 3++-
Mumtool/report-to-video/package.json | 1+
Mumtool/report-to-video/vertical-plan.mjs | 2+-
28 files changed, 651 insertions(+), 24 deletions(-)

diff --git a/common/lib/report/look.d.mts b/common/lib/report/look.d.mts @@ -4,7 +4,7 @@ type Manifest = { render?: Record<string, unknown> | null; timeline?: unknown[] } & Record<string, unknown>; type Render = Record<string, unknown> | null | undefined; -export type LookKey = "headerHeight" | "footerHeight" | "qr" | "transition" | "transitionStyle" | "loudness" | "captions" | "room" | "slide" | "blur" | "intro" | "format" | "vertical" | "mode" | "basic" | "tallWindows" | "desktop" | "promo" | "zooms"; +export type LookKey = "headerHeight" | "footerHeight" | "qr" | "transition" | "transitionStyle" | "loudness" | "captions" | "room" | "slide" | "blur" | "intro" | "format" | "vertical" | "mode" | "basic" | "tallWindows" | "desktop" | "promo" | "zooms" | "censor"; export const LOOK_KEYS: readonly LookKey[]; export const QR_CORNERS: readonly ["br", "bl", "tr", "tl"]; export const QR_LINK_VALUES: readonly ["cite", "moment", "channel"]; diff --git a/common/lib/report/look.mjs b/common/lib/report/look.mjs @@ -29,7 +29,7 @@ const round2 = (n) => Number(Number(n).toFixed(2)); /** The corner code's corners and links (lane clip-kit; umtool report-to-video clip-kit.mjs draws them). */ export const QR_CORNERS = Object.freeze(["br", "bl", "tr", "tl"]); export const QR_LINK_VALUES = Object.freeze(["cite", "moment", "channel"]); -export const LOOK_KEYS = Object.freeze(["headerHeight", "footerHeight", "qr", "transition", "transitionStyle", "loudness", "captions", "room", "slide", "blur", "intro", "format", "vertical", "mode", "basic", "tallWindows", "desktop", "promo", "zooms"]); +export const LOOK_KEYS = Object.freeze(["headerHeight", "footerHeight", "qr", "transition", "transitionStyle", "loudness", "captions", "room", "slide", "blur", "intro", "format", "vertical", "mode", "basic", "tallWindows", "desktop", "promo", "zooms", "censor"]); /** `headerHeight` / `footerHeight`: whole pixels, 0 (off) to this. */ export const BAND_MAX = 240; diff --git a/common/lib/report/videoAssistOps.test.ts b/common/lib/report/videoAssistOps.test.ts @@ -26,7 +26,7 @@ test("the look's rules: one patch function — keys refused, null removes, qr on assert.deepEqual(bad.errors, validateTransitionStyle({ render: { slide: { blur: 9 } } })); assert.deepEqual(applyLookPatch(m, { loudness: { target: -40 } }).errors, validateLook({ render: { loudness: { target: -40 } } })); assert.deepEqual(lookErrors(m), []); - assert.equal(LOOK_KEYS.length, 19); + assert.equal(LOOK_KEYS.length, 20); }); test("render.mode and render.basic: deck is the default (no key), basic the footage alone; the fades checked", () => { diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md @@ -1,6 +1,15 @@ # Changelog ## [Unreleased] +- **umtool: parts of a recording's picture can be hidden on every clip of it.** This covers things like a stream + layout's chat overlay or a window showing other people's accounts. + - `render.censor` (`umtool censor <p> --video <id> --box x,y,w,h[@from-to]`, or the clip editor's + **Hide regions**) blurs, blacks out or pixelates the same boxes on every clip of that recording. A box can be + limited to a span of the clip. + - A clip's own `censor` adds boxes for that clip; `censor=false` turns its recording's off. + - The boxes are applied to the source picture first, in every kind of build (a cut, a short, a desktop clip, Make a + short), and they stay on in the uncensored variant. + - Without the keys the segments are unchanged. - **umtool: a short or a desktop clip can open on its payoff.** A clip's `coldOpen` (`{from, to}`, 1–4 s of its cut) plays first, then the short cuts hard to the clip's start. - The cold open has its own captions and sound, the hook band, no code and no card. The channel promo still ends diff --git a/umtool/bin/umtool.mjs b/umtool/bin/umtool.mjs @@ -957,6 +957,8 @@ const COMMANDS = { // A batch of shorts: a take's clips in each format, into shorts-<take>/ (lane clip-kit): lib/report/shortsCli.mjs. shorts: async () => process.exit(await (await import("../lib/report/shortsCli.mjs")).shortsCommand(argv.slice(argv.indexOf("shorts") + 1))), // The channel promo's portrait from a clip, and its card drawn to look at (lane clip-kit): lib/report/promoCli.mjs. + // The regions hidden on every clip of one recording (lane clip-kit): lib/report/censorCli.mjs. + censor: async () => process.exit(await (await import("../lib/report/censorCli.mjs")).censorCommand(argv.slice(argv.indexOf("censor") + 1))), promo: async () => process.exit(await (await import("../lib/report/promoCli.mjs")).promoCommand(argv.slice(argv.indexOf("promo") + 1))), // Quick clip (lane output-modes): one moment to a basic-mode mp4 and its share line: lib/report/quickClip.mjs. clip: async () => process.exit(await (await import("../lib/report/quickClip.mjs")).quickClipCommand(argv.slice(argv.indexOf("clip") + 1))), diff --git a/umtool/components/projects/review/ClipEditor.tsx b/umtool/components/projects/review/ClipEditor.tsx @@ -890,7 +890,7 @@ export default function ClipEditor({ {view.reactionsError && <p className="m-0 text-[12px] text-reject-text">{view.reactionsError}</p>} {view.rulingsError && <p className="m-0 text-[12px] text-reject-text">{view.rulingsError}</p>} - <ShortMaker project={project} clipId={clip.id} short={view.shorts?.[clip.id] ?? null} framed={!!clip.vertical} framing={framing} onFraming={setFraming} onCentre={() => setCrop(null)} onMade={() => void reload().catch(() => {})} busy={busy} live={view.live?.status === "live"} kit={clip.kit ?? {}} onKit={(patch, done) => void write({ op: "kit", clip: clip.id, kit: patch }, done)} playhead={playhead} selection={selection} cut={cut} /> + <ShortMaker project={project} clipId={clip.id} short={view.shorts?.[clip.id] ?? null} framed={!!clip.vertical} framing={framing} onFraming={setFraming} onCentre={() => setCrop(null)} onMade={() => void reload().catch(() => {})} busy={busy} live={view.live?.status === "live"} kit={clip.kit ?? {}} onKit={(patch, done) => void write({ op: "kit", clip: clip.id, kit: patch }, done)} playhead={playhead} selection={selection} cut={cut} recordingCensor={clip.recordingCensor ?? []} onRecordingCensor={(censor, done) => void write({ op: "censor-recording", clip: clip.id, censor }, done)} /> <RenderTake project={project} render={render} takes={takes} takesHref={takesHref} /> </aside> </div> @@ -1591,7 +1591,7 @@ function SpeakerLabel({ speaker, busy, onSave }: { speaker: Speaker; busy: boole } /** Make a short: the clip at 1080x1920 from its box, a job; the one there is set aside, never overwritten. */ -function ShortMaker({ project, clipId, short, framed, framing, onFraming, onCentre, onMade, busy, live = false, kit = {}, onKit, playhead = null, selection = null, cut = null }: { +function ShortMaker({ project, clipId, short, framed, framing, onFraming, onCentre, onMade, busy, live = false, kit = {}, onKit, playhead = null, selection = null, cut = null, recordingCensor = [], onRecordingCensor }: { project: string; clipId: string; short: { mtimeMs: number; size: number; stale: boolean } | null; @@ -1612,6 +1612,9 @@ function ShortMaker({ project, clipId, short, framed, framing, onFraming, onCent // The strip's selection and the clip's cut: a cold open is a span of the cut (lane clip-kit, slice G). selection?: { cutStart: number; cutEnd: number } | null; cut?: { cutStart: number; cutEnd: number } | null; + // Hidden regions (lane clip-kit, slice E): the recording's, and their writer (op "censor-recording"). + recordingCensor?: NonNullable<EditorClip["recordingCensor"]>; + onRecordingCensor?: (censor: Record<string, unknown> | null, done: string) => void; }) { const [job, setJob] = useState<{ id: string; state: string; error: string | null } | null>(null); const [err, setErr] = useState<string | null>(null); @@ -1734,6 +1737,9 @@ function ShortMaker({ project, clipId, short, framed, framing, onFraming, onCent {onKit && ( <ColdOpen clipId={clipId} coldOpen={kit.coldOpen && typeof kit.coldOpen === "object" ? (kit.coldOpen as { from: number; to: number }) : null} selection={selection} cut={cut} busy={busy} onKit={onKit} /> )} + {onKit && onRecordingCensor && ( + <HideRegions clipId={clipId} own={kit.censor ?? null} recording={recordingCensor[0] ?? null} playhead={playhead} busy={busy} onKit={onKit} onRecording={onRecordingCensor} /> + )} {onKit && <ZoomList clipId={clipId} zooms={Array.isArray(kit.zooms) ? (kit.zooms as Zoom[]) : []} playhead={playhead} busy={busy} onKit={onKit} />} {job && ( <p data-short-job={job.state} className="m-0 text-[12px] text-text-2"> @@ -1783,6 +1789,103 @@ function ColdOpen({ clipId, coldOpen, selection, cut, busy, onKit }: { clipId: s ); } +// --------------------------------------------------------------------------- +// Hidden regions (lane clip-kit, report-to-video clip-censor.mjs): a box of the source picture (percent), hidden on +// every clip of this recording (a chat overlay, a window with other accounts) or on this clip alone -- blurred, black +// or pixelated, for the whole clip or from / to the playhead. Privacy: on in the uncensored variant too. +// --------------------------------------------------------------------------- + +type CensorSetUi = NonNullable<EditorClip["recordingCensor"]>[number]; +const boxOf = (b: unknown): number[] | null => (Array.isArray(b) ? (b as number[]) : b && typeof b === "object" && Array.isArray((b as { box?: number[] }).box) ? (b as { box: number[] }).box : null); +const pct = (n: number) => Math.round(n * 1000) / 10; + +function HideRegions({ clipId, own, recording, playhead, busy, onKit, onRecording }: { + clipId: string; + own: unknown; + recording: CensorSetUi | null; + playhead: number | null; + busy: boolean; + onKit: (patch: Record<string, unknown>, done: string) => void; + onRecording: (censor: Record<string, unknown> | null, done: string) => void; +}) { + const [box, setBox] = useState(["70", "0", "30", "100"]); + const [scope, setScope] = useState<"recording" | "clip">("recording"); + const [style, setStyle] = useState("blur"); + const [from, setFrom] = useState<number | null>(null); + const [to, setTo] = useState<number | null>(null); + const ownSet = own && typeof own === "object" ? (own as { boxes?: unknown[]; style?: string }) : null; + const frac = box.map((v) => Number(v) / 100); + const ok = frac.every((n) => Number.isFinite(n) && n >= 0 && n <= 1) && frac[2] > 0.01 && frac[3] > 0.01 && frac[0] + frac[2] <= 1.0001 && frac[1] + frac[3] <= 1.0001; + const r3 = (n: number) => Math.round(n * 1000) / 1000; + const entry = (): number[] | { box: number[]; from?: number; to?: number } => { + const b = frac.map(r3); + return from !== null || to !== null ? { box: b, ...(from !== null ? { from } : {}), ...(to !== null ? { to } : {}) } : b; + }; + const add = () => { + if (scope === "recording") onRecording({ boxes: [...(recording?.boxes ?? []), entry()], style: recording?.style ?? style }, "Hidden on every clip of this recording"); + else onKit({ censor: { ...(ownSet ?? {}), boxes: [...(ownSet?.boxes ?? []), entry()], style: ownSet?.style ?? style } }, "Hidden on this clip"); + }; + const list = (boxes: unknown[], remove: (i: number) => void, tag: string) => + boxes.map((b, i) => { + const bx = boxOf(b); + const span = b && typeof b === "object" && !Array.isArray(b) ? (b as { from?: number; to?: number }) : null; + return ( + <li key={`${tag}${i}`} data-censor-row={`${tag}${i}`} className="flex items-center gap-1.5"> + <span> + {tag === "r" ? "recording" : "this clip"}: {bx ? bx.map(pct).join(", ") : "?"} %{span ? ` (${span.from ?? "start"}–${span.to ?? "end"} s)` : ""} + </span> + <button type="button" data-censor-remove={`${tag}${i}`} disabled={busy} onClick={() => remove(i)} className={buttonVariants({ variant: "quiet", size: "sm" })} aria-label="remove this region"> + × + </button> + </li> + ); + }); + return ( + <div className="space-y-1 text-[12px] text-text-2" data-kit-censor={clipId}> + <span>Hide regions</span> + <ul className="m-0 list-none space-y-0.5 p-0"> + {list(recording?.boxes ?? [], (i) => { + const rest = (recording?.boxes ?? []).filter((_, j) => j !== i); + onRecording(rest.length ? { ...recording, boxes: rest, video: undefined, channel: undefined } : null, "Took the region off the recording"); + }, "r")} + {list(ownSet?.boxes ?? [], (i) => { + const rest = (ownSet?.boxes ?? []).filter((_, j) => j !== i); + onKit({ censor: rest.length ? { ...ownSet, boxes: rest } : null }, "Took the region off this clip"); + }, "c")} + </ul> + <div className="flex flex-wrap items-center gap-1"> + {["x", "y", "w", "h"].map((k, i) => ( + <input key={k} data-censor-box={k} type="number" min={0} max={100} step={1} value={box[i]} disabled={busy} aria-label={`${k}, % of the picture`} onChange={(e) => setBox(box.map((v, j) => (j === i ? e.target.value : v)))} className="w-[4em] rounded-[3px] border border-seam-2 bg-transparent px-1 text-text" /> + ))} + % + <select data-censor-scope="" value={scope} disabled={busy} onChange={(e) => setScope(e.target.value as "recording" | "clip")} className="rounded-[3px] border border-seam-2 bg-transparent px-1 py-0.5 text-text"> + <option value="recording">every clip of this recording</option> + <option value="clip">this clip</option> + </select> + <select data-censor-style="" value={style} disabled={busy} onChange={(e) => setStyle(e.target.value)} className="rounded-[3px] border border-seam-2 bg-transparent px-1 py-0.5 text-text"> + <option value="blur">blurred</option> + <option value="black">black</option> + <option value="pixelate">pixelated</option> + </select> + <button type="button" data-censor-from="" disabled={busy || playhead === null} onClick={() => setFrom(playhead === null ? null : Math.round(playhead * 100) / 100)} className={buttonVariants({ variant: "quiet", size: "sm" })}> + {from === null ? "From playhead" : `from ${from} s`} + </button> + <button type="button" data-censor-to="" disabled={busy || playhead === null} onClick={() => setTo(playhead === null ? null : Math.round(playhead * 100) / 100)} className={buttonVariants({ variant: "quiet", size: "sm" })}> + {to === null ? "To playhead" : `to ${to} s`} + </button> + {(from !== null || to !== null) && ( + <button type="button" data-censor-whole="" disabled={busy} onClick={() => { setFrom(null); setTo(null); }} className={buttonVariants({ variant: "quiet", size: "sm" })}> + Whole clip + </button> + )} + <button type="button" data-censor-add={clipId} disabled={busy || !ok} onClick={add} className={buttonVariants({ variant: "outline", size: "sm" })}> + Hide it + </button> + </div> + </div> + ); +} + type Zoom = { at: number; scale?: number; hold?: number; focus?: [number, number]; box?: number[]; ramp?: number }; function ZoomList({ clipId, zooms, playhead, busy, onKit }: { clipId: string; zooms: Zoom[]; playhead: number | null; busy: boolean; onKit: (patch: Record<string, unknown>, done: string) => void }) { diff --git a/umtool/docs/cli.md b/umtool/docs/cli.md @@ -275,6 +275,7 @@ draft (the project's manifest); *project*: a project's other files, or reads; *c | `pool verify [--sample N] [--all]` | the render pool's files checked | form · queued · *corpus* | | `trailer <project> [--take TAKE] [--reel REEL] [--beats BEATS] [--beats-json JSON] [--intro] [--finale N] [--xfade N] [--no-snap] [--out OUT] [--dry-run] [--candidates] [--vertical] [--layout reframe]` | a trailer or beat reel cut from a take's master | form · queued · *project* | | `vertical <project> --take TAKE [--reel REEL] [--beats BEATS] [--items ITEMS] [--clip full\|framed\|quote] [--post card\|stack\|media] [--side split\|overlay] [--hook HOOK] [--captions l\|xl] [--lines 1\|2] [--loudness N] [--max N] [--name NAME] [--reframe] [--landscape] [--desktop] [--dry-run] [--intro] [--no-intro] [--no-outro] [--deck stacked\|bare] [--qr on\|off] [--qr-corner tr\|tl\|br\|bl] [--promo] [--no-promo] [--promo-lead N] [--promo-fade N] [--promo-hold N] [--no-cold-open]` | a vertical short (1080x1920) of a take's items | form · queued · *project* | +| `censor <project> [--video VIDEO] [--channel CHANNEL] [--box BOX…] [--style blur\|black\|pixelate] [--strength N] [--from N] [--to N] [--clear] [--list]` | the regions hidden on every clip of one recording (a chat overlay, other accounts) | form · *project* | | `promo <project> [--portrait-from PORTRAIT-FROM] [--box BOX] [--draw] [--take TAKE]` | the channel promo: its portrait from a clip at a second, its card drawn | form · *project* | | `shorts <project> --take TAKE [--items ITEMS] [--all] [--again] [--formats FORMATS] [--clip full\|framed\|quote] [--post card\|stack\|media] [--side split\|overlay] [--hook HOOK] [--captions l\|xl] [--lines 1\|2] [--loudness N] [--max-vertical N] [--max-landscape N] [--max-desktop N] [--deck stacked\|bare] [--qr on\|off] [--qr-corner tr\|tl\|br\|bl] [--no-promo] [--promo-lead N] [--promo-fade N] [--promo-hold N] [--no-cold-open] [--replace] [--dry-run]` | a batch of shorts: each clip of a take in each format, into shorts-<take>/ | form · queued · *project* | | `trailer-beats <project> ls [--reel REEL]` | a reel's beats against its limit | form · *project* | diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -508,6 +508,34 @@ span; this is the short's. | a clip's cold open | the clip editor's **Short**: select 1–4 s of the cut on the strip, **Cold open from selection**; **Clear** | `umtool set <p> <clip> coldOpen.from=… coldOpen.to=…` (`coldOpen=` none) | | without them | the ⌘K forms' **--no-cold-open** | `umtool vertical … --no-cold-open` · `umtool shorts … --no-cold-open` | +## Hidden regions (a chat overlay, other accounts on screen) + +A stream layout carries things a clip should not show: the chat overlay, a browser window with other people's accounts. +`render.censor` hides the same boxes on every clip cut from ONE recording; a clip's own `censor` adds boxes to it +(lane clip-kit; `report-to-video/clip-censor.mjs`, with the post censor's styles and strengths). A box is a fraction of +the SOURCE picture and may be limited to a span of the clip. + +- **Where:** on the source picture FIRST -- before the clip's blur, its zooms and any framing -- in every path a clip + is cut in: a cut with or without the deck, a short, a desktop clip, Make a short. So a box is the same part of the + recording whatever frames it. A montage re-cuts its pictures and draws none. +- **Privacy, not TOS:** it stays on in the uncensored variant (`render.blur: "off"`), as a post's censor does. No + caption is drawn. +- The cut record names what was hidden (`censor: [{box, style, strength?, from?, to?}]`). `--chrome-only` does not + re-cut segments: after changing a recording's boxes, build again. + +| Knob | Values (default) | What it does | +|---|---|---| +| `render.censor` | `[{video, channel?, boxes, style?, strength?, from?, to?}]`, ≤ 16 | the boxes hidden on every clip of that recording (`channel`: only that channel's; absent: any) | +| a clip's `censor` | `false` · `{boxes, style?, strength?, from?, to?}` | its own boxes, added; `false`: none, not even its recording's | +| `boxes` | 1–8 of `[x, y, w, h]` or `{box: [x, y, w, h], from?, to?}` | fractions of the source picture; a box's own `from`/`to` (source seconds) limit it to that span | +| `style`, `strength` | `blur` · `black` · `pixelate` (`blur`); 1–10 (7) | how it is hidden | +| `from`, `to` | source seconds | every box of the entry only over that span | + +| | In umtool | From a terminal | +|---|---|---| +| a recording's | the clip editor's **Short**: **Hide regions** -- the box (x, y, w, h in %), **every clip of this recording**, the style, **From playhead** / **To playhead**, **Hide it**; × takes one off | `umtool censor <p> --video <id> [--channel <slug>] --box x,y,w,h[@from-to] [--box …] [--style black]` · `--clear` · `--list` | +| one clip's | the same, **this clip** | `umtool set <p> <clip> censor.boxes='[[0.75,0,0.25,1]]' censor.style=pixelate` · `censor=false` · `censor=` | + ## A clip's QR: its corner and its link The corner code a cut with no deck draws on each clip (`render.qr`), and the code a short draws (`render.vertical.qr`), diff --git a/umtool/e2e/clip-kit.spec.ts b/umtool/e2e/clip-kit.spec.ts @@ -97,6 +97,21 @@ test("the clip editor: a clip's own QR corner, its end card off and back, the pr await expect.poll(() => clip("r001")?.zooms?.[0]?.scale).toBe(1.5); await page.locator("[data-zoom-remove='0']").click(); await expect.poll(() => clip("r001") && "zooms" in clip("r001")).toBe(false); + // Hidden regions (slice E): a box on every clip of this recording, taken off again; one on this clip alone. + await page.locator("[data-censor-box='x']").fill("75"); + await page.locator("[data-censor-box='y']").fill("0"); + await page.locator("[data-censor-box='w']").fill("25"); + await page.locator("[data-censor-box='h']").fill("100"); + await page.locator("[data-censor-style]").selectOption("black"); + await page.locator("[data-censor-add='r001']").click(); + await expect.poll(() => render().censor ?? null).toEqual([{ video: "vid1", boxes: [[0.75, 0, 0.25, 1]], style: "black" }]); + await page.locator("[data-censor-remove='r0']").click(); + await expect.poll(() => render().censor ?? null).toBe(null); + await page.locator("[data-censor-scope]").selectOption("clip"); + await page.locator("[data-censor-add='r001']").click(); + await expect.poll(() => clip("r001")?.censor ?? null).toEqual({ boxes: [[0.75, 0, 0.25, 1]], style: "black" }); + await page.locator("[data-censor-remove='c0']").click(); + await expect.poll(() => clip("r001") && "censor" in clip("r001")).toBe(false); // The portrait: the player ready, the playhead moved (l: 2 s on), the frame there grabbed into shots/. await expect(page.locator("[data-editor-player]")).toHaveAttribute("data-editor-player", /^(?!looking|none)/, { timeout: 20_000 }); if (!render().promo) test.skip(true, "the look test sets the promo first"); diff --git a/umtool/lib/cli/groups.mjs b/umtool/lib/cli/groups.mjs @@ -701,6 +701,16 @@ export const GROUPS = [ ], }, { + cmd: "censor", + usage: [ + " umtool censor <project> --video <id> [--channel <slug>] --box x,y,w,h[@from-to] [--box …] [--style blur|black|pixelate]", + " [--strength 1-10] [--from s] [--to s] | --clear | --list the same parts of the picture hidden on", + " every clip of one recording (render.censor: a chat overlay, a window with other accounts)", + ], + docs: [ + ], + }, + { cmd: "promo", usage: [ " umtool promo <project> [--portrait-from <clip>@<second>] [--box x,y,w,h] [--draw] [--take <t>] [--json]", diff --git a/umtool/lib/cli/verbs.mjs b/umtool/lib/cli/verbs.mjs @@ -328,6 +328,11 @@ export const VERBS = Object.freeze([ num("--promo-lead", { help: "s before the end the card comes up (4.5)" }), num("--promo-fade", { help: "s (0.7)" }), num("--promo-hold", { help: "s of silence on the card (1.5)" }), bool("--no-cold-open", "play the clips as cut, without their cold opens"), ], Q), + form("censor", "project", "the regions hidden on every clip of one recording (a chat overlay, other accounts)", [ + project(), opt("--video", { help: "the recording's id" }), opt("--channel", { help: "its channel (default: any)" }), + many("--box", { item: "string", help: "x,y,w,h or x,y,w,h@from-to, one per line" }), pick("--style", ["blur", "black", "pixelate"]), + num("--strength", { help: "1-10 (7)" }), num("--from", { help: "s" }), num("--to", { help: "s" }), bool("--clear", "this recording's regions removed"), bool("--list", "every recording's"), + ]), form("promo", "project", "the channel promo: its portrait from a clip at a second, its card drawn", [ project(), opt("--portrait-from", { help: "<clip>@<source second>" }), opt("--box", { help: "x,y,w,h: the circle's part of the frame" }), bool("--draw", "draw the card 9:16 and 16:9 into out/promo/"), takeOpt({ help: "draw it in this take's look" }), diff --git a/umtool/lib/report/censorCli.mjs b/umtool/lib/report/censorCli.mjs @@ -0,0 +1,104 @@ +// `umtool censor` (lane clip-kit, slice E): the boxes hidden on every clip cut from ONE recording -- a stream layout's +// chat overlay, a browser window showing other people's accounts -- written into `render.censor` (report-to-video +// clip-censor.mjs) through the look's writer. A clip's own boxes are `umtool set <p> <clip> censor.boxes=…`. +// +// umtool censor <project> --video <id> [--channel <slug>] --box x,y,w,h[@from-to] [--box …] +// [--style blur|black|pixelate] [--strength 1-10] [--from s] [--to s] [--json] +// umtool censor <project> --video <id> [--channel <slug>] --clear +// umtool censor <project> --list +import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs"; +import { kindMakesTakes } from "../projects/kinds.mjs"; +import { readManifest } from "../projects/report.mjs"; +import { manifestToken, updateRender } from "./manifest.mjs"; + +export const CENSOR_USAGE = [ + "usage: umtool censor <project> --video <id> [--channel <slug>] --box x,y,w,h[@from-to] [--box …]", + " [--style blur|black|pixelate] [--strength 1-10] [--from s] [--to s] [--json]", + " umtool censor <project> --video <id> [--channel <slug>] --clear", + " umtool censor <project> --list", + "", + "Hides the same parts of the picture on every clip cut from one recording (render.censor): fractions of the", + "source picture, each box for the whole clip or, with @from-to (source seconds), that span. Blurred (default),", + "black or pixelated; on in the uncensored variant too (privacy, not TOS). Given again for the same recording, the", + "boxes replace its boxes. A clip's own: `umtool set <p> <clip> censor.boxes='[[x,y,w,h]]'` (`censor=false` none).", +].join("\n"); + +class CliError extends Error {} + +/** `x,y,w,h` or `x,y,w,h@from-to`, read. */ +export function parseBox(text) { + const m = /^([0-9.]+),([0-9.]+),([0-9.]+),([0-9.]+)(?:@([0-9.]+)-([0-9.]+))?$/.exec(String(text ?? "").trim()); + if (!m) throw new CliError(`--box ${text}: x,y,w,h (fractions of the picture), or x,y,w,h@from-to (source seconds)`); + const box = m.slice(1, 5).map(Number); + return m[5] !== undefined ? { box, from: Number(m[5]), to: Number(m[6]) } : box; +} + +/** render.censor with one recording's boxes set (`entry`) or removed (null). */ +export function withRecording(list, { video, channel = null }, entry) { + const same = (r) => r?.video === video && (r.channel ?? null) === channel; + const rest = (Array.isArray(list) ? list : []).filter((r) => !same(r)); + return entry ? [...rest, entry] : rest; +} + +/** + * `umtool censor …` + * @param {string[]} args + * @param {{ reportsRoot?: string, log?: (s: string) => void, err?: (s: string) => void }} [o] + */ +export async function censorCommand(args, { reportsRoot = REPORTS_ROOT, log = console.log, err = console.error } = {}) { + try { + const flags = { "--box": [] }; + const pos = []; + for (let i = 0; i < args.length; i += 1) { + const a = args[i]; + if (["--video", "--channel", "--style", "--strength", "--from", "--to", "--box"].includes(a)) { + if (i + 1 >= args.length) throw new CliError(`${a} needs a value`); + if (a === "--box") flags["--box"].push(args[++i]); + else flags[a] = args[++i]; + } else if (["--clear", "--list", "--json", "--help"].includes(a)) flags[a] = true; + else if (a.startsWith("--")) throw new CliError(`unknown flag ${a}`); + else pos.push(a); + } + if (flags["--help"] || !pos.length) { + log(CENSOR_USAGE); + return flags["--help"] ? 0 : 2; + } + const r = await resolveProject(pos[0], reportsRoot); + if (r.ambiguous) throw new CliError(`"${pos[0]}" is the name of ${r.ambiguous.length} projects — pass its id`); + if (!r.project) throw new CliError(`no project matches "${pos[0]}"`); + if (!kindMakesTakes(r.project.kind)) throw new CliError(`${r.project.id} is a ${r.project.kind}, not a report video`); + const manifest = await readManifest(r.project.dir); + const now = Array.isArray(manifest?.render?.censor) ? manifest.render.censor : []; + if (flags["--list"]) { + log(flags["--json"] ? JSON.stringify(now, null, 2) : now.length ? now.map((e) => `${e.channel ? `${e.channel}/` : ""}${e.video}: ${e.boxes.length} box(es), ${e.style ?? "blur"}`).join("\n") : "no recording's regions are hidden (render.censor)"); + return 0; + } + const video = typeof flags["--video"] === "string" ? flags["--video"].trim() : ""; + if (!video) throw new CliError("--video <id>: the recording whose clips hide the boxes"); + const channel = typeof flags["--channel"] === "string" ? flags["--channel"].trim() : null; + let entry = null; + if (!flags["--clear"]) { + if (!flags["--box"].length) throw new CliError("--box x,y,w,h (one or more), or --clear"); + const num = (k) => (flags[k] !== undefined ? Number(flags[k]) : undefined); + entry = { + video, ...(channel ? { channel } : {}), boxes: flags["--box"].map(parseBox), + ...(flags["--style"] ? { style: flags["--style"] } : {}), + ...(num("--strength") !== undefined ? { strength: num("--strength") } : {}), + ...(num("--from") !== undefined ? { from: num("--from") } : {}), + ...(num("--to") !== undefined ? { to: num("--to") } : {}), + }; + } + const next = withRecording(now, { video, channel }, entry); + const w = await updateRender(r.project.dir, { censor: next.length ? next : null }, { token: await manifestToken(r.project.dir) }); + const written = w.look.censor ?? []; + if (flags["--json"]) log(JSON.stringify(written, null, 2)); + else log(entry ? `${channel ? `${channel}/` : ""}${video}: ${entry.boxes.length} box(es) hidden on every clip of it (${entry.style ?? "blur"})` : `${video}: no regions hidden`); + return 0; + } catch (e) { + if (e instanceof CliError || e?.name === "RenderRefused") { + err(`umtool censor: ${e instanceof Error ? e.message : e}`); + return 2; + } + throw e; + } +} diff --git a/umtool/lib/report/clipEditor.mjs b/umtool/lib/report/clipEditor.mjs @@ -40,7 +40,10 @@ import { updateMarks, updateClip, updateOnscreen, + updateRender, } from "./manifest.mjs"; +import { namesClip } from "umtool-report-to-video/clip-censor"; +import { withRecording } from "./censorCli.mjs"; import { CLAIM_KNOB_DEFAULTS, markVerdictsOf, rawMarksOf, stampingEntryId } from "./knobs.mjs"; import { resolveFactcheck } from "umtool-report-to-video/factcheck"; import { momentKeysOf, readRulingsState, setMontageRuling } from "./montageRulings.mjs"; @@ -130,6 +133,8 @@ export async function clipEditorView(project) { vertical: isObj(e.vertical) && Array.isArray(e.vertical.crop) ? { crop: e.vertical.crop, ...(fin(e.vertical.aspect) ? { aspect: e.vertical.aspect } : {}) } : null, // The clip kit (lane clip-kit): its own code and name for a per-clip build, as written. kit: Object.fromEntries(CLIP_KIT_KEYS.filter((k) => e[k] !== undefined).map((k) => [k, e[k]])), + // Its recording's hidden regions (render.censor naming its video), for the Hide regions list. + recordingCensor: (Array.isArray(manifest.render?.censor) ? manifest.render.censor : []).filter((r) => namesClip(r, e, manifest.provenance ?? {})), // Room at its edges (release 36 lane E): the clip's own override as // written, and the edges it gets with the cut's render.room. room: e.room === false ? false : isObj(e.room) ? e.room : null, @@ -577,6 +582,19 @@ export async function runClipEditorOp(project, body, { now = null } = {}) { structural = false; break; } + case "censor-recording": { + // The regions hidden on every clip of THIS clip's recording (render.censor; clip-censor.mjs), through the + // look's writer and its checks: `censor` {boxes, style?, strength?} sets them, null removes them. + const e = needClip(); + if (body.censor !== null && !isObj(body.censor)) throw new OpError("censor is {boxes, style?, strength?}, or null for none"); + const m = await readManifest(dir); + const key = { video: e.video, channel: null }; + const next = withRecording(m?.render?.censor, key, body.censor ? { video: e.video, ...body.censor } : null); + const w = await updateRender(dir, { censor: next.length ? next : null }, { token }); + result = { censor: w.look.censor ?? null }; + structural = false; + break; + } case "room": { const e = needClip(); if (body.room !== null && body.room !== false && !isObj(body.room)) throw new OpError("room is false, {tail?, head?}, or null for the cut's"); @@ -632,7 +650,7 @@ export async function runClipEditorOp(project, body, { now = null } = {}) { break; } default: - throw new OpError("op must be trim, restore, split, merge, flash-forward, add, bring-in, ruling, role, label, vertical, kit, room, claim, marks, audio, blur or onscreen"); + throw new OpError("op must be trim, restore, split, merge, flash-forward, add, bring-in, ruling, role, label, vertical, kit, censor-recording, room, claim, marks, audio, blur or onscreen"); } let carried = null; if (structural) { diff --git a/umtool/lib/report/clipEditorTypes.ts b/umtool/lib/report/clipEditorTypes.ts @@ -30,7 +30,9 @@ export type EditorClip = { /** A short's framing (release 36): `crop` = [x, y, w, h], fractions of the source picture. */ vertical: { crop: number[]; aspect?: number } | null; /** The clip kit (lane clip-kit): its own code (`qr`: false or {corner?, links?}) and batch `name`, as written. */ - kit?: { qr?: false | { corner?: string; links?: string }; name?: string; promo?: false | { lead?: number; fade?: number; hold?: number }; zooms?: unknown[]; coldOpen?: { from: number; to: number }; [k: string]: unknown }; + kit?: { qr?: false | { corner?: string; links?: string }; name?: string; promo?: false | { lead?: number; fade?: number; hold?: number }; zooms?: unknown[]; coldOpen?: { from: number; to: number }; censor?: false | CensorSet; [k: string]: unknown }; + /** Its recording's hidden regions (render.censor naming its video). */ + recordingCensor?: Array<CensorSet & { video: string; channel?: string }>; /** Room at its edges (release 36 lane E): the clip's own `room` as written (false: none), and the edges it gets. */ room?: false | { tail?: boolean; head?: boolean } | null; roomEdges?: { tail: boolean; head: boolean } | null; @@ -124,3 +126,7 @@ export type Neighbourhood = { /** The take "Render a take" makes again (the clip deck's rule), or null: the Takes page chooses. */ export type RenderTarget = { take: string; label: string; builtAt: string | null; why: "latest" | "picked" | "whole cut" } | null; + +/** Hidden regions (report-to-video clip-censor.mjs): boxes as fractions of the source picture, each maybe over a span. */ +export type CensorBox = number[] | { box: number[]; from?: number; to?: number }; +export type CensorSet = { boxes: CensorBox[]; style?: "blur" | "black" | "pixelate"; strength?: number; from?: number; to?: number }; diff --git a/umtool/lib/report/clipKit.test.mjs b/umtool/lib/report/clipKit.test.mjs @@ -1,7 +1,7 @@ // The clip kit's keys written (lane clip-kit): `umtool set`'s and the clip editor's writer (manifest.mjs updateClip) // takes a clip's `qr` (whole or one field) and its batch `name`, refuses what the build would, and clears with null. import assert from "node:assert/strict"; -import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; +import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; @@ -101,3 +101,31 @@ test("a clip's cold open written: both fields in one patch, inside its cut, 1-4 await rm(dir, { recursive: true, force: true }); } }); + +import { censorCommand } from "./censorCli.mjs"; + +test("hidden regions written: a clip's own (dotted fields), a recording's through umtool censor; refused in the build's words", async () => { + const root = await mkdtemp(path.join(tmpdir(), "umtool-censor-")); + const dir = path.join(root, "reports", "proj"); + try { + await mkdir(dir, { recursive: true }); + await writeFile(path.join(dir, MANIFEST_NAME), JSON.stringify(manifest(), null, 2) + "\n"); + await updateClip(dir, "w01", { "censor.boxes": [[0, 0, 0.2, 0.2]], "censor.style": "black" }); + assert.deepEqual((await read(dir)).censor, { boxes: [[0, 0, 0.2, 0.2]], style: "black" }); + await assert.rejects(updateClip(dir, "w01", { "censor.style": "smudge" }), /censor\.style is one of blur, black, pixelate/); + await updateClip(dir, "w01", { censor: false }); + assert.equal((await read(dir)).censor, false); + const out = []; + const code = await censorCommand(["proj", "--video", "01a1d292-6d30", "--box", "0.75,0,0.25,1", "--box", "0,0.6,0.3,0.4@12-14", "--style", "pixelate"], { reportsRoot: path.join(root, "reports"), log: (s) => out.push(s), err: (s) => out.push(s) }); + assert.equal(code, 0, out.join("\n")); + const m = JSON.parse(await readFile(path.join(dir, MANIFEST_NAME), "utf8")); + assert.deepEqual(m.render.censor, [{ video: "01a1d292-6d30", boxes: [[0.75, 0, 0.25, 1], { box: [0, 0.6, 0.3, 0.4], from: 12, to: 14 }], style: "pixelate" }]); + const bad = []; + assert.equal(await censorCommand(["proj", "--video", "x", "--box", "0.9,0,0.3,1"], { reportsRoot: path.join(root, "reports"), log: () => {}, err: (s) => bad.push(s) }), 2); + assert.match(bad.join(), /boxes\[0\] is \[x, y, w, h\]/); + assert.equal(await censorCommand(["proj", "--video", "01a1d292-6d30", "--clear"], { reportsRoot: path.join(root, "reports"), log: () => {}, err: () => {} }), 0); + assert.equal(JSON.parse(await readFile(path.join(dir, MANIFEST_NAME), "utf8")).render.censor, undefined); + } finally { + await rm(root, { recursive: true, force: true }); + } +}); diff --git a/umtool/lib/report/knobsCli.mjs b/umtool/lib/report/knobsCli.mjs @@ -58,7 +58,7 @@ const GAP_KEYS = ["gaps", "gap.add", "gap.remove"]; export const VERTICAL_SET_KEYS = Object.freeze(["vertical", "vertical.crop", "vertical.layout", "vertical.aspect", "vertical.crops"]); export const SIDE_SET_KEYS = Object.freeze(["side", "side.item", "side.post", "side.from", "side.to", "side.place"]); /** The clip kit (lane clip-kit; report-to-video clip-kit.mjs): a clip's code in a per-clip build, its batch file name. */ -export const KIT_SET_KEYS = Object.freeze(["qr", "qr.corner", "qr.links", "name", "promo", "promo.lead", "promo.fade", "promo.hold", "zooms", "coldOpen", "coldOpen.from", "coldOpen.to"]); +export const KIT_SET_KEYS = Object.freeze(["qr", "qr.corner", "qr.links", "name", "promo", "promo.lead", "promo.fade", "promo.hold", "zooms", "coldOpen", "coldOpen.from", "coldOpen.to", "censor", "censor.boxes", "censor.style", "censor.strength", "censor.from", "censor.to"]); const SET_KEYS = [ "claim", ...CLAIM_KNOBS.map((k) => `claim.${k}`), ...MARK_KEYS, ...AUDIO_KNOBS.map((k) => `audio.${k}`), ...BLUR_KNOBS.map((k) => `blur.${k}`), "layout", ...REVIEW_KEYS, ...FX_KEYS, ...GAP_KEYS, "chat", "hideModules", "shelfNote", "chapter", @@ -128,6 +128,9 @@ export const SET_USAGE = [ " picture in at those source seconds (or \"box\":[x,y,w,h] to fill the frame with); `zooms=` none.", " coldOpen.from=… coldOpen.to=… (source seconds of its cut, 1-4 s): a short or a desktop clip plays that payoff", " first, then cuts to the clip's start; `coldOpen=` none.", + " censor.boxes='[[x,y,w,h]]' hides those parts of its picture (fractions of the source; a box may be", + " {\"box\":[…],\"from\":s,\"to\":s}); censor.style=blur|black|pixelate, censor.strength=1-10, censor.from/to;", + " censor=false: none, not even its recording's (`umtool censor` sets a recording's); `censor=` its recording's.", " gap.add=12.3-15.1 cuts those source seconds out of the clip's middle (one segment of jump cuts; inside", " the cut, ≥ 0.2 s, 0.5 s kept between); gap.remove=<sec> the gap holding it; gaps=12.3-15.1,20-20.6 (or", " a JSON list of {from,to}) the whole list, `gaps=` none. The same as `umtool window --gap/--gap-remove/--gaps`.", @@ -372,6 +375,7 @@ export async function setCommand(args, { root = REPORTS_ROOT, out = (s) => conso if ("name" in entryPatch) results.name = result.entry.name ?? null; if (["promo", "promo.lead", "promo.fade", "promo.hold"].some((k) => k in entryPatch)) results.promo = result.entry.promo ?? null; if ("zooms" in entryPatch) results.zooms = result.entry.zooms ?? null; + if (Object.keys(entryPatch).some((k) => k === "censor" || k.startsWith("censor."))) results.censor = result.entry.censor ?? null; if (["coldOpen", "coldOpen.from", "coldOpen.to"].some((k) => k in entryPatch)) results.coldOpen = result.entry.coldOpen ?? null; if (FX_KEYS.some((k) => k in entryPatch)) results.fx = result.entry.fx ?? null; if ("gaps" in entryPatch || "gapAdd" in entryPatch || "gapRemove" in entryPatch) { @@ -411,6 +415,7 @@ export async function setCommand(args, { root = REPORTS_ROOT, out = (s) => conso if ("vertical" in results) out(`${clipId}: vertical ${results.vertical ? JSON.stringify(results.vertical) : "the cut's (the centred crop)"}`); if ("side" in results) out(`${clipId}: side ${results.side ? JSON.stringify({ ...results.side, ...(results.side.post ? { post: `@${results.side.post.handle ?? results.side.post.author}` } : {}) }) : "none"}`); if ("qr" in results) out(`${clipId}: qr ${results.qr === false ? "none on this clip" : results.qr ? JSON.stringify(results.qr) : "the cut's"}`); + if ("censor" in results) out(`${clipId}: censor ${results.censor === false ? "none (not even its recording's)" : results.censor ? JSON.stringify(results.censor) : "its recording's (render.censor)"}`); if ("coldOpen" in results) out(`${clipId}: cold open ${results.coldOpen ? `${results.coldOpen.from}–${results.coldOpen.to} s, played first` : "none"}`); if ("zooms" in results) out(`${clipId}: zooms ${results.zooms ? results.zooms.map((z) => `${z.at} s ×${z.scale ?? (z.box ? "box" : 1.3)}`).join(", ") : "none"}`); if ("promo" in results) out(`${clipId}: promo ${results.promo === false ? "none (it ends without the card)" : results.promo ? JSON.stringify(results.promo) : "the cut's"}`); diff --git a/umtool/lib/report/look.test.mjs b/umtool/lib/report/look.test.mjs @@ -46,7 +46,7 @@ const read = async (dir) => JSON.parse(await readFile(path.join(dir, MANIFEST_NA test("updateRender: the look's keys only, null removes one, the build's checks refuse a bad value", async () => { const p = await project({ transition: 0.4, crf: 21 }); try { - assert.deepEqual(LOOK_KEYS, ["headerHeight", "footerHeight", "qr", "transition", "transitionStyle", "loudness", "captions", "room", "slide", "blur", "intro", "format", "vertical", "mode", "basic", "tallWindows", "desktop", "promo", "zooms"]); + assert.deepEqual(LOOK_KEYS, ["headerHeight", "footerHeight", "qr", "transition", "transitionStyle", "loudness", "captions", "room", "slide", "blur", "intro", "format", "vertical", "mode", "basic", "tallWindows", "desktop", "promo", "zooms", "censor"]); const token = await manifestToken(p.dir); const r = await updateRender(p.dir, { headerHeight: 0, footerHeight: 0, qr: false, transition: 0.5, transitionStyle: "fadeblack", diff --git a/umtool/lib/report/manifest.mjs b/umtool/lib/report/manifest.mjs @@ -41,6 +41,7 @@ import { verticalErrors } from "umtool-report-to-video/look"; import { CLIP_KIT_KEYS, clipKitErrors, validateClipKit } from "umtool-report-to-video/clip-kit"; import { validatePromo } from "umtool-report-to-video/promo-card"; import { renderZoomsErrors } from "umtool-report-to-video/clip-zoom"; +import { renderCensorErrors } from "umtool-report-to-video/clip-censor"; /** The kit keys a clip patch sets (clip-kit.mjs), whole or one dotted field. */ const CLIP_KIT_PATCH_KEYS = CLIP_KIT_KEYS; import { LOOK_KEYS, applyLookPatch, basicOn, lookOf } from "yt-dlp-transcript-common/lib/report/look.mjs"; @@ -1917,6 +1918,8 @@ export async function updateRender(dir, patch, { token = null } = {}) { if ("promo" in patch || "qr" in patch) errors.push(...validatePromo({ render }), ...validateClipKit({ render, timeline: manifest.timeline ?? [] })); // The zooms' soft limit (report-to-video clip-zoom.mjs). if ("zooms" in patch) errors.push(...renderZoomsErrors(render.zooms)); + // The recordings' hidden regions (report-to-video clip-censor.mjs). + if ("censor" in patch) errors.push(...renderCensorErrors(render.censor)); if (errors.length) throw new RenderRefused(errors); manifest.render = render; const nextToken = await writeManifestAtomic(dir, manifest); diff --git a/umtool/lib/report/shortsBatch.test.mjs b/umtool/lib/report/shortsBatch.test.mjs @@ -64,7 +64,7 @@ test("formats, items and the record's again", () => { test("the snapshot: the project keys a clip has, null for one it lacks; laid over the project's entries", () => { const e = { type: "clip", id: "a", vertical: { crop: [0.6, 0, 0.3164, 1] } }; - assert.deepEqual(snapshotOf(e, PROJECT_KEYS), { vertical: { crop: [0.6, 0, 0.3164, 1] }, side: null, qr: null, promo: null, zooms: null, coldOpen: null }); + assert.deepEqual(snapshotOf(e, PROJECT_KEYS), { vertical: { crop: [0.6, 0, 0.3164, 1] }, side: null, qr: null, promo: null, zooms: null, coldOpen: null, censor: null }); const project = [{ type: "clip", id: "a", vertical: { crop: [0.1, 0, 0.3164, 1] }, side: { item: "p", from: 0, to: 3 } }]; const laid = withOverrides(project, { a: { vertical: { crop: [0.6, 0, 0.3164, 1] }, side: null, title: "ignored" } }); assert.deepEqual(laid[0], { type: "clip", id: "a", vertical: { crop: [0.6, 0, 0.3164, 1] } }); @@ -119,7 +119,7 @@ test("umtool shorts: each clip in each format into shorts-<take>/, named, record // The builder was asked one clip at a time, with the flags' knobs and each format's cap. // The take's own 16:9 look takes none of the per-clip builder's knobs (each format only the knobs it reads). assert.deepEqual(calls.map((c) => [c.items[0], c.landscape, c.knobs.maxSeconds, c.knobs.clip]), [["m01", false, 180, "framed"], ["m01", true, 140, undefined], ["w01", false, 180, "framed"], ["w01", true, 140, undefined]]); - assert.deepEqual(calls[2].overrides, { w01: { vertical: { crop: [0.6, 0, 0.3164, 1] }, side: null, qr: null, promo: null, zooms: null, coldOpen: null } }); + assert.deepEqual(calls[2].overrides, { w01: { vertical: { crop: [0.6, 0, 0.3164, 1] }, side: null, qr: null, promo: null, zooms: null, coldOpen: null, censor: null } }); const rec = JSON.parse(await readFile(path.join(folder, "batch.json"), "utf8")); assert.equal(rec.kind, "shorts-batch"); assert.deepEqual(rec.last.argv, ["shorts", "proj", "--take", "kit", "--items", "m01,w01", "--formats", "vertical,landscape"]); diff --git a/umtool/report-to-video/build-video.mjs b/umtool/report-to-video/build-video.mjs @@ -241,6 +241,8 @@ import { clipQrUrl, cornerOverlayXY, cornerQrOf, desktopQrBox, desktopQrOf, vali import { promoBand, promoCardInput, promoFilterParts, promoOf, renderPromoCard, validatePromo } from "./promo-card.mjs"; // ZOOM AT POINTS (lane clip-kit, slice F; clip-zoom.mjs): a per-clip build's pushes in on its picture. import { resolveZooms, validateZooms, zoomFilters } from "./clip-zoom.mjs"; +// HIDDEN REGIONS (lane clip-kit, slice E; clip-censor.mjs): a recording's chat overlay, other accounts on screen. +import { censorParts, censorRecordOf, censorRegionsOf, validateCensor } from "./clip-censor.mjs"; // THE STACKED VERTICAL DECK (vertical-deck.mjs): a 9:16 cut that keeps its deck -- the picture at full width, the // captions under it, a clip's two crops, a post item's hero card -- and the modules it leaves out. import { ENLARGE_WARN, clipTwoCrop, leftOutWords, stackedCaptionGeo, stackedGeometry, stackedOn, twoCropEnlargement, twoCropGraph } from "./vertical-deck.mjs"; @@ -1810,6 +1812,18 @@ async function buildClipSegment(entry, meta, render, dirs, opts, chrome, nodes, return blurPictureFilters({ blur, span, h, layout, lineFiles, render }); }; + // HIDDEN REGIONS (clip-censor.mjs): its recording's boxes (render.censor) and its own, on the SOURCE picture first -- + // before its blur, its zooms and any framing -- over their spans. None: every graph below is the one it always was. + const censorRegions = media.hasVideo ? censorRegionsOf(entry, render, provenance) : []; + const censorDims = censorRegions.length ? await probeDims(raw) : null; + if (censorRegions.length) cutRecord.censor = censorRecordOf(censorRegions); + /** The picture `vLabel` (a "[label]") with the regions hidden: the parts to run first, and the label after them. */ + const censored = (vLabel) => { + if (!censorRegions.length) return { parts: [], v: vLabel }; + const parts = censorParts(vLabel.slice(1, -1), "vcen", censorRegions, { width: censorDims[0], height: censorDims[1], from: cutRecord.start, gaps: cutRecord.gaps ?? [], seconds: segSeconds }); + return { parts, v: "[vcen]" }; + }; + // THE SIDE POST (side-card.mjs): the post a clip carries beside it, up over its `from`-`to`, never read. const sidePost = dirs.sides ? sidePostOf(entry, dirs.sides.timeline) : null; const sideUp = sidePost ? sideSpan(entry.side, segSeconds) : null; @@ -1915,7 +1929,8 @@ async function buildClipSegment(entry, meta, render, dirs, opts, chrome, nodes, "-filter_complex", [ ...g.parts, ...levelParts(null, g.a), - `${g.v}${graph}${qrBox ? "[vp0]" : "[vp]"}`, + ...censored(g.v).parts, + `${censored(g.v).v}${graph}${qrBox ? "[vp0]" : "[vp]"}`, ...qrParts, ...(promoPart ? promoPart.parts : []), cap ? `${promoPart ? promoPart.v : "[vp]"}${cap.filter}[v]` : `${promoPart ? promoPart.v : "[vp]"}null[v]`, @@ -1962,7 +1977,8 @@ async function buildClipSegment(entry, meta, render, dirs, opts, chrome, nodes, "-filter_complex", [ ...g.parts, ...levelParts(null, g.a), - `${g.v}${graph}[vp]`, + ...censored(g.v).parts, + `${censored(g.v).v}${graph}[vp]`, cap ? `[vp]${cap.filter}[v]` : "[vp]null[v]", ].join(";"), "-map", "[v]", "-map", audioMap, @@ -1982,7 +1998,8 @@ async function buildClipSegment(entry, meta, render, dirs, opts, chrome, nodes, const sideGeo = sideUp ? landscapeSideGeometry({ x: fr.box.x, y: fr.box.y, w: fr.box.width, h: fr.box.height }, entry.side.place) : null; const sideInput = sideGeo ? await sideCard(sideGeo.w, sideGeo.h) : []; const sideIdx = 1 + (pst ? 1 : 0) + (soundInput ? 1 : 0); - const framed = `${pst ? "[pic]" : g.v}${deckFramingFilter(render, { feed: fr.layout === "feed", picture })}`; + const cen = pst ? { parts: [], v: "[pic]" } : censored(g.v); + const framed = `${cen.v}${deckFramingFilter(render, { feed: fr.layout === "feed", picture })}`; // The stacked vertical deck's captions (vertical-deck.mjs): under the picture, each word lit, over the frame. const vcap = dirs.vertical?.stacked && dirs.look ? await segmentCaptions({ @@ -2004,6 +2021,7 @@ async function buildClipSegment(entry, meta, render, dirs, opts, chrome, nodes, "-filter_complex", [ ...g.parts, ...levelParts(pst ? pst.parts : null, g.a), + ...cen.parts, ...(sideGeo ? [`${framed}[vb]`, `[${sideIdx}:v]${sideFitFilter(sideGeo.w, sideGeo.h)}[vsc]`, ...(capped(`[vb][vsc]${landscapeSideOverlay(sideGeo, sideUp, render.width)}`) ?? [`[vb][vsc]${landscapeSideOverlay(sideGeo, sideUp, render.width)}[v]`])] : capped(framed) ?? [`${framed}[v]`]), @@ -2133,10 +2151,12 @@ async function buildClipSegment(entry, meta, render, dirs, opts, chrome, nodes, const mg = mont ? montageSegmentGraph({ mont, render, box: { w: VW, h: VH }, hasVideo: media.hasVideo, cutA, cutB, gainDb: level?.gain ?? null }) : null; // The gaps out first (none in a montage: segGaps is empty there). const g = gapped(ain); - const pic = mg?.v ?? (pst ? "[pic]" : g.v); + // Hidden regions (clip-censor.mjs) on the picture first; a montage re-cuts its picture, and draws none. + const cenPlain = mg || pst ? { parts: [], v: null } : censored(g.v); + const pic = mg?.v ?? (pst ? "[pic]" : cenPlain.v); const lead = mg ? [...(pst ? [`[0:a]asplit=2[mpa][mpw]`, ...pst.parts.map((p) => p.replaceAll("[0:a]", "[mpw]"))] : []), ...mg.parts] - : [...g.parts, ...levelParts(pst ? pst.parts : null, g.a)]; + : [...g.parts, ...levelParts(pst ? pst.parts : null, g.a), ...cenPlain.parts]; const parts = hasFooter ? [ @@ -6944,7 +6964,7 @@ export async function buildVideo({ manifestPath, opts = {}, out, only, fetchOnly ...validateFlipEntries(whole), ...validateNarration(whole), ...validateDrafted(whole), ...validatePublish(whole), ...validateStatsEntries(whole), ...validateMontage(whole), ...validateAssist(whole), ...validateFxEntries(whole, { schedule: false }), ...validateTransitionStyle(whole), ...validateLook(whole), ...validateClipAudioEntries(whole), ...validateClipBlurEntries(whole), ...validateFinaleEntries(whole), - ...validateGapEntries(whole), ...measureSettingsProblems(whole), ...validateAnalysisEntries(whole), ...validateClipKit(whole), ...validatePromo(whole), ...validateZooms(whole), + ...validateGapEntries(whole), ...measureSettingsProblems(whole), ...validateAnalysisEntries(whole), ...validateClipKit(whole), ...validatePromo(whole), ...validateZooms(whole), ...validateCensor(whole), ]; if (errors.length) throw new Error(`manifest: ${errors.join("; ")}`); } diff --git a/umtool/report-to-video/clip-censor.mjs b/umtool/report-to-video/clip-censor.mjs @@ -0,0 +1,164 @@ +// HIDDEN REGIONS of a clip's picture (lane clip-kit, slice E): a stream layout's chat overlay, a browser window showing +// other people's accounts -- the same boxes on every clip cut from ONE recording, or on one clip, each for the whole +// clip or a span of it. Privacy, not TOS: they stay on in the uncensored variant (`render.blur: "off"`), as a post +// attachment's censor does (post-censor.mjs, whose styles, strengths and box rules these are). +// +// render.censor [{ video, channel?, boxes, style?, strength?, from?, to? }] per recording (≤ 16) +// video the recording's id; `channel` its channel (default: any channel's recording of that id) +// clip.censor false (none, not even the recording's) | { boxes, style?, strength?, from?, to? } added to them +// boxes [[x, y, w, h] | { box: [x, y, w, h], from?, to? }] 1 to 8, fractions of the SOURCE picture; +// a box's own from/to (source seconds) limit it to that span +// style "blur" (default) | "black" | "pixelate"; strength 1–10 (7) +// from, to source seconds: every box of the entry only over that span +// +// WHERE: on the source picture, FIRST -- before a clip's blur, its zooms and any layout -- in every path a clip is cut +// in (a cut with or without the deck, a short, a desktop clip, Make a short), so a box is the same part of the +// recording whatever frames it. Nothing else is touched: the sound, the captions, the header, the deck. +// +// PURE: no fs, no ffmpeg run. +import { blurSigma, boxOk, pixelGrid } from "./post-censor.mjs"; +import { offsetIn } from "./gaps.mjs"; + +const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); +const num = (v) => typeof v === "number" && Number.isFinite(v); + +export const CENSOR_STYLES = Object.freeze(["blur", "black", "pixelate"]); +export const CENSOR_DEFAULTS = Object.freeze({ style: "blur", strength: 7 }); +export const CENSOR_BOXES_MAX = 8; +export const CENSOR_RECORDINGS_MAX = 16; +const ENTRY_KEYS = ["boxes", "style", "strength", "from", "to"]; + +function spanErrors(o, where) { + const errors = []; + for (const k of ["from", "to"]) if (o[k] !== undefined && !(num(o[k]) && o[k] >= 0)) errors.push(`${where}.${k} is a source second`); + if (num(o.from) && num(o.to) && o.to - o.from < 0.2) errors.push(`${where}: its span ${o.from}–${o.to} is under 0.2 s`); + return errors; +} + +/** Each thing wrong with one censor entry's boxes, style, strength and span. */ +function entryErrors(v, where) { + const errors = []; + if (!Array.isArray(v.boxes) || !v.boxes.length || v.boxes.length > CENSOR_BOXES_MAX) errors.push(`${where}.boxes is a list of 1 to ${CENSOR_BOXES_MAX} boxes: [x, y, w, h] or {box, from?, to?}`); + else v.boxes.forEach((b, j) => { + const w = `${where}.boxes[${j}]`; + if (Array.isArray(b)) { + if (!boxOk(b)) errors.push(`${w} is [x, y, w, h], fractions of the picture inside it`); + } else if (isObj(b)) { + for (const k of Object.keys(b)) if (!["box", "from", "to"].includes(k)) errors.push(`${w}.${k} is not a key (box, from, to)`); + if (!boxOk(b.box)) errors.push(`${w}.box is [x, y, w, h], fractions of the picture inside it`); + errors.push(...spanErrors(b, w)); + } else errors.push(`${w} is [x, y, w, h] or {box, from?, to?}`); + }); + if (v.style !== undefined && !CENSOR_STYLES.includes(v.style)) errors.push(`${where}.style is one of ${CENSOR_STYLES.join(", ")}`); + if (v.strength !== undefined && !(num(v.strength) && v.strength >= 1 && v.strength <= 10)) errors.push(`${where}.strength is 1–10`); + errors.push(...spanErrors(v, where)); + return errors; +} + +/** Each thing wrong with a clip's `censor` ([] when fine, or absent). */ +export function clipCensorErrors(v, where = "clip.censor") { + if (v === undefined || v === false) return []; + if (!isObj(v)) return [`${where} is false (none, not even the recording's) or {boxes, style?, strength?, from?, to?}`]; + const errors = []; + for (const k of Object.keys(v)) if (!ENTRY_KEYS.includes(k)) errors.push(`${where}.${k} is not a key (${ENTRY_KEYS.join(", ")})`); + return [...errors, ...entryErrors(v, where)]; +} + +/** Each thing wrong with `render.censor` ([] when fine, or absent). */ +export function renderCensorErrors(v, where = "render.censor") { + if (v === undefined || v === null) return []; + if (!Array.isArray(v) || v.length > CENSOR_RECORDINGS_MAX) return [`${where} is a list of at most ${CENSOR_RECORDINGS_MAX} recordings' boxes [{video, channel?, boxes, …}]`]; + const errors = []; + v.forEach((e, i) => { + const w = `${where}[${i}]`; + if (!isObj(e)) return errors.push(`${w} is {video, channel?, boxes, style?, strength?, from?, to?}`); + for (const k of Object.keys(e)) if (![...ENTRY_KEYS, "video", "channel"].includes(k)) errors.push(`${w}.${k} is not a key (video, channel, ${ENTRY_KEYS.join(", ")})`); + if (typeof e.video !== "string" || !e.video.trim()) errors.push(`${w}.video is the recording's id`); + if (e.channel !== undefined && (typeof e.channel !== "string" || !e.channel.trim())) errors.push(`${w}.channel is a channel's slug`); + errors.push(...entryErrors(e, w)); + }); + return errors; +} + +/** Every reason a manifest's hidden regions cannot be drawn. */ +export function validateCensor(manifest) { + const errors = renderCensorErrors(manifest?.render?.censor); + for (const e of manifest?.timeline ?? []) { + if (e?.censor === undefined) continue; + if (e.type !== "clip") errors.push(`timeline ${e.id ?? "?"}: censor is a clip's`); + else errors.push(...clipCensorErrors(e.censor, `timeline ${e.id}.censor`)); + } + return errors; +} + +/** Does a recording entry of `render.censor` name this clip's recording? */ +export function namesClip(rec, entry, provenance = {}) { + if (rec?.video !== entry?.video) return false; + if (rec.channel === undefined) return true; + return rec.channel === (entry.channel ?? provenance?.channelSlug ?? null); +} + +/** + * The regions a clip's picture hides (PURE): its recording's (render.censor) and its own, each `{box, style, + * strength, from, to}` (`from`/`to` source seconds or null: the whole clip). None when the clip says `censor: false`. + */ +export function censorRegionsOf(entry, render, provenance = {}) { + if (entry?.type !== "clip" || entry.censor === false) return []; + const sets = [ + ...(Array.isArray(render?.censor) ? render.censor.filter((r) => isObj(r) && namesClip(r, entry, provenance)) : []), + ...(isObj(entry.censor) ? [entry.censor] : []), + ]; + const out = []; + for (const s of sets) { + const style = CENSOR_STYLES.includes(s.style) ? s.style : CENSOR_DEFAULTS.style; + const strength = num(s.strength) ? s.strength : CENSOR_DEFAULTS.strength; + for (const b of Array.isArray(s.boxes) ? s.boxes : []) { + const box = Array.isArray(b) ? b : b?.box; + if (!boxOk(box)) continue; + const from = num(b?.from) ? b.from : num(s.from) ? s.from : null; + const to = num(b?.to) ? b.to : num(s.to) ? s.to : null; + out.push({ box, style, strength, from, to }); + } + } + return out; +} + +const f3 = (n) => Number(n).toFixed(3); + +/** + * The filtergraph parts that hide `regions` on a picture of `width`×`height` px (`[vIn]` → `[vOut]`, labels without + * brackets): each box blurred or pixelated (split, cropped, laid back over) or filled black, over its span on the + * segment's clock (`from` the source second the segment starts at, `gaps` the cut's). Empty when there are none: + * the graph is the one it always was. + */ +export function censorParts(vIn, vOut, regions, { width, height, from = 0, gaps = [], seconds = Infinity }) { + if (!regions?.length) return []; + const parts = []; + let cur = vIn; + regions.forEach((g, j) => { + const x = Math.round(g.box[0] * width); + const y = Math.round(g.box[1] * height); + const w = Math.max(2, 2 * Math.round(Math.min(width - x, g.box[2] * width) / 2)); + const h = Math.max(2, 2 * Math.round(Math.min(height - y, g.box[3] * height) / 2)); + const a = g.from === null ? null : Math.max(0, offsetIn(g.from, from, gaps)); + const b = g.to === null ? null : Math.min(seconds, offsetIn(g.to, from, gaps)); + const enable = a === null && b === null ? "" : `:enable='between(t,${f3(a ?? 0)},${f3(b ?? 1e6)})'`; + const next = j === regions.length - 1 ? vOut : `${vOut}_c${j}`; + if (g.style === "black") { + parts.push(`[${cur}]drawbox=x=${x}:y=${y}:w=${w}:h=${h}:color=black@1:t=fill${enable}[${next}]`); + } else { + const fx = g.style === "pixelate" + ? (() => { + const [nx, ny] = pixelGrid(g.strength, g.box[2], g.box[3], width, height); + return `scale=${nx}:${ny}:flags=neighbor,scale=${w}:${h}:flags=neighbor`; + })() + : `gblur=sigma=${blurSigma(g.strength, width)}:steps=3`; + parts.push(`[${cur}]split[${vOut}_s${j}a][${vOut}_s${j}b]`, `[${vOut}_s${j}b]crop=${w}:${h}:${x}:${y},${fx}[${vOut}_s${j}c]`, `[${vOut}_s${j}a][${vOut}_s${j}c]overlay=x=${x}:y=${y}${enable}[${next}]`); + } + cur = next; + }); + return parts; +} + +/** What a cut record says of the regions it hid (rounded). */ +export const censorRecordOf = (regions) => regions.map((g) => ({ box: g.box, style: g.style, ...(g.style !== "black" ? { strength: g.strength } : {}), ...(g.from !== null ? { from: g.from } : {}), ...(g.to !== null ? { to: g.to } : {}) })); diff --git a/umtool/report-to-video/clip-censor.test.mjs b/umtool/report-to-video/clip-censor.test.mjs @@ -0,0 +1,58 @@ +// Hidden regions (lane clip-kit, slice E): the rules, a recording's boxes on every clip of it, a clip's own, the graph. +import { test } from "node:test"; +import assert from "node:assert/strict"; + +import { censorParts, censorRegionsOf, clipCensorErrors, namesClip, renderCensorErrors, validateCensor } from "./clip-censor.mjs"; +import { parseBox, withRecording } from "../lib/report/censorCli.mjs"; + +const clip = (o = {}) => ({ type: "clip", id: "c1", channel: "chan", video: "rec1", start: 100, end: 160, ...o }); +const CHAT = { video: "rec1", boxes: [[0.75, 0, 0.25, 1]], style: "pixelate" }; +const TAB = { video: "rec1", channel: "chan", boxes: [{ box: [0, 0.6, 0.3, 0.4], from: 120, to: 130 }] }; + +test("the rules: boxes of the picture (1 to 8), a box's own span, a style and a strength; per recording, its video", () => { + assert.deepEqual(renderCensorErrors([CHAT, TAB]), []); + assert.deepEqual(clipCensorErrors({ boxes: [[0.1, 0.1, 0.2, 0.2]], style: "black", from: 101, to: 110 }), []); + assert.deepEqual(clipCensorErrors(false), []); + const no = (v, re, f = clipCensorErrors) => assert.match(f(v).join("\n"), re, JSON.stringify(v)); + no({ boxes: [] }, /a list of 1 to 8 boxes/); + no({ boxes: [[0.9, 0, 0.3, 1]] }, /boxes\[0\] is \[x, y, w, h\]/); + no({ boxes: [{ box: [0, 0, 0.5, 0.5], from: 5, to: 5.1 }] }, /under 0\.2 s/); + no({ boxes: [[0, 0, 0.5, 0.5]], style: "smudge" }, /style is one of blur, black, pixelate/); + no({ boxes: [[0, 0, 0.5, 0.5]], strength: 20 }, /strength is 1–10/); + no("yes", /is false \(none, not even the recording's\)/); + no([{ boxes: [[0, 0, 0.5, 0.5]] }], /video is the recording's id/, renderCensorErrors); + no([{ ...CHAT, hidden: true }], /hidden is not a key/, renderCensorErrors); + assert.match(validateCensor({ render: {}, timeline: [{ type: "post", id: "p", censor: false }] }).join(), /censor is a clip's/); +}); + +test("a clip's regions: its recording's (any channel, or the one named) and its own; `censor: false` none at all", () => { + assert.ok(namesClip(CHAT, clip()) && namesClip(TAB, clip()) && !namesClip(TAB, clip({ channel: "other" })) && !namesClip(CHAT, clip({ video: "rec2" }))); + const r = censorRegionsOf(clip({ censor: { boxes: [[0.1, 0.1, 0.1, 0.1]], style: "black" } }), { censor: [CHAT, TAB] }); + assert.deepEqual(r.map((g) => [g.style, g.from, g.to]), [["pixelate", null, null], ["blur", 120, 130], ["black", null, null]]); + assert.deepEqual(censorRegionsOf(clip({ censor: false }), { censor: [CHAT] }), []); + assert.deepEqual(censorRegionsOf(clip({ video: "rec2" }), { censor: [CHAT] }), []); + // The channel from the provenance when the clip names none. + assert.equal(censorRegionsOf({ type: "clip", video: "rec1" }, { censor: [TAB] }, { channelSlug: "chan" }).length, 1); +}); + +test("the graph: blurred and pixelated regions split, cut and laid back; black filled; a span on the segment's clock; none: nothing", () => { + assert.deepEqual(censorParts("0:v", "vcen", [], { width: 1920, height: 1080 }), []); + const regions = censorRegionsOf(clip({ censor: { boxes: [[0, 0, 0.1, 0.1]], style: "black" } }), { censor: [CHAT, TAB] }); + const parts = censorParts("0:v", "vcen", regions, { width: 1920, height: 1080, from: 110, gaps: [{ from: 115, to: 117 }], seconds: 40 }); + assert.equal(parts[0], "[0:v]split[vcen_s0a][vcen_s0b]"); + assert.match(parts[1], /^\[vcen_s0b\]crop=480:1080:1440:0,scale=\d+:\d+:flags=neighbor,scale=480:1080:flags=neighbor\[vcen_s0c\]$/); + assert.equal(parts[2], "[vcen_s0a][vcen_s0c]overlay=x=1440:y=0[vcen_c0]"); + assert.match(parts[4], /gblur=sigma=/); + // 120–130 source s, from 110 with 2 s of gap before: 8–18 on the segment's clock. + assert.equal(parts[5], "[vcen_s1a][vcen_s1c]overlay=x=0:y=648:enable='between(t,8.000,18.000)'[vcen_c1]"); + assert.equal(parts[6], "[vcen_c1]drawbox=x=0:y=0:w=192:h=108:color=black@1:t=fill[vcen]"); +}); + +test("umtool censor's arguments: a box, a box over a span; a recording's set replaced, removed", () => { + assert.deepEqual(parseBox("0.75,0,0.25,1"), [0.75, 0, 0.25, 1]); + assert.deepEqual(parseBox("0,0.6,0.3,0.4@120-130"), { box: [0, 0.6, 0.3, 0.4], from: 120, to: 130 }); + assert.throws(() => parseBox("a,b"), /x,y,w,h/); + const list = [CHAT, { video: "rec2", boxes: [[0, 0, 0.5, 0.5]] }]; + assert.deepEqual(withRecording(list, { video: "rec1" }, { video: "rec1", boxes: [[0, 0, 1, 0.1]] }).map((r) => [r.video, r.boxes.length]), [["rec2", 1], ["rec1", 1]]); + assert.deepEqual(withRecording(list, { video: "rec1" }, null).map((r) => r.video), ["rec2"]); +}); diff --git a/umtool/report-to-video/clip-kit-render.test.mjs b/umtool/report-to-video/clip-kit-render.test.mjs @@ -281,3 +281,46 @@ test("a cut with no deck, the QR on and off: a clip, a still with a citeUrl, a t } } }); + +// ---- slice E: hidden regions ---------------------------------------------------------------------------------------- +test("hidden regions: a recording's box on every clip of it, in a cut and in a short; a box over a span; on in the uncensored cut; another recording's changes nothing", { skip: !have && "needs ffmpeg and qrencode" }, async () => { + quiet(); + // The window is a grey picture with WHITE in its right quarter (a stand-in chat overlay); the box blacks it out. + const white = async (p) => { + const raw = path.join(p.root, "out", "clips-raw", `${VIDEO}_0.00-6.00.mp4`); + const r = spawnSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", `color=c=gray:s=1920x1080:r=${FPS}:d=6`, "-f", "lavfi", "-i", "sine=frequency=440:sample_rate=48000:duration=6", + "-filter_complex", "[0:v]drawbox=x=1440:y=0:w=480:h=1080:c=white:t=fill[v]", "-map", "[v]", "-map", "1:a", "-c:v", "libx264", "-preset", "ultrafast", "-c:a", "aac", "-shortest", raw]); + assert.equal(r.status, 0, String(r.stderr)); + }; + const CHAT = { video: VIDEO, boxes: [[0.75, 0, 0.25, 1]], style: "black" }; + const ps = [ + await project({ render: { qr: false, censor: [CHAT], blur: "off" } }), + await project({ render: { qr: false, censor: [{ ...CHAT, boxes: [{ box: [0.75, 0, 0.25, 1], from: 2.5, to: 4 }] }] } }), + await project({ render: { qr: false } }), + await project({ render: { qr: false, censor: [{ ...CHAT, video: "another-recording" }] } }), + ]; + try { + for (const p of ps) await white(p); + for (const p of ps) await buildVideo({ manifestPath: p.manifestPath, opts: { noNetwork: true } }); + const seg = (p) => path.join(p.root, "out", "sourced", "segments", "c1.mp4"); + const right = { x: 1500, y: 300, w: 300, h: 300 }; + // The whole clip, in the uncensored variant too: black where the overlay was. + assert.ok(boxAvg(seg(ps[0]), right, 1) < 40, `hidden (${boxAvg(seg(ps[0]), right, 1)})`); + assert.deepEqual(JSON.parse(await readFile(seg(ps[0]).replace(/\.mp4$/, ".cut.json"), "utf8")).censor, [{ box: [0.75, 0, 0.25, 1], style: "black" }]); + // Over its span only (source 2.5–4 s, the clip from 1 s): shown at 0.5 s, hidden at 2 s. + assert.ok(boxAvg(seg(ps[1]), right, 0.5) > 200 && boxAvg(seg(ps[1]), right, 2) < 40, "over its span"); + // Another recording's boxes change nothing: the segment as with none. + assert.equal(md5(seg(ps[3])), md5(seg(ps[2]))); + assert.equal(JSON.parse(await readFile(seg(ps[2]).replace(/\.mp4$/, ".cut.json"), "utf8")).censor, undefined); + // A short of the same clip: the box is the same part of the recording (hidden under its framed layout too). + const m = JSON.parse(await readFile(ps[0].manifestPath, "utf8")); + m.render.vertical = { clip: "framed" }; + await writeFile(ps[0].manifestPath, JSON.stringify(m)); + await buildVideo({ manifestPath: ps[0].manifestPath, opts: { noNetwork: true, vertical: true, verticalOut: path.join(ps[0].root, "out", "kit.vertical.mp4") } }); + const v = clipGeometry("framed", { format: "vertical" }, 1080, 1920).video; + const vseg = path.join(ps[0].root, "out", "vertical", "segments", "c1.mp4"); + assert.ok(boxAvg(vseg, { x: 860, y: v.y + 100, w: 180, h: 200 }, 1) < 40, "hidden in the short's picture"); + } finally { + for (const p of ps) await rm(p.root, { recursive: true, force: true }); + } +}); diff --git a/umtool/report-to-video/clip-kit.mjs b/umtool/report-to-video/clip-kit.mjs @@ -25,6 +25,7 @@ import { DESKTOP_QR_CORNERS, DESKTOP_QR_SIZE, QR_LINKS, VERTICAL_QR_CORNERS, VER import { archiveMomentUrl } from "./site-links.mjs"; import { clipPromoErrors } from "./promo-card.mjs"; import { zoomsErrors } from "./clip-zoom.mjs"; +import { clipCensorErrors } from "./clip-censor.mjs"; const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); const q = (v) => JSON.stringify(v); @@ -35,7 +36,7 @@ export const QR_KEYS = Object.freeze(["scale", "quiet", "ecc", "margin", "corner export { QR_LINKS, VERTICAL_QR_CORNERS, VERTICAL_QR_KEYS, VERTICAL_QR_SIZE, verticalQrErrors }; /** The keys a clip may carry for the kit (vertical-plan.mjs reads them from the project over a take's). */ -export const CLIP_KIT_KEYS = Object.freeze(["qr", "name", "promo", "zooms", "coldOpen"]); +export const CLIP_KIT_KEYS = Object.freeze(["qr", "name", "promo", "zooms", "coldOpen", "censor"]); /** A cold open's length (s): refused outside the hard bounds, noted outside the soft ones (what reads best). */ export const COLD_OPEN = Object.freeze({ min: 1, max: 4, softMin: 1.5, softMax: 3 }); @@ -72,8 +73,10 @@ export function clipKitErrors(entry, where = "clip") { errors.push(...zoomsErrors(entry.zooms, `${where}.zooms`, entry)); // Its cold open: a span of its own cut, played first. errors.push(...coldOpenErrors(entry.coldOpen, `${where}.coldOpen`, entry)); - if ((entry.qr !== undefined || entry.name !== undefined || entry.promo !== undefined || entry.zooms !== undefined || entry.coldOpen !== undefined) && entry.type !== undefined && entry.type !== "clip") { - errors.push(`${where}: qr, name, promo, zooms and coldOpen are a clip's`); + // Its hidden regions (clip-censor.mjs). + errors.push(...clipCensorErrors(entry.censor, `${where}.censor`)); + if ((entry.qr !== undefined || entry.name !== undefined || entry.promo !== undefined || entry.zooms !== undefined || entry.coldOpen !== undefined || entry.censor !== undefined) && entry.type !== undefined && entry.type !== "clip") { + errors.push(`${where}: qr, name, promo, zooms, coldOpen and censor are a clip's`); } return errors; } diff --git a/umtool/report-to-video/clip-kit.test.mjs b/umtool/report-to-video/clip-kit.test.mjs @@ -68,7 +68,7 @@ test("the rules refuse what cannot be drawn, by name", () => { assert.match(clipKitErrors({ type: "clip", qr: { corner: "tl", size: 2 } }, "w01").join(), /w01\.qr\.size is not a key/); assert.match(clipKitErrors({ type: "clip", qr: "yes" }, "w01").join(), /w01\.qr is false/); assert.match(clipKitErrors({ type: "clip", name: "x".repeat(61) }, "w01").join(), /w01\.name is a file name of 1 to 60/); - assert.match(clipKitErrors({ type: "post", qr: false }, "p1").join(), /qr, name, promo, zooms and coldOpen are a clip's/); + assert.match(clipKitErrors({ type: "post", qr: false }, "p1").join(), /qr, name, promo, zooms, coldOpen and censor are a clip's/); assert.match(validateClipKit({ render: { qr: { links: "channel" } }, timeline: [] }).join(), /set render\.promo\.url/); assert.deepEqual(validateClipKit({ render: { qr: { links: "channel" }, promo: { url: "https://kick.com/somechan" } }, timeline: [] }), []); // A short's code: at the top only (its captions run along the foot), a size in bounds. diff --git a/umtool/report-to-video/lint.mjs b/umtool/report-to-video/lint.mjs @@ -126,6 +126,7 @@ import { archiveMomentUrl } from "./site-links.mjs"; import { clipQrUrl, coldOpenNote, cornerQrOf, desktopQrOf, expiringLinkNote, validateClipKit, verticalQrOf } from "./clip-kit.mjs"; import { validatePromo } from "./promo-card.mjs"; import { validateZooms } from "./clip-zoom.mjs"; +import { validateCensor } from "./clip-censor.mjs"; import { cardNarrationSeconds, hasNarration, narrationsOf, validateNarration } from "./narration.mjs"; import { validatePodcast } from "./build-podcast.mjs"; import { draftsReviewFromNarration, draftsReviewProblems, readDraftsReview } from "./drafts-review.mjs"; @@ -365,7 +366,7 @@ export function validatorErrors(whole) { // A clip's `chat` and render.chrome.chat (chat.mjs). ...validateChatEntries(whole), // The clip kit: a clip's `qr` and `name`, render.qr's corner and links (clip-kit.mjs); the channel promo (promo-card.mjs). - ...validateClipKit(whole), ...validatePromo(whole), ...validateZooms(whole), + ...validateClipKit(whole), ...validatePromo(whole), ...validateZooms(whole), ...validateCensor(whole), // Release 33: render.montage, its keys and what it does not combine with. ...validateMontage(whole), // Release 35: a clip's `assist` (the clip finder's provenance; the render ignores it). diff --git a/umtool/report-to-video/package.json b/umtool/report-to-video/package.json @@ -31,6 +31,7 @@ "./clip-kit": "./clip-kit.mjs", "./promo-card": "./promo-card.mjs", "./clip-zoom": "./clip-zoom.mjs", + "./clip-censor": "./clip-censor.mjs", "./reframe": "./reframe.mjs", "./side-card": "./side-card.mjs", "./check-availability": "./check-availability.mjs", diff --git a/umtool/report-to-video/vertical-plan.mjs b/umtool/report-to-video/vertical-plan.mjs @@ -41,7 +41,7 @@ export function beatsOf(doc) { * The keys of a clip a short reads from the PROJECT over the take's: set with `umtool set` after the take was made * (its framing, its side post, the clip kit's keys). A batch's record snapshots them (lib/report/shortsBatch.mjs). */ -export const PROJECT_KEYS = Object.freeze(["vertical", "side", "qr", "promo", "zooms", "coldOpen"]); +export const PROJECT_KEYS = Object.freeze(["vertical", "side", "qr", "promo", "zooms", "coldOpen", "censor"]); /** The project's per-clip framing (PROJECT_KEYS) laid over a take's entry. */ export function withProjectFraming(entry, projectById) {