commit 5014c0dd80001687bba5dbe4d1a5432d4f9e6a58 parent 30cfc24a4ffd443d87dce6c7fc923ed627bd84e4 Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st> Date: Fri, 13 Nov 2026 22:09:18 -0500 clip kit F: zoom at points in a per-clip build A clip's `zooms` ([{at, hold?, scale?, focus?, box?, ramp?}], 1-8, none overlapping; report-to-video clip-zoom.mjs) push a short's or a desktop clip's picture in at those source seconds, smoothstep in and out over `ramp`. In source space, after the blur and before the layout (zoompan about the focus, its frames at the cut's rate), so a short's vertical.crop stays the same box and the focus keeps its place; captions, the source line, the code and the promo card never zoom. Strict by default: a layout's rest enlargement (vertical.mjs pictureRegion) times the zoom may not pass the source's own pixels -- the build refuses it by name with the enlargement it would play at. render.zooms.maxScale (1-1.3) is a soft limit over the sharp one, and the build notes each zoom that plays softer than its source. A push outside what a segment plays is left out, said. The cut record names each zoom drawn. Writer (updateClip, `zooms=`; updateRender, render.zooms), lint and build validate it. The clip editor's Zoom here (scale, focus, hold, x); the Look panel's Zooms (never / up to x1.15 / up to x1.3 soft). No zooms: the graph is the one it always was. The render test file loads its modules before the first test is declared: a test declared after a top-level await could start after the root's after-hook had removed its corpus (seen running one test alone). Co-Authored-By: Claude <noreply@anthropic.com> Diffstat:
25 files changed, 500 insertions(+), 21 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"; +export type LookKey = "headerHeight" | "footerHeight" | "qr" | "transition" | "transitionStyle" | "loudness" | "captions" | "room" | "slide" | "blur" | "intro" | "format" | "vertical" | "mode" | "basic" | "tallWindows" | "desktop" | "promo" | "zooms"; 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"]); +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"]); /** `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, 18); + assert.equal(LOOK_KEYS.length, 19); }); 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,16 @@ # Changelog ## [Unreleased] +- **umtool: a short or a desktop clip can zoom in at points.** A clip's `zooms` + (`[{at, scale|box, focus, hold, ramp}]`) push its picture in at those source seconds, eased in and out. + - The zoom works on the source picture before the layout. A short's crop stays put and the focus keeps its place + on screen. + - It is strict by default: a zoom past the source's own pixels is refused, naming the enlargement. With 1080 windows + a framed short has room up to ×1.78; a full short and a desktop clip have none. + - `render.zooms.maxScale` (up to 1.3) allows a soft zoom past that limit, and the build says how much softer than + its source it plays. + - Controls: the clip editor's **Zoom here** (scale, focus, hold), the Look panel's **Zooms**, and + `umtool set <p> <clip> zooms=…`. - **umtool: a clip can end on the channel's card, for promoting the streamer it was clipped from.** `render.promo` (`{name, url, qr?, portrait?, palette?, lead?, fade?, hold?, captions?}`) ends a short's, a desktop clip's or a batch's last clip on a card. diff --git a/umtool/components/projects/report/LookPanel.tsx b/umtool/components/projects/report/LookPanel.tsx @@ -44,6 +44,7 @@ type Look = { blur?: string; intro?: string | { style?: string; [k: string]: unknown } | null; promo?: Promo | null; + zooms?: { maxScale?: number } | null; desktop?: { tag?: boolean; qr?: boolean | { corner?: string; size?: number; links?: string }; captions?: { size?: string; lines?: number }; [k: string]: unknown } | null; }; type Mode = "deck" | "basic"; @@ -93,6 +94,7 @@ type Draft = { promoFade: string; promoHold: string; promoCaptions: boolean; + zoomSoft: string; }; /** A desktop clip's code as the panel shows it: off, or its corner (br when on with none). */ @@ -182,6 +184,7 @@ function draftOf(l: Look, mode: Mode = "deck"): Draft { deskQr: deskQrOf(l.desktop), deskSize: l.desktop?.captions?.size ?? "l", ...promoDraftOf(l.promo), + zoomSoft: String(l.zooms?.maxScale ?? 1), }; } @@ -236,6 +239,8 @@ function patchOf(was: Look, d: Draft, view: View): Record<string, unknown> { const next = promoNext(was.promo, d); if (JSON.stringify(next ?? null) !== JSON.stringify(was.promo ?? null)) p.promo = next; } + // The zooms' soft limit (render.zooms.maxScale, clip-zoom.mjs): 1 (strict) is no key. + if (Number(d.zoomSoft) !== (was.zooms?.maxScale ?? 1)) p.zooms = Number(d.zoomSoft) === 1 ? null : { maxScale: Number(d.zoomSoft) }; // The desktop clips (render.desktop, the clip kit): the source line, a code, the captions' size. { const next = desktopNext(was.desktop, d); @@ -494,6 +499,13 @@ export default function LookPanel({ project }: { project: string }) { <option value="tl">top left</option> </Select> </Field> + <Field label="Zooms" hint="past the source's own pixels"> + <Select data-look-zoom-soft="" value={draft.zoomSoft} disabled={busy} onChange={(e) => set({ zoomSoft: e.target.value })}> + <option value="1">never (sharp)</option> + <option value="1.15">up to ×1.15 soft</option> + <option value="1.3">up to ×1.3 soft</option> + </Select> + </Field> <Field label="Captions"> <Select data-look-desktop-size="" value={draft.deskSize} disabled={busy} onChange={(e) => set({ deskSize: e.target.value })}> <option value="m">medium</option> diff --git a/umtool/components/projects/review/ClipEditor.tsx b/umtool/components/projects/review/ClipEditor.tsx @@ -1728,6 +1728,7 @@ function ShortMaker({ project, clipId, short, framed, framing, onFraming, onCent {portrait && <span data-promo-portrait-set="">portrait: {portrait}</span>} </div> )} + {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"> {running ? "Rendering 1080×1920 in the heavy slot" : job.state === "done" ? "Made — on the Deliver tab's Shorts list" : `Failed${job.error ? `: ${job.error}` : ""}`} @@ -1743,6 +1744,72 @@ function ShortMaker({ project, clipId, short, framed, framing, onFraming, onCent } // --------------------------------------------------------------------------- +// Zoom at points (lane clip-kit, report-to-video clip-zoom.mjs): a short's or a desktop clip's picture pushed in at +// a source second, about a focus (percent of the picture), eased in and out. The build refuses one past the +// source's pixels (or the cut's soft limit) by name. +// --------------------------------------------------------------------------- + +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 }) { + const write = (next: Zoom[], done: string) => onKit({ zooms: next.length ? [...next].sort((a, b) => a.at - b.at) : null }, done); + const change = (i: number, z: Zoom) => write(zooms.map((x, j) => (j === i ? z : x)), "Saved the zoom"); + return ( + <div className="space-y-1" data-kit-zooms={clipId}> + <div className="flex flex-wrap items-center gap-1.5 text-[12px] text-text-2"> + <span>Zooms</span> + <button + type="button" + data-zoom-add={clipId} + disabled={busy || playhead === null} + onClick={() => write([...zooms, { at: Math.round((playhead ?? 0) * 100) / 100, scale: 1.3, hold: 1.5 }], "A zoom at the playhead")} + className={buttonVariants({ variant: "quiet", size: "sm" })} + title="push the picture in at the playhead (×1.3, held 1.5 s, about the picture's centre)" + > + Zoom here + </button> + </div> + {zooms.map((z, i) => ( + <div key={`${z.at}-${i}`} data-zoom-row={i} className="flex flex-wrap items-center gap-1.5 text-[12px] text-text-2"> + <span className="tabular-nums">{z.at.toFixed(2)} s</span> + {z.box ? ( + <span>a box</span> + ) : ( + <> + <select + data-zoom-scale={i} + value={String(z.scale ?? 1.3)} + disabled={busy} + onChange={(e) => change(i, { ...z, scale: Number(e.target.value) })} + className="rounded-[3px] border border-seam-2 bg-transparent px-1 py-0.5 text-[12px] text-text" + > + {["1.15", "1.3", "1.5", "1.8", "2"].map((v) => ( + <option key={v} value={v}> + ×{v} + </option> + ))} + </select> + <label className="flex items-center gap-1"> + focus + <input data-zoom-focus-x={i} type="number" min={0} max={100} step={5} value={Math.round((z.focus?.[0] ?? 0.5) * 100)} disabled={busy} onChange={(e) => change(i, { ...z, focus: [Number(e.target.value) / 100, z.focus?.[1] ?? 0.5] })} className="w-[4em] rounded-[3px] border border-seam-2 bg-transparent px-1 text-text" aria-label="focus, % across" /> + <input data-zoom-focus-y={i} type="number" min={0} max={100} step={5} value={Math.round((z.focus?.[1] ?? 0.5) * 100)} disabled={busy} onChange={(e) => change(i, { ...z, focus: [z.focus?.[0] ?? 0.5, Number(e.target.value) / 100] })} className="w-[4em] rounded-[3px] border border-seam-2 bg-transparent px-1 text-text" aria-label="focus, % down" />% + </label> + </> + )} + <label className="flex items-center gap-1"> + held + <input data-zoom-hold={i} type="number" min={0.3} max={10} step={0.1} value={z.hold ?? 1.5} disabled={busy} onChange={(e) => change(i, { ...z, hold: Number(e.target.value) })} className="w-[4em] rounded-[3px] border border-seam-2 bg-transparent px-1 text-text" />s + </label> + <button type="button" data-zoom-remove={i} disabled={busy} onClick={() => write(zooms.filter((_, j) => j !== i), "Took the zoom off")} className={buttonVariants({ variant: "quiet", size: "sm" })} aria-label="remove this zoom"> + × + </button> + </div> + ))} + </div> + ); +} + +// --------------------------------------------------------------------------- // New clip: a span of this clip's recording, its id, its quote (read from the // words or the cues as the span changes, until a person types one), Blur // picture -- inserted after this clip (the timeline route's `insert`). diff --git a/umtool/docs/cli.md b/umtool/docs/cli.md @@ -555,6 +555,8 @@ $U vertical emberparadox/mr-obvious --take mid-14 --reel short-die --reframe --j - **The channel promo:** when the take sets `render.promo`, the short's last clip ends on the streamer's card -- the picture dissolves into it over the clip's last seconds, its sound on under it and the captions over it, then it holds in silence (`--no-promo`, `--promo-lead`, `--promo-hold`; [knobs.md](knobs.md#the-channel-promo-the-card-a-clip-ends-on)). +- **Zooms:** a clip's `zooms` push its picture in at points, eased (`umtool set <p> <clip> zooms='[…]'`); refused past + the source's pixels unless the project allows a soft limit ([knobs.md](knobs.md#zoom-at-points-a-shorts-or-a-desktop-clips-picture-pushed-in)). - **A code on the short:** `--qr on` (or `--qr-corner tr|tl`) puts one at the top of the safe area, linking the source at the second each clip plays from ([knobs.md](knobs.md#a-clips-qr-its-corner-and-its-link)). - **Many clips, both formats, one command:** `umtool shorts` ([below](#make-promo-clips-a-batch-of-shorts)). diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -456,6 +456,34 @@ where, one template draws it 9:16 and 16:9. | one clip | the clip editor's **Short**: **End card** (the cut's / none) | `umtool set <p> <clip> promo=false` · `promo.hold=2` · `promo=` | | a short or a batch | the ⌘K forms **vertical**, **shorts** | `umtool vertical … [--no-promo] [--promo-lead 4.5] [--promo-fade 0.7] [--promo-hold 1.5]` · `umtool shorts … [--no-promo]` | +## Zoom at points (a short's or a desktop clip's picture pushed in) + +A clip built alone -- a short, a desktop clip, a batch's -- can push in on part of its picture for a moment, eased in +and out (lane clip-kit; `report-to-video/clip-zoom.mjs`). The push is in SOURCE space, before the layout: a short's +9:16 crop (`vertical.crop`) stays the same box, the focus keeps its place on screen and the picture grows around it. +The captions, the source line, the code and the promo card never zoom. A whole cut's punch-ins are the deck's +`fx.punchIn` (Effects), not these. + +**Sharp by default.** A layout already shows its source at some enlargement: a 1080 window fitted into a framed +short's 1080x608 box 0.56×, cut 9:16 to fill 1080x1920 1.78×, a desktop clip 1.0×. A zoom multiplies it. A zoom past +the source's own pixels is refused, by name, with the enlargement it would play at. With 1080 windows +(`render.tallWindows`) a framed short has room up to ×1.78 (720 windows: ×1.19); a full short and a desktop clip have +none. `render.zooms.maxScale` (up to 1.3) lets a project go that much past the sharp limit, and the build says how +much softer than its source each such zoom plays. + +| Knob | Values (default) | What it does | +|---|---|---| +| a clip's `zooms` | `[{at, hold?, scale?, focus?, box?, ramp?}]`, 1–8, none overlapping | `at` the source second the push starts; `hold` 0.3–10 s at full zoom (1.5); `scale` 1.05–3 (1.3) and `focus` `[x, y]` (fractions of the picture; its centre), or `box` `[x, y, w, h]`, the part of the picture to fill the frame with; `ramp` 0.2–1 s each way (0.4, smoothstep) | +| `render.zooms.maxScale` | 1–1.3 (absent: 1, strict) | how far past the source's pixels a zoom may go | + +| | In umtool | From a terminal | +|---|---|---| +| a zoom | the clip editor's **Short**: **Zoom here** (at the playhead), its scale, focus (%) and hold; × takes it off | `umtool set <p> <clip> zooms='[{"at":231.4,"scale":1.3,"focus":[0.7,0.35]}]'` (`zooms=` none) | +| the soft limit | Build, **Look**: **Zooms** (never / up to ×1.15 / up to ×1.3 soft) | `umtool look <p> zooms='{"maxScale":1.3}'` (`zooms=` strict) | + +The cut record names each zoom drawn (`zooms: [{at, scale, focus, hold, ramp, enlargement}]`, `at` on the segment's +clock). + ## 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 @@ -86,6 +86,17 @@ test("the clip editor: a clip's own QR corner, its end card off and back, the pr await expect.poll(() => clip("r001")?.promo).toBe(false); await page.locator("[data-kit-promo='r001']").selectOption("cut"); await expect.poll(() => clip("r001") && "promo" in clip("r001")).toBe(false); + // A zoom at the playhead (slice F): added, its scale changed, taken off. + await expect(page.locator("[data-editor-player]")).toHaveAttribute("data-editor-player", /^(?!looking|none)/, { timeout: 20_000 }); + await page.locator("body").press("l"); + await expect(page.locator("[data-zoom-add='r001']")).toBeEnabled(); + await page.locator("[data-zoom-add='r001']").click(); + await expect.poll(() => clip("r001")?.zooms?.length ?? 0).toBe(1); + expect(clip("r001").zooms[0]).toMatchObject({ scale: 1.3, hold: 1.5 }); + await page.locator("[data-zoom-scale='0']").selectOption("1.5"); + 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); // 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/report/clipEditorTypes.ts b/umtool/lib/report/clipEditorTypes.ts @@ -30,7 +30,7 @@ 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 }; [k: string]: unknown }; + kit?: { qr?: false | { corner?: string; links?: string }; name?: string; promo?: false | { lead?: number; fade?: number; hold?: number }; zooms?: unknown[]; [k: string]: unknown }; /** 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; diff --git a/umtool/lib/report/clipKit.test.mjs b/umtool/lib/report/clipKit.test.mjs @@ -69,3 +69,20 @@ test("the channel promo written: the look's (checked by the build's rules) and a await rm(dir, { recursive: true, force: true }); } }); + +test("a clip's zooms written: whole, checked against its window and each other; [] or null clears", async () => { + const dir = await mkdtemp(path.join(tmpdir(), "umtool-zooms-")); + try { + await writeFile(path.join(dir, MANIFEST_NAME), JSON.stringify(manifest(), null, 2) + "\n"); + await updateClip(dir, "w01", { zooms: [{ at: 12, scale: 1.5, focus: [0.7, 0.3] }] }); + assert.deepEqual((await read(dir)).zooms, [{ at: 12, scale: 1.5, focus: [0.7, 0.3] }]); + await assert.rejects(updateClip(dir, "w01", { zooms: [{ at: 19 }] }), /w01\.zooms\[0\] \(19–21\.3 s\) runs outside the clip's window \(10–20\)/); + await assert.rejects(updateClip(dir, "w01", { zooms: [{ at: 11 }, { at: 12 }] }), /starts before the one at 11 s is out again/); + await updateClip(dir, "w01", { zooms: [] }); + assert.equal("zooms" in (await read(dir)), false); + await assert.rejects(updateRender(dir, { zooms: { maxScale: 2 } }), /maxScale is 1–1\.3/); + assert.deepEqual((await updateRender(dir, { zooms: { maxScale: 1.3 } })).look.zooms, { maxScale: 1.3 }); + } finally { + await rm(dir, { 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"]); +export const KIT_SET_KEYS = Object.freeze(["qr", "qr.corner", "qr.links", "name", "promo", "promo.lead", "promo.fade", "promo.hold", "zooms"]); 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", @@ -124,6 +124,8 @@ export const SET_USAGE = [ " shorts (umtool shorts) are called that, not its title's slug; `name=` the title's again.", " promo=false: a per-clip build of this clip ends without the channel promo (render.promo); promo.lead /", " promo.fade / promo.hold (seconds) its own timing over the cut's; `promo=` the cut's again.", + " zooms='[{\"at\":231.4,\"scale\":1.3,\"focus\":[0.7,0.35],\"hold\":1.5}]' pushes a short's or a desktop clip's", + " picture in at those source seconds (or \"box\":[x,y,w,h] to fill the frame with); `zooms=` none.", " 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`.", @@ -367,6 +369,7 @@ export async function setCommand(args, { root = REPORTS_ROOT, out = (s) => conso if (["qr", "qr.corner", "qr.links"].some((k) => k in entryPatch)) results.qr = result.entry.qr ?? null; 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 (FX_KEYS.some((k) => k in entryPatch)) results.fx = result.entry.fx ?? null; if ("gaps" in entryPatch || "gapAdd" in entryPatch || "gapRemove" in entryPatch) { results.gaps = result.entry.gaps ?? []; @@ -405,6 +408,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 ("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"}`); if ("name" in results) out(`${clipId}: name ${results.name ? JSON.stringify(results.name) : "its title's slug"}`); if ("gaps" in results) out(`${clipId}: ${results.gaps.length ? `gaps ${results.gaps.map((g) => `${g.from}–${g.to}`).join(", ")}` : "no gaps (the cut plays whole)"}`); 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"]); + assert.deepEqual(LOOK_KEYS, ["headerHeight", "footerHeight", "qr", "transition", "transitionStyle", "loudness", "captions", "room", "slide", "blur", "intro", "format", "vertical", "mode", "basic", "tallWindows", "desktop", "promo", "zooms"]); 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 @@ -40,6 +40,7 @@ import { validateAssist } from "yt-dlp-transcript-common/lib/clips/assist.mjs"; 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"; /** 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"; @@ -869,7 +870,7 @@ export function patchClipEntry(manifest, clipId, patch, { edit = "trim", now = n if (v === null || v === "") delete next[f]; else next[f] = v; } - if (next === null || (isObj(next) && !Object.keys(next).length)) delete entry[key]; + if (next === null || (isObj(next) && !Object.keys(next).length) || (Array.isArray(next) && !next.length)) delete entry[key]; else entry[key] = typeof next === "string" ? next.trim() : next; const errors = clipKitErrors(entry, clipId); if (errors.length) throw new Error(errors.join("; ")); @@ -1914,6 +1915,8 @@ export async function updateRender(dir, patch, { token = null } = {}) { const { render, errors } = applyLookPatch(manifest, patch); // The channel promo (report-to-video promo-card.mjs) and the clip kit's QR: the build's own rules. 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)); 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 }); + assert.deepEqual(snapshotOf(e, PROJECT_KEYS), { vertical: { crop: [0.6, 0, 0.3164, 1] }, side: null, qr: null, promo: null, zooms: 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] } }); @@ -118,7 +118,7 @@ test("umtool shorts: each clip in each format into shorts-<take>/, named, record assert.deepEqual(files, ["batch.json", "toms-toast-w01.landscape.mp4", "toms-toast-w01.vertical.mp4", "toms-toast.landscape.mp4", "toms-toast.vertical.mp4"]); // The builder was asked one clip at a time, with the flags' knobs and each format's cap. assert.deepEqual(calls.map((c) => [c.items[0], c.landscape, c.knobs.maxSeconds, c.knobs.clip]), [["m01", false, 180, "framed"], ["m01", true, 140, "framed"], ["w01", false, 180, "framed"], ["w01", true, 140, "framed"]]); - assert.deepEqual(calls[2].overrides, { w01: { vertical: { crop: [0.6, 0, 0.3164, 1] }, side: null, qr: null, promo: null } }); + assert.deepEqual(calls[2].overrides, { w01: { vertical: { crop: [0.6, 0, 0.3164, 1] }, side: null, qr: null, promo: null, zooms: 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 @@ -232,13 +232,15 @@ import { clipGeometry, clipVerticalLayout, landscapeSideGeometry, landscapeSideOverlay, sidePostOf, sideSpan, sourceTagText, sectionTitlesOf, validateVerticalRender, verticalAss, verticalClipGraph, verticalHookOf, verticalNotes, verticalOn, verticalPostBox, verticalPostEntry, verticalRender, safeArea, - desktopGeometry, desktopHookOf, desktopKnobs, desktopRender, desktopSafeArea, validateDesktopRender, + desktopGeometry, desktopHookOf, desktopKnobs, desktopRender, desktopSafeArea, validateDesktopRender, pictureRegion, } from "./vertical.mjs"; import { renderSideCard, sideFitFilter } from "./side-card.mjs"; // THE CLIP KIT (lane clip-kit): a per-clip build's code -- its corner, its link (clip-kit.mjs). import { clipQrUrl, cornerOverlayXY, cornerQrOf, desktopQrBox, desktopQrOf, validateClipKit, verticalQrBox, verticalQrOf } from "./clip-kit.mjs"; // THE CHANNEL PROMO (lane clip-kit, slice D): the card a per-clip build ends on (promo-card.mjs). 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"; // 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"; @@ -1858,8 +1860,19 @@ async function buildClipSegment(entry, meta, render, dirs, opts, chrome, nodes, next += 1; } const g = gapped(ain); + // Its zooms (clip-zoom.mjs): in source space, after the blur, before the layout cuts it; refused past their + // limit by name, said when softer than the source. + let zoom = []; + if (Array.isArray(entry.zooms) && entry.zooms.length) { + const { region, rest } = pictureRegion(geo, sw, sh, entry.vertical?.crop ?? null); + const z = resolveZooms(entry, { from: cutRecord.start, gaps: cutRecord.gaps ?? [], srcW: sw, srcH: sh, region, rest, maxScale: render.zooms?.maxScale ?? 1, seconds: segSeconds }); + if (z.errors.length) throw new Error(`zooms: ${z.errors.join("; ")}`); + for (const message of z.notes) EMIT("note", { message }); + zoom = zoomFilters(z.zooms, { srcW: sw, srcH: sh, fps: render.fps }); + if (z.zooms.length) cutRecord.zooms = z.zooms.map((x) => ({ at: Number(x.at.toFixed(3)), scale: Number(x.scale.toFixed(3)), focus: x.focus.map((n) => Number(n.toFixed(4))), hold: x.hold, ramp: x.ramp, enlargement: Number((rest * x.scale).toFixed(3)) })); + } const graph = verticalClipGraph({ - geo, srcW: sw, srcH: sh, crop: entry.vertical?.crop ?? null, blur: await blurPicture(sw, sh), side, fps: render.fps, W: width, H: height, + geo, srcW: sw, srcH: sh, crop: entry.vertical?.crop ?? null, blur: [...(await blurPicture(sw, sh)), ...zoom], side, fps: render.fps, W: width, H: height, }); const tag = sourceTagText({ channel: channelName(entry, meta, provenance), date: entry.date ?? uploadDateToIso(meta.uploadDate) }); // The promo's timing for the captions (the card itself is drawn below): from when, over how long, into which band. @@ -6929,7 +6942,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), + ...validateGapEntries(whole), ...measureSettingsProblems(whole), ...validateAnalysisEntries(whole), ...validateClipKit(whole), ...validatePromo(whole), ...validateZooms(whole), ]; if (errors.length) throw new Error(`manifest: ${errors.join("; ")}`); } diff --git a/umtool/report-to-video/clip-kit-render.test.mjs b/umtool/report-to-video/clip-kit-render.test.mjs @@ -20,6 +20,12 @@ const { MONO_BOLD_FONT_FILE, MONO_FONT_FILE } = await import("./brand.mjs"); const { desktopQrBox, verticalQrBox } = await import("./clip-kit.mjs"); const { clipGeometry, desktopSafeArea, safeArea } = await import("./vertical.mjs"); +// Every module this file reads, loaded before the first test is declared: a test declared after a top-level await +// can start after the root's after-hook has removed the corpus (node:test ends the root once its queue is empty). +const { probeDuration } = await import("./build-video.mjs"); +const { promoBand } = await import("./promo-card.mjs"); +const havePw = await import("@playwright/test").then((m) => !!(m.chromium ?? m.default?.chromium), () => false); + test.after(() => rm(CORPUS, { recursive: true, force: true })); const have = ["ffmpeg", "ffprobe", "qrencode"].every((b) => spawnSync(b, b === "qrencode" ? ["--version"] : ["-version"]).status === 0); @@ -131,9 +137,6 @@ test("a short's code: at the top right of the safe area; none unless asked, the }); // ---- slice D: the channel promo ------------------------------------------------------------------------------------- -const { probeDuration } = await import("./build-video.mjs"); -const { promoBand } = await import("./promo-card.mjs"); -const havePw = await import("@playwright/test").then((m) => !!(m.chromium ?? m.default?.chromium), () => false); /** The picture's mean luma at `t` s. */ function yavg(file, t) { @@ -204,3 +207,43 @@ test("the promo: a clip's `promo: false` ends without it, exactly as a cut that for (const p of ps) await rm(p.root, { recursive: true, force: true }); } }); + +// ---- slice F: zoom at points ---------------------------------------------------------------------------------------- +/** The mean luma of a box of a frame `t` s in. */ +function boxAvg(file, box, t) { + const r = spawnSync("ffmpeg", ["-v", "error", "-ss", String(t), "-i", file, "-frames:v", "1", "-vf", `crop=${box.w}:${box.h}:${box.x}:${box.y},signalstats,metadata=print:file=-`, "-f", "null", "-"], { maxBuffer: 1 << 24 }); + return Number((/lavfi\.signalstats\.YAVG=([0-9.]+)/.exec(String(r.stdout)) ?? [])[1]); +} + +test("a zoom: the framed short's picture pushed in on its focus for its span, eased back out; refused past the sharp limit", { skip: !have && "needs ffmpeg and qrencode" }, async () => { + quiet(); + // A window whose left half is white and right half black: pushed in on its left edge, the picture is mostly white. + const p = await project({ render: { vertical: { clip: "framed" } }, clip: { zooms: [{ at: 1.5, scale: 1.75, focus: [0, 0.5], hold: 1, ramp: 0.3 }] } }); + 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=black:s=1920x1080:r=${FPS}:d=6`, "-f", "lavfi", "-i", "sine=frequency=440:sample_rate=48000:duration=6", + "-filter_complex", "[0:v]drawbox=x=0:y=0:w=960: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)); + try { + await buildVideo({ manifestPath: p.manifestPath, opts: { noNetwork: true, vertical: true, verticalOut: path.join(p.root, "out", "kit.vertical.mp4") } }); + const seg = path.join(p.root, "out", "vertical", "segments", "c1.mp4"); + const rec = JSON.parse(await readFile(seg.replace(/\.mp4$/, ".cut.json"), "utf8")); + assert.deepEqual([rec.zooms[0].at, rec.zooms[0].scale, rec.zooms[0].focus], [0.5, 1.75, [0, 0.5]]); + const v = clipGeometry("framed", { format: "vertical" }, 1080, 1920).video; + const box = { x: 0, y: v.y + 40, w: 1080, h: v.h - 80 }; + const before = boxAvg(seg, box, 0.2); + const pushed = boxAvg(seg, box, 1.3); + const after = boxAvg(seg, box, 2.6); + assert.ok(before > 100 && before < 150, `half white before (${before})`); + assert.ok(pushed > 180, `pushed in on the white (${pushed})`); + assert.ok(Math.abs(after - before) < 12, `back out after (${after} vs ${before})`); + // Past the sharp limit (a 1080 window in a full 9:16 crop is already past its pixels): refused, by name. + const m = JSON.parse(await readFile(p.manifestPath, "utf8")); + m.render.vertical = { clip: "full" }; + await writeFile(p.manifestPath, JSON.stringify(m)); + await assert.rejects(buildVideo({ manifestPath: p.manifestPath, opts: { noNetwork: true, vertical: true, verticalOut: path.join(p.root, "out", "kit2.vertical.mp4") } }), /zooms: c1: the zoom at 1\.5 s \(×1\.75\) plays its source at .* the limit here is ×1/); + } finally { + 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 @@ -24,6 +24,7 @@ import { VOD_RETENTION_DAYS, seekPlatformOfUrl } from "yt-dlp-transcript-common/ import { DESKTOP_QR_CORNERS, DESKTOP_QR_SIZE, QR_LINKS, VERTICAL_QR_CORNERS, VERTICAL_QR_KEYS, VERTICAL_QR_SIZE, desktopKnobs, verticalQrErrors } from "yt-dlp-transcript-common/lib/report/vertical.mjs"; import { archiveMomentUrl } from "./site-links.mjs"; import { clipPromoErrors } from "./promo-card.mjs"; +import { zoomsErrors } from "./clip-zoom.mjs"; const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); const q = (v) => JSON.stringify(v); @@ -34,7 +35,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"]); +export const CLIP_KIT_KEYS = Object.freeze(["qr", "name", "promo", "zooms"]); /** A clip's pinned file name in a batch (shortsBatch.mjs): at most this many characters. */ export const CLIP_NAME_MAX = 60; @@ -64,8 +65,10 @@ export function clipKitErrors(entry, where = "clip") { } // Its channel promo (promo-card.mjs): false, or its own timing. errors.push(...clipPromoErrors(entry.promo, `${where}.promo`)); - if ((entry.qr !== undefined || entry.name !== undefined || entry.promo !== undefined) && entry.type !== undefined && entry.type !== "clip") { - errors.push(`${where}: qr, name and promo are a clip's`); + // Its zooms (clip-zoom.mjs), against its window. + errors.push(...zoomsErrors(entry.zooms, `${where}.zooms`, entry)); + if ((entry.qr !== undefined || entry.name !== undefined || entry.promo !== undefined || entry.zooms !== undefined) && entry.type !== undefined && entry.type !== "clip") { + errors.push(`${where}: qr, name, promo and zooms 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 and promo are a clip's/); + assert.match(clipKitErrors({ type: "post", qr: false }, "p1").join(), /qr, name, promo and zooms 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/clip-zoom.mjs b/umtool/report-to-video/clip-zoom.mjs @@ -0,0 +1,178 @@ +// ZOOM AT POINTS in a per-clip build (lane clip-kit, slice F): a clip of a short or a desktop clip pushes in on a +// part of its picture for a moment, eased in and out -- the operator: "we may want to zoom in at points". +// +// clip.zooms [{ at, hold?, scale?, focus?: [x, y], box?: [x, y, w, h], ramp? }] 1 to 8, none overlapping +// at the source second the push starts (inside the clip's window; gap-aware) +// hold seconds held at full zoom (0.3–10; 1.5) +// scale how far in (1.05–3; 1.3) -- or `box`, the part of the SOURCE picture to fill the frame with +// focus the point that stays where it is on screen, fractions of the source picture ([0.5, 0.5]; a box's +// centre) +// ramp the ease in, and out again (0.2–1 s; 0.4; smoothstep) +// render.zooms { maxScale?: 1–1.3 } how far past the source's own pixels a zoom may go (absent: 1, strict) +// +// IN SOURCE SPACE, BEFORE THE LAYOUT. The picture is pushed in about `focus` and the layout then cuts it as it always +// does: a short's 9:16 crop (`vertical.crop`) is the same box, the focus keeps its place on screen and the picture +// grows around it; a desktop clip's full frame likewise. Captions, the source line, the code and the promo card are +// drawn after it and never zoom. +// +// SHARP. A layout already shows its source at some enlargement (a 1080 window fitted into the 1080x608 box of a +// framed short: 0.56; cropped 9:16 to fill 1080x1920: 1.78; a desktop clip: 1.0). A zoom multiplies it. The sharp +// limit is the scale at which the picture reaches the source's own pixels: max(1, 1 / rest). Past it is refused, +// by name -- unless the project allows a SOFT zoom, `render.zooms.maxScale` (up to 1.3 times the sharp limit), and +// then the build says how much softer than its source the zoom plays. +// +// PURE: no fs, no ffmpeg run. The build (build-video.mjs) draws it with ffmpeg's zoompan. +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 ZOOM_KEYS = Object.freeze(["at", "hold", "scale", "focus", "box", "ramp"]); +export const ZOOM_LIMITS = Object.freeze({ + hold: Object.freeze({ min: 0.3, max: 10, default: 1.5 }), + scale: Object.freeze({ min: 1.05, max: 3, default: 1.3 }), + ramp: Object.freeze({ min: 0.2, max: 1, default: 0.4 }), +}); +export const ZOOMS_MAX = 8; +/** `render.zooms.maxScale`: the soft limit, times the sharp limit (1: strict). */ +export const ZOOM_SOFT = Object.freeze({ min: 1, max: 1.3, default: 1 }); + +/** A zoom's span on a clock: from `at`, eased in over `ramp`, held, eased out over `ramp`. */ +export const zoomEnd = (z) => z.at + 2 * (z.ramp ?? ZOOM_LIMITS.ramp.default) + (z.hold ?? ZOOM_LIMITS.hold.default); + +/** Each thing wrong with a clip's `zooms` ([] when fine, or absent). `entry` its window (start, end), when known. */ +export function zoomsErrors(zooms, where = "clip.zooms", entry = null) { + if (zooms === undefined) return []; + if (!Array.isArray(zooms) || !zooms.length || zooms.length > ZOOMS_MAX) return [`${where} is a list of 1 to ${ZOOMS_MAX} zooms [{at, hold?, scale?, focus?, box?, ramp?}]`]; + const errors = []; + zooms.forEach((z, i) => { + const w = `${where}[${i}]`; + if (!isObj(z)) return errors.push(`${w} is {at, hold?, scale?, focus?, box?, ramp?}`); + for (const k of Object.keys(z)) if (!ZOOM_KEYS.includes(k)) errors.push(`${w}.${k} is not a key (${ZOOM_KEYS.join(", ")})`); + if (!num(z.at) || z.at < 0) errors.push(`${w}.at is a source second`); + else if (entry && num(entry.start) && num(entry.end) && (z.at < entry.start - 0.02 || zoomEnd(z) > entry.end + 0.02)) { + errors.push(`${w} (${z.at}–${Math.round(zoomEnd(z) * 100) / 100} s) runs outside the clip's window (${entry.start}–${entry.end})`); + } + for (const [k, b] of Object.entries(ZOOM_LIMITS)) if (z[k] !== undefined && !(num(z[k]) && z[k] >= b.min && z[k] <= b.max)) errors.push(`${w}.${k} is ${b.min}–${b.max}`); + if (z.focus !== undefined && !(Array.isArray(z.focus) && z.focus.length === 2 && z.focus.every((n) => num(n) && n >= 0 && n <= 1))) errors.push(`${w}.focus is [x, y], fractions of the picture`); + if (z.box !== undefined) { + const b = z.box; + if (!(Array.isArray(b) && b.length === 4 && b.every(num) && b[2] > 0.02 && b[3] > 0.02 && b[0] >= 0 && b[1] >= 0 && b[0] + b[2] <= 1.001 && b[1] + b[3] <= 1.001)) errors.push(`${w}.box is [x, y, w, h], fractions of the picture inside it`); + if (z.scale !== undefined || z.focus !== undefined) errors.push(`${w}: a box says its own scale and focus -- give box, or scale and focus`); + } + }); + const ok = zooms.filter((z) => isObj(z) && num(z.at)).sort((a, b) => a.at - b.at); + for (let i = 1; i < ok.length; i += 1) { + if (ok[i].at < zoomEnd(ok[i - 1]) - 1e-6) errors.push(`${where}: the zoom at ${ok[i].at} s starts before the one at ${ok[i - 1].at} s is out again (${Math.round(zoomEnd(ok[i - 1]) * 100) / 100} s)`); + } + return errors; +} + +/** Each thing wrong with `render.zooms` ([] when fine, or absent). */ +export function renderZoomsErrors(v, where = "render.zooms") { + if (v === undefined || v === null) return []; + if (!isObj(v)) return [`${where} is {maxScale}`]; + const errors = []; + for (const k of Object.keys(v)) if (k !== "maxScale") errors.push(`${where}.${k} is not a key (maxScale)`); + if (v.maxScale !== undefined && !(num(v.maxScale) && v.maxScale >= ZOOM_SOFT.min && v.maxScale <= ZOOM_SOFT.max)) { + errors.push(`${where}.maxScale is ${ZOOM_SOFT.min}–${ZOOM_SOFT.max}: how far past the source's own pixels a zoom may go (1: never)`); + } + return errors; +} + +/** Every reason a manifest's zooms cannot be drawn. */ +export function validateZooms(manifest) { + const errors = renderZoomsErrors(manifest?.render?.zooms); + for (const e of manifest?.timeline ?? []) { + if (e?.zooms === undefined) continue; + if (e.type !== "clip") errors.push(`timeline ${e.id ?? "?"}: zooms are a clip's`); + else errors.push(...zoomsErrors(e.zooms, `timeline ${e.id}.zooms`, e)); + } + return errors; +} + +/** + * The enlargement a layout shows its source at, before any zoom: the frame's pixels over the source's for the part + * of the source it shows. `region` that part ({w, h}, px of the source); `box` the frame's box it fills ({w, h}). + * A fitted picture is the smaller ratio. + */ +export const restEnlargement = (region, box) => Math.min(box.w / region.w, box.h / region.h); + +/** The sharp limit: the zoom at which the picture reaches its source's own pixels (never under 1). */ +export const sharpLimit = (rest) => Math.max(1, 1 / rest); + +/** + * Each zoom resolved for a segment (PURE): its clock in the segment's seconds (`from` the source second it starts at, + * `gaps` the cut's), its scale (a box's derived from the region the layout shows) and focus, and how sharp it plays. + * `region` px of the source the layout shows ({x, y, w, h}); `rest` its enlargement; `maxScale` the soft limit. + * Returns `{zooms, errors, notes}`: a zoom past its limit is an error naming it, one past the sharp limit (soft, + * allowed) a note. + */ +export function resolveZooms(entry, { from, gaps = [], srcW, srcH, region, rest, maxScale = 1, seconds = Infinity, id = entry?.id ?? "clip" }) { + const zooms = []; + const errors = []; + const notes = []; + const sharp = sharpLimit(rest); + const ceiling = sharp * Math.max(1, Math.min(ZOOM_SOFT.max, maxScale)); + const round = (n) => Math.round(n * 100) / 100; + for (const z of Array.isArray(entry?.zooms) ? entry.zooms : []) { + const ramp = z.ramp ?? ZOOM_LIMITS.ramp.default; + const hold = z.hold ?? ZOOM_LIMITS.hold.default; + let scale = z.scale ?? ZOOM_LIMITS.scale.default; + let focus = Array.isArray(z.focus) ? z.focus : null; + if (Array.isArray(z.box)) { + const [bx, by, bw, bh] = z.box; + scale = Math.min(region.w / (bw * srcW), region.h / (bh * srcH)); + focus = [bx + bw / 2, by + bh / 2]; + } + focus ??= [(region.x + region.w / 2) / srcW, (region.y + region.h / 2) / srcH]; + const at = offsetIn(z.at, from, gaps); + const what = `${id}: the zoom at ${z.at} s (×${round(scale)})`; + // A push outside what this segment plays (a cut tighter than its window, a reel's part): not drawn, said. + if (at < -0.05 || at + 2 * ramp + hold > seconds + 0.05) { + notes.push(`${what} is outside what plays here (${round(from)} s on, ${round(seconds)} s) -- left out`); + continue; + } + if (scale <= 1.001) { + notes.push(`${what} shows no more than the layout already does -- left out`); + continue; + } + if (scale > ceiling + 1e-6) { + const ways = ["a smaller zoom", "a sharper source (render.tallWindows)", ...(maxScale < ZOOM_SOFT.max ? [`a soft limit (umtool look <p> zooms='{"maxScale":${ZOOM_SOFT.max}}')`] : [])]; + errors.push(`${what} plays its source at ${round(rest * scale)}× its pixels; the limit here is ×${round(ceiling)} (${maxScale > 1 ? `render.zooms.maxScale ${maxScale} times ` : ""}the sharp ×${round(sharp)}) -- ${ways.join(", ")}`); + continue; + } + if (rest * scale > 1.001) notes.push(`${what} plays softer than its source: ${round(rest * scale)}× its pixels`); + zooms.push({ at: Math.max(0, at), ramp, hold, scale, focus }); + } + return { zooms, errors, notes }; +} + +const f = (n) => Number(n).toFixed(4); + +/** The eased zoom of one push at `t` (an ffmpeg expression): 0 outside it, smoothstep up, held, smoothstep down. */ +function pushExpr(z, t) { + const a = z.at; + const b = a + z.ramp; + const c = b + z.hold; + const d = c + z.ramp; + const up = `((${t}-${f(a)})/${f(z.ramp)})`; + const down = `((${f(d)}-${t})/${f(z.ramp)})`; + const ease = (u) => `(${u}*${u}*(3-2*${u}))`; + return `if(between(${t},${f(a)},${f(d)}),${f(z.scale - 1)}*if(lt(${t},${f(b)}),${ease(up)},if(lt(${t},${f(c)}),1,${ease(down)})),0)`; +} + +/** + * The zoom as ONE ffmpeg filter chain on the source picture (PURE): its frames at `fps`, then zoompan with the zoom + * and the focus kept in place (each push its own focus; between them, none). Empty when there are no zooms. + */ +export function zoomFilters(zooms, { srcW, srcH, fps }) { + if (!zooms?.length) return []; + const t = "it"; + const Z = `(1+${zooms.map((z) => pushExpr(z, t)).join("+")})`; + // The focus of the push under way (a nested choice by span); outside every push the zoom is 1 and it does not matter. + const pick = (k) => zooms.reduceRight((acc, z) => `if(between(${t},${f(z.at)},${f(zoomEnd(z))}),${f(z.focus[k])},${acc})`, "0.5"); + const x = `${pick(0)}*iw*(1-1/zoom)`; + const y = `${pick(1)}*ih*(1-1/zoom)`; + return [`fps=${fps}`, `zoompan=z='${Z}':x='${x}':y='${y}':d=1:s=${srcW}x${srcH}:fps=${fps}`]; +} diff --git a/umtool/report-to-video/clip-zoom.test.mjs b/umtool/report-to-video/clip-zoom.test.mjs @@ -0,0 +1,75 @@ +// Zoom at points (lane clip-kit, slice F): the rules, the sharp and the soft limits, the eased expression. +import { test } from "node:test"; +import assert from "node:assert/strict"; + +import { renderZoomsErrors, resolveZooms, restEnlargement, sharpLimit, validateZooms, zoomEnd, zoomFilters, zoomsErrors } from "./clip-zoom.mjs"; +import { clipGeometry, desktopGeometry, pictureRegion } from "./vertical.mjs"; + +const clip = (zooms, o = {}) => ({ type: "clip", id: "c1", start: 10, end: 40, zooms, ...o }); + +test("the rules: a list of 1 to 8, inside the window, none overlapping; a box or a scale and focus", () => { + assert.deepEqual(zoomsErrors([{ at: 12 }, { at: 20, scale: 1.5, focus: [0.7, 0.3], hold: 2, ramp: 0.3 }, { at: 30, box: [0.5, 0, 0.3, 0.4] }], "z", clip()), []); + const no = (z, re) => assert.match(zoomsErrors(z, "z", clip()).join("\n"), re, JSON.stringify(z)); + no([], /a list of 1 to 8/); + no(Array.from({ length: 9 }, (_, i) => ({ at: 11 + i * 3 })), /a list of 1 to 8/); + no([{ at: 39.5 }], /runs outside the clip's window/); + no([{ at: 12, scale: 5 }], /scale is 1\.05–3/); + no([{ at: 12, focus: [2, 0] }], /focus is \[x, y\]/); + no([{ at: 12, box: [0.9, 0, 0.3, 0.3] }], /box is \[x, y, w, h\]/); + no([{ at: 12, box: [0.1, 0, 0.3, 0.3], scale: 2 }], /a box says its own scale/); + no([{ at: 12 }, { at: 13 }], /starts before the one at 12 s is out again \(14\.3 s\)/); + no([{ at: 12, wobble: 1 }], /wobble is not a key/); + assert.equal(zoomEnd({ at: 12 }), 14.3); + assert.deepEqual(renderZoomsErrors({ maxScale: 1.3 }), []); + assert.match(renderZoomsErrors({ maxScale: 2 }).join(), /maxScale is 1–1\.3/); + assert.match(validateZooms({ render: {}, timeline: [{ type: "post", id: "p", zooms: [{ at: 1 }] }] }).join(), /zooms are a clip's/); +}); + +test("sharp: a layout's rest enlargement, the sharp limit -- a framed short has room, a desktop clip and a full short none", () => { + const W = 1080, H = 1920; + const framed = pictureRegion(clipGeometry("framed", {}, W, H), 1920, 1080); + assert.equal(Math.round(framed.rest * 1000) / 1000, 0.563); + assert.equal(Math.round(sharpLimit(framed.rest) * 100) / 100, 1.78); + const full = pictureRegion(clipGeometry("full", {}, W, H), 1920, 1080); + assert.ok(full.rest > 1.7 && sharpLimit(full.rest) === 1, "a full short is already past its pixels"); + const desk = pictureRegion(desktopGeometry({}, 1920, 1080), 1920, 1080); + assert.equal(desk.rest, 1); + // 720 windows: a framed short's room is 1.18. + assert.equal(Math.round(sharpLimit(pictureRegion(clipGeometry("framed", {}, W, H), 1280, 720).rest) * 100) / 100, 1.19); + assert.equal(restEnlargement({ w: 100, h: 100 }, { w: 200, h: 150 }), 1.5); +}); + +test("resolved: refused past the limit by name; a soft limit lets it through with a note; a box's scale and focus", () => { + const desk = pictureRegion(desktopGeometry({}, 1920, 1080), 1920, 1080); + const base = { from: 10, srcW: 1920, srcH: 1080, region: desk.region, rest: desk.rest, seconds: 30 }; + const strict = resolveZooms(clip([{ at: 12, scale: 1.2 }]), base); + assert.equal(strict.zooms.length, 0); + assert.match(strict.errors[0], /c1: the zoom at 12 s \(×1\.2\) plays its source at 1\.2× its pixels; the limit here is ×1 .*soft limit/); + const soft = resolveZooms(clip([{ at: 12, scale: 1.2 }]), { ...base, maxScale: 1.3 }); + assert.deepEqual(soft.errors, []); + assert.match(soft.notes[0], /plays softer than its source: 1\.2× its pixels/); + assert.equal(soft.zooms[0].at, 2, "on the segment's clock"); + assert.match(resolveZooms(clip([{ at: 12, scale: 1.4 }]), { ...base, maxScale: 1.3 }).errors[0], /limit here is ×1\.3 .*sharper source \(render\.tallWindows\)$/); + // A framed short: 1.5 is sharp, no note. + const fr = pictureRegion(clipGeometry("framed", {}, 1080, 1920), 1920, 1080); + const sharp = resolveZooms(clip([{ at: 12, scale: 1.5 }]), { ...base, region: fr.region, rest: fr.rest }); + assert.deepEqual([sharp.errors, sharp.notes, sharp.zooms[0].focus], [[], [], [0.5, 0.5]]); + // A box: its centre the focus, the scale that fills the region with it. + const box = resolveZooms(clip([{ at: 12, box: [0.4, 0.4, 0.6, 0.6] }]), { ...base, region: fr.region, rest: fr.rest }); + assert.deepEqual([Math.round(box.zooms[0].scale * 1000) / 1000, box.zooms[0].focus.map((n) => Math.round(n * 100) / 100)], [1.667, [0.7, 0.7]]); + // A box too small for the source's pixels: refused like any zoom past its limit. + assert.match(resolveZooms(clip([{ at: 12, box: [0.5, 0.5, 0.5, 0.5] }]), { ...base, region: fr.region, rest: fr.rest }).errors[0], /×2\) plays its source at 1\.13× its pixels/); + // Outside what plays (the cut later than the window): left out, said. + const out = resolveZooms(clip([{ at: 12 }]), { ...base, from: 13, region: fr.region, rest: fr.rest }); + assert.deepEqual([out.zooms.length, /outside what plays/.test(out.notes[0])], [0, true]); +}); + +test("the filter: frames at the cut's rate, zoompan eased by smoothstep about each push's focus; none without zooms", () => { + assert.deepEqual(zoomFilters([], { srcW: 1920, srcH: 1080, fps: 30 }), []); + const [fps, zp] = zoomFilters([{ at: 2, ramp: 0.4, hold: 1.5, scale: 1.5, focus: [0.75, 0.3] }], { srcW: 1920, srcH: 1080, fps: 30 }); + assert.equal(fps, "fps=30"); + assert.match(zp, /^zoompan=z='\(1\+if\(between\(it,2\.0000,4\.3000\),0\.5000\*if\(lt\(it,2\.4000\),/); + assert.match(zp, /\*\(3-2\*/, "smoothstep"); + assert.match(zp, /:x='if\(between\(it,2\.0000,4\.3000\),0\.7500,0\.5\)\*iw\*\(1-1\/zoom\)'/); + assert.match(zp, /:d=1:s=1920x1080:fps=30$/); +}); diff --git a/umtool/report-to-video/lint.mjs b/umtool/report-to-video/lint.mjs @@ -125,6 +125,7 @@ import { qrUrlFor } from "./render-cards.mjs"; import { archiveMomentUrl } from "./site-links.mjs"; import { clipQrUrl, cornerQrOf, desktopQrOf, expiringLinkNote, validateClipKit, verticalQrOf } from "./clip-kit.mjs"; import { validatePromo } from "./promo-card.mjs"; +import { validateZooms } from "./clip-zoom.mjs"; import { cardNarrationSeconds, hasNarration, narrationsOf, validateNarration } from "./narration.mjs"; import { validatePodcast } from "./build-podcast.mjs"; import { draftsReviewFromNarration, draftsReviewProblems, readDraftsReview } from "./drafts-review.mjs"; @@ -364,7 +365,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), + ...validateClipKit(whole), ...validatePromo(whole), ...validateZooms(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 @@ -30,6 +30,7 @@ "./vertical-plan": "./vertical-plan.mjs", "./clip-kit": "./clip-kit.mjs", "./promo-card": "./promo-card.mjs", + "./clip-zoom": "./clip-zoom.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 @@ -39,7 +39,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"]); +export const PROJECT_KEYS = Object.freeze(["vertical", "side", "qr", "promo", "zooms"]); /** The project's per-clip framing (PROJECT_KEYS) laid over a take's entry. */ export function withProjectFraming(entry, projectById) { diff --git a/umtool/report-to-video/vertical.mjs b/umtool/report-to-video/vertical.mjs @@ -227,6 +227,17 @@ export function aspectCrop(sw, sh, aspect, crop = null) { } /** + * The part of the source a clip's layout shows (px: {x, y, w, h}) and the enlargement it shows it at (the frame's + * pixels over the source's) -- the box verticalClipGraph cuts, measured. A zoom (clip-zoom.mjs) multiplies it. + */ +export function pictureRegion(geo, srcW, srcH, crop = null) { + const v = geo.video; + if (v.fill === "fit") return { region: { x: 0, y: 0, w: srcW, h: srcH }, rest: Math.min(v.w / srcW, v.h / srcH) }; + const box = v.aspect === 9 / 16 ? cropPixels(crop, srcW, srcH) : aspectCrop(srcW, srcH, v.aspect, crop); + return { region: box, rest: Math.min(v.w / box.w, v.h / box.h) }; +} + +/** * The picture of a vertical clip as ONE filtergraph from a single input pad * (written after the build's `${pic}`) to its last filter (the build names it): * the source's own blur first (`blur`: clip-blur's filters on the source