// THE GAP MARK, drawn (lane gap-cue, slice 1): "» 27 s" at the join a clip's // gap leaves, in the clip's own segment -- after its hidden regions and its // blur, so the mark is chrome over the footage and never blurred -- by one // drawtext per mark over its seconds, as a blurred clip's caption is drawn // (clip-blur.mjs). The settings, the label and the timing are common // lib/report/gapCue.mjs's, which umtool's pages read too; this file is where // the mark stands in a frame and the ffmpeg that draws it. // // WHERE. In a box the layout names -- the footage as it plays (the deck's // footage box, the plain cut's picture, a vertical cut's picture or crop one // inside its safe area) -- at a corner `inset` in from its edges: the // layout's own free corner (`auto`: the deck's stamp stands top-left and its // posts top-right, so bottom-left; the plain cut's captions sit at its foot // and its code at the bottom right, so top-left; a vertical split's captions // at its picture's foot, so top-right), or the one `corner` says. A hidden // region up while the mark is, or a code, under that corner moves it to the // next free one (tl, tr, bl, br); none free, it stays where it was asked. A // mark too wide for its box is drawn smaller, then cut ("…"): never off it. // // THE LOOK is common gapCue.mjs's GAP_CUE_LOOK (umtool's pages draw it from the // same numbers): IBM Plex Mono Bold (the vendored face: the same mark whatever // the brand), 3 % of the frame's short side (32 px at 1080), light text on a // near-opaque dark box inside a 2 px border (operator, 20 Nov: "more visible // and readable with a border"; "Go with variant B": the border in the deck's // accent, common gapCueLook -- the build passes the clip's), faded in and out by `alpha` // (GAP_CUE_MOTION), which fades the box and its border with the text. The // border is a second drawtext under the first: the same text, unseen, its box // the border's colour and wider by the stroke. No sound. // // PURE: no fs, no ffmpeg run. The build writes each mark's text file. import { GAP_CUE_LOOK, GAP_CUE_MOTION } from "yt-dlp-transcript-common/lib/report/gapCue.mjs"; import { MONO_BOLD_FONT_FILE } from "./brand.mjs"; import { deckOn } from "./deck.mjs"; // The placement, the marks and their records: pure, in gap-mark-place.mjs (the deck's schedule reads them too). export * from "./gap-mark-place.mjs"; const f3 = (n) => Number(n.toFixed(3)).toString(); /** * WHO DRAWS THE MARK (lane gap-cue, slice 1d), one predicate for the build: the gap-cue MODULE -- a HyperFrames * page per mark, laid by the chrome over the cut -- wherever a deck is drawn over the picture (`render.chrome`: * the HyperFrames deck, landscape, the feed, or the stacked vertical deck, twocrop clips too), and the build lays * its chrome (not `--no-chrome`). Everywhere else the DRAWTEXT into the clip's segment: no `render.chrome` (the * plain letterbox cut), `--no-chrome`, a bare vertical cut, `--desktop`, `--short` (their renders carry no deck). * Never both on one frame: with the module, a segment draws no mark (its argv and record are the plain ones). * * @param {any} render the build's render (a short's, a desktop's, a vertical's: as transformed) * @param {{ noChrome?: boolean }} [opts] */ export const gapMarkByChrome = (render, opts = {}) => deckOn(render) && !opts.noChrome; /** * Why a build draws its marks into the segments (gapMarkByChrome false), in words for its note. * * @param {any} render @param {{ noChrome?: boolean, short?: unknown, desktop?: unknown, vertical?: unknown }} [opts] */ export function gapMarkDrawtextWhy(render, opts = {}) { if (opts.short) return "--short"; if (opts.desktop) return "--desktop"; if (deckOn(render) && opts.noChrome) return "--no-chrome"; if (render?.format === "vertical") return "a bare vertical cut"; return "no deck (render.chrome)"; } /** * The drawtext filters for the marks (`marks` with their `places`), each text * read from `files[k]` (written by the caller -- `places[k].text`, the mark's * text as fitted: textfile=, so nothing needs filter escaping, and * expansion=none, so nothing in it is expanded) at its place's `size` -- one * comma-joined chain, or "" for none. * * @param {{ marks: Array<{ at: number, until: number }>, places: Array<{ rect: { x: number, y: number }, size?: ReturnType }>, * files: string[], size: ReturnType, look?: Partial, font?: string }} o */ export function gapMarkFilters({ marks, places, files, size, look = GAP_CUE_LOOK, font = MONO_BOLD_FONT_FILE }) { const M = GAP_CUE_MOTION; const L = { ...GAP_CUE_LOOK, ...look }; const hex = (c) => String(c).replace(/^#/, "0x"); return marks .flatMap((m, k) => { const a = f3(m.at); const b = f3(m.until); // gapCueAlpha (common gapCue.mjs), for ffmpeg: up over `in`, down over `out`, `peak` between. const alpha = `${M.peak}*clip(min((t-${a})/${M.in},(${b}-t)/${M.out}),0,1)`; const { x, y } = places[k].rect; // A mark fitted to its box (gapMarkPlaces: a smaller face) draws at its own size. const sz = places[k].size ?? size; const stroke = sz.stroke ?? 0; const at = [`x=${x + stroke + sz.border}`, `y=${y + stroke + sz.border}`, `alpha='${alpha}'`, `enable='between(t,${a},${b})'`]; const text = (fontcolor, boxcolor, boxborderw) => // expansion=none: the text is drawn as written -- a `%` or a `\` in a reason or a label is words, never // drawtext's %{…} expansion (a stray % stops ffmpeg at the mark's first frame; a backslash would vanish). [`drawtext=textfile='${files[k]}'`, "expansion=none", `fontfile='${font}'`, `fontsize=${sz.fontSize}`, `fontcolor=${fontcolor}`, "box=1", `boxcolor=${boxcolor}`, `boxborderw=${boxborderw}`, ...at].join(":"); return [ // The border: the same text, unseen, its box the stroke's colour and wider by the stroke. ...(stroke > 0 ? [text(`${hex(L.fg)}@0`, `${hex(L.strokeColor)}@${L.strokeAlpha}`, sz.border + stroke)] : []), text(hex(L.fg), `${hex(L.box)}@${L.boxAlpha}`, sz.border), ]; }) .join(","); }