// THE REEL'S OUTRO CARD (operator, 5 Nov: "Maybe the trailer gets a bespoke outro?"). // // A reel (a beats file, lib/report/trailerBeats.mjs) may end on a card: the // full video's title large, a short call to action ("Full video on the // channel"), the site's name small (the intro's site -- "Anilyzer"), over the // ground or over an image of the project's (the thumbnail art, blurred and // darkened so the words read). The card fades in from the last beat over // OUTRO_FADE seconds while the beat's sound fades out; the reel then holds the // card, in silence, to its end. // // The reel's setting (`outro` in promo/-beats.json): // // { "on": true, "title": "…", "text": "…", "image": "promo/thumb.jpg", "seconds": 3.5 } // // every key but `on` optional: `title` defaults to the reel's title, else the // project's; `text` to OUTRO_TEXT_DEFAULT; `image` to none; `seconds` (the // card's length, its fade-in included) to OUTRO_SECONDS_DEFAULT. // // The card is one still, drawn by ImageMagick + Pango in the vendored faces // (Archivo, IBM Plex Sans; fonts/fonts.conf), at the cut's size: 16:9 or 9:16, // laid out by outroLayout -- inside the platform's safe area on a vertical // (Shorts: the top 8 %, the bottom 20 % and the right 12 % carry the player's // own buttons and text). Drawn once per key, beside the reel's cut. // // Plain ESM: the CLI runs it under bare node. import { execFile } from "node:child_process"; import { createHash } from "node:crypto"; import { access, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises"; import path from "node:path"; import { promisify } from "node:util"; import { FONTCONFIG_FILE } from "./brand.mjs"; import { cutChannelName } from "./attribution.mjs"; const execFileP = promisify(execFile); const exists = (p) => access(p).then(() => true, () => false); /** The card's length, its fade-in included. */ export const OUTRO_SECONDS_DEFAULT = 3.5; export const OUTRO_SECONDS_MIN = 1.5; export const OUTRO_SECONDS_MAX = 10; /** The fade from the last beat into the card (its picture; the beat's sound fades out over it). */ export const OUTRO_FADE = 0.5; /** The call to action under the title. */ export const OUTRO_TEXT_DEFAULT = "Full video on the channel"; /** The setting's keys. */ export const OUTRO_KEYS = Object.freeze(["on", "title", "text", "image", "seconds"]); const TITLE_MAX = 160; const TEXT_MAX = 120; const IMAGE_EXT = /\.(jpe?g|png|webp)$/i; /** The vertical's safe area, as fractions of the frame (YouTube Shorts' overlays). */ export const VERTICAL_SAFE = Object.freeze({ top: 0.08, bottom: 0.2, right: 0.12, left: 0.12 }); const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); /** * Each thing wrong with an outro setting, by name ([] when it is fine). * `true`/`false` are on/off with every default; an object carries the keys. * * @param {unknown} v * @returns {string[]} */ export function outroErrors(v) { if (v === undefined || v === null || v === true || v === false) return []; if (!isObj(v)) return [`outro is on|off or {${OUTRO_KEYS.join(", ")}}`]; const o = /** @type {Record} */ (v); const errors = []; for (const k of Object.keys(o)) if (!OUTRO_KEYS.includes(k)) errors.push(`outro.${k} is not a key (${OUTRO_KEYS.join(", ")})`); if (o.on !== undefined && typeof o.on !== "boolean") errors.push("outro.on is true or false"); if (o.title !== undefined && (typeof o.title !== "string" || o.title.length > TITLE_MAX)) errors.push(`outro.title is text (up to ${TITLE_MAX} characters)`); if (o.text !== undefined && (typeof o.text !== "string" || o.text.length > TEXT_MAX)) errors.push(`outro.text is text (up to ${TEXT_MAX} characters)`); if (o.image !== undefined) { const s = o.image; if (typeof s !== "string" || !s.trim() || path.isAbsolute(s) || s.split(/[\\/]/).includes("..") || !IMAGE_EXT.test(s)) { errors.push("outro.image is a .jpg, .png or .webp file of the project's, by its path inside the project (e.g. promo/thumbnail.jpg)"); } } if (o.seconds !== undefined && !(typeof o.seconds === "number" && o.seconds >= OUTRO_SECONDS_MIN && o.seconds <= OUTRO_SECONDS_MAX)) { errors.push(`outro.seconds is ${OUTRO_SECONDS_MIN}–${OUTRO_SECONDS_MAX}`); } return errors; } /** * The setting as stored: `{ on, ...keys }` (a trimmed title or text; an empty * one dropped). Refused by name when it does not validate. * @param {unknown} v * @returns {{ on: boolean, title?: string, text?: string, image?: string, seconds?: number } | null} */ export function normalizeOutro(v) { const errors = outroErrors(v); if (errors.length) throw new Error(errors.join("; ")); if (v === undefined || v === null) return null; if (v === true || v === false) return { on: v }; const o = /** @type {Record} */ (v); const out = { on: o.on !== false }; for (const k of ["title", "text"]) if (typeof o[k] === "string" && o[k].trim()) out[k] = o[k].trim().replace(/\s+/g, " "); if (typeof o.image === "string") out.image = o.image.trim().replace(/^\.\//, ""); if (typeof o.seconds === "number") out.seconds = Number(o.seconds.toFixed(2)); return out; } /** Is the outro on? */ export const outroOn = (v) => v === true || (isObj(v) && /** @type {any} */ (v).on !== false); /** * The card's words and length, with the defaults: null when the outro is off. * @param {unknown} setting the reel's `outro` * @param {{ reelTitle?: string | null, projectTitle?: string | null }} [o] */ export function resolveOutro(setting, { reelTitle = null, projectTitle = null } = {}) { if (!outroOn(setting)) return null; const s = setting === true ? {} : /** @type {Record} */ (setting); const title = (typeof s.title === "string" && s.title.trim()) || (reelTitle && reelTitle.trim()) || (projectTitle && projectTitle.trim()) || ""; return { title, text: typeof s.text === "string" && s.text.trim() ? s.text.trim() : OUTRO_TEXT_DEFAULT, image: typeof s.image === "string" ? s.image : null, seconds: typeof s.seconds === "number" ? s.seconds : OUTRO_SECONDS_DEFAULT, }; } /** What the outro adds to a reel's length: its seconds less the fade it overlaps the last beat by. */ export function outroAdds(seconds) { return Number.isFinite(seconds) && seconds > 0 ? Math.max(0, seconds - OUTRO_FADE) : 0; } /** * Where the card's parts go, in px: the content box (inside the safe area on * a vertical), the title's wrap width and size, the call to action's size, * the brand line's size and baseline area. Pure. * * @param {{ width: number, height: number }} size */ export function outroLayout({ width: W, height: H }) { const vertical = H > W; if (vertical) { const box = { x0: Math.round(W * VERTICAL_SAFE.left), x1: Math.round(W * (1 - VERTICAL_SAFE.right)), y0: Math.round(H * VERTICAL_SAFE.top), y1: Math.round(H * (1 - VERTICAL_SAFE.bottom)), }; const u = W / 1080; return { vertical, box, titlePx: [92, 80, 70, 62, 54].map((p) => Math.round(p * u)), titleLines: 5, ctaPx: Math.round(46 * u), brandPx: Math.round(44 * u), gap: Math.round(44 * u), rule: { w: Math.round(110 * u), h: Math.max(2, Math.round(6 * u)) }, // The brand sits at the box's foot; the title and the call to action centre in what is above it. brandRoom: Math.round(150 * u), }; } const u = H / 1080; const box = { x0: Math.round(W * 0.1), x1: Math.round(W * 0.9), y0: Math.round(H * 0.1), y1: Math.round(H * 0.9) }; return { vertical, box, titlePx: [96, 84, 74, 64].map((p) => Math.round(p * u)), titleLines: 3, ctaPx: Math.round(44 * u), brandPx: Math.round(40 * u), gap: Math.round(40 * u), rule: { w: Math.round(120 * u), h: Math.max(2, Math.round(6 * u)) }, brandRoom: Math.round(120 * u), }; } function esc(s) { return String(s).replace(/&/g, "&").replace(//g, ">").replace(/"/g, """).replace(/'/g, "'"); } const pt = (px) => px * 0.75; const span = (text, { px, color, face }) => `${esc(text)}`; const magickOpts = { maxBuffer: 1 << 24, env: { ...process.env, FONTCONFIG_FILE } }; /** Pango markup -> a transparent PNG centred lines wrapped at `width`; its size. */ async function textPng(markup, file, width, align = "center") { const markupPath = file.replace(/\.png$/, ".pango"); await writeFile(markupPath, markup, "utf8"); const args = ["-background", "none", "-define", `pango:align=${align}`]; if (width) args.push("-size", `${Math.round(width)}x`, "-define", "pango:wrap=word"); args.push(`pango:@${markupPath}`, "-trim", "+repage", file); await execFileP("magick", args, magickOpts); const { stdout } = await execFileP("magick", [file, "-format", "%w %h", "info:"]); const [w, h] = stdout.trim().split(" ").map(Number); return { file, width: w, height: h }; } /** The card's colours: the report videos' dark ground, the brand's paper and the site's accent. */ export const OUTRO_COLOURS = Object.freeze({ ground: "#151b20", ink: "#f6f1e6", muted: "#a9b4bc" }); /** * The card's key: everything drawn (the words, the size, the image's bytes, the brand; a 9:16 end card's QR, * host and sources). * @param {object} o */ export function outroKey({ width, height, title, text, imageSha = null, brand, end = null }) { return createHash("sha256").update(JSON.stringify({ v: 1, width, height, title, text, imageSha, brand, ...(end ? { end } : {}) })).digest("hex").slice(0, 20); } // --------------------------------------------------------------------------- // THE 9:16 END CARD (lane vertical-deck, out/vertical-design EndCard): a vertical outro with somewhere to go -- // its QR large, "scan or search" and the archive's host beside it, the cut's sources listed (each its date, its // channel and the time it is from; the rest counted), the site's name at the foot. The same card, more on it. // --------------------------------------------------------------------------- /** How many sources the end card lists before it counts the rest. */ export const END_CARD_SOURCES = 3; /** The end card's words over its title. */ export const END_CARD_KICKER = "EVERY CLIP, IN FULL"; const MONTHS_SHORT = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; /** "2026-01-12" or "Jan 12, 2026" as the list's date ("Jan 12"); anything else as it is. */ export function endCardDate(d) { const s = String(d ?? "").trim(); const iso = /^(\d{4})-(\d{2})-(\d{2})/.exec(s); if (iso) return `${MONTHS_SHORT[Number(iso[2]) - 1]} ${Number(iso[3])}`; const long = /^([A-Z][a-z]{2}) (\d{1,2}), \d{4}$/.exec(s); return long ? `${long[1]} ${long[2]}` : s; } /** * The sources an end card lists: each clip of `timeline` once (by video), in order -- its date, its channel and * the time it is from, from the build's schedule (a stacked deck's `vsource`) else what the entry says of itself -- * its own `channelTitle`, else the cut's name for its channel (`names`, the cut's `render.channelNames`). Pure. * * @param {Array>} timeline * @param {{ segments?: Array> } | null} [schedule] * @param {Record | null} [names] * @param {{ channelSlug?: string | null }} [provenance] * @returns {Array<{ date: string, label: string }>} */ export function endCardSources(timeline, schedule = null, names = null, provenance = {}) { const bySeg = new Map((Array.isArray(schedule?.segments) ? schedule.segments : []).map((x) => [x.id, x])); const seen = new Set(); const out = []; for (const e of Array.isArray(timeline) ? timeline : []) { if (e?.type !== "clip") continue; const key = String(e.video ?? e.id); if (seen.has(key)) continue; seen.add(key); const v = bySeg.get(e.id)?.vsource ?? bySeg.get(String(e.id).replace(/~\d+$/, ""))?.vsource ?? null; const channel = String(v?.channel ?? (String(e.channelTitle ?? "").trim() || cutChannelName(e, provenance, names))).trim(); const at = Number(e.cite ?? e.start); const clock = v?.clock ?? (Number.isFinite(at) ? hmsOf(at) : ""); const label = [channel, clock].filter(Boolean).join(" · "); if (!label) continue; out.push({ date: endCardDate(v?.date ?? e.date ?? ""), label }); } return out; } function hmsOf(total) { const s = Math.floor(Math.max(0, total)); const h = Math.floor(s / 3600); const m = Math.floor((s % 3600) / 60); const x = s % 60; return h > 0 ? `${h}:${String(m).padStart(2, "0")}:${String(x).padStart(2, "0")}` : `${m}:${String(x).padStart(2, "0")}`; } /** The archive's host as the card says it ("https://jeralyzer.pages.dev/x" → "jeralyzer.pages.dev"), or "". */ export function endCardHost(url) { try { return new URL(String(url ?? "")).hostname; } catch { return ""; } } /** * Where the 9:16 end card's parts go, px (the mockup's at 1080x1920): inside the safe area, top to bottom -- the * kicker and the title, the QR and its words beside it, the sources, the wordmark. Pure. * * @param {{ width: number, height: number }} size */ export function endCardLayout({ width: W, height: H }) { const u = W / 1080; const box = { x0: Math.round(W * 0.05), x1: Math.round(W * (1 - VERTICAL_SAFE.right)), y0: Math.round(H * VERTICAL_SAFE.top), y1: Math.round(H * (1 - VERTICAL_SAFE.bottom)), }; const qr = Math.round(450 * u); return { box, u, kicker: { px: Math.round(34 * u), y: box.y0 + Math.round(34 * u) }, title: { px: [64, 58, 52, 46].map((p) => Math.round(p * u)), lines: 3, gap: Math.round(18 * u) }, qr: { size: qr, pad: Math.round(28 * u), radius: Math.round(26 * u) }, side: { gap: Math.round(32 * u), headPx: Math.round(36 * u), hostPx: Math.round(30 * u), textPx: Math.round(28 * u) }, list: { px: Math.round(32 * u), row: Math.round(54 * u), dateW: Math.round(140 * u), gap: Math.round(40 * u) }, brandPx: Math.round(46 * u), }; } /** * Draw the card: `/outro-.png` (kept: a second cut with the same * words is not drawn again). `brand` is the site's name as the intro splits * it (`lead` heavy, the rest light) in its accent (`ink`). * * @param {{ width: number, height: number, title: string, text: string, imageFile?: string | null, * brand: { name: string, lead?: string, ink: string }, dir: string }} o * @returns {Promise<{ file: string, key: string, cached: boolean, layout: ReturnType, placed: Record }>} */ export async function renderOutroCard({ width: W, height: H, title, text, imageFile = null, brand, dir, qrUrl = null, sources = null }) { const L = outroLayout({ width: W, height: H }); const imageBytes = imageFile ? await readFile(imageFile).catch(() => null) : null; if (imageFile && !imageBytes) throw new Error(`outro.image ${imageFile}: not there`); const imageSha = imageBytes ? createHash("sha256").update(imageBytes).digest("hex") : null; // A 9:16 card with somewhere to go (a QR, or the sources to list) is the END CARD: the same card, more on it. const end = L.vertical && (qrUrl || sources?.length) ? { qrUrl: qrUrl ?? null, host: endCardHost(qrUrl), sources: sources ?? [] } : null; const key = outroKey({ width: W, height: H, title, text, imageSha, brand, end }); await mkdir(dir, { recursive: true }); const file = path.join(dir, `outro-${key}.png`); const placedFile = `${file}.json`; if ((await exists(file)) && (await exists(placedFile))) { return { file, key, cached: true, layout: L, placed: JSON.parse(await readFile(placedFile, "utf8")) }; } const work = path.join(dir, `.outro-${key}-${process.pid}`); await mkdir(work, { recursive: true }); try { const boxW = L.box.x1 - L.box.x0; // The title: the largest size whose wrap keeps to its lines. let t = null; for (const px of L.titlePx) { t = await textPng(span(title, { px, color: OUTRO_COLOURS.ink, face: "Archivo @wght=800,wdth=108" }), path.join(work, "title.png"), boxW); if (t.height <= px * 1.25 * L.titleLines) break; } const cta = await textPng(span(text, { px: L.ctaPx, color: brand.ink, face: "IBM Plex Sans @wght=600" }), path.join(work, "cta.png"), boxW); const lead = brand.lead && brand.name.startsWith(brand.lead) ? brand.lead : ""; const brandMarkup = `${lead ? span(lead, { px: L.brandPx, color: brand.ink, face: "Archivo @wght=800,wdth=108" }) : ""}${span(brand.name.slice(lead.length), { px: L.brandPx, color: lead ? brand.ink : brand.ink, face: lead ? "Archivo @wght=380,wdth=108" : "Archivo @wght=800,wdth=108" })}`; const mark = await textPng(brandMarkup, path.join(work, "brand.png"), null); // The ground: the image covering the frame, blurred and darkened, else the plain ground. const ground = path.join(work, "ground.png"); if (imageFile) { const blur = Math.round(Math.max(W, H) / 70); await execFileP("magick", [ imageFile, "-auto-orient", "-resize", `${W}x${H}^`, "-gravity", "center", "-extent", `${W}x${H}`, "-blur", `0x${blur}`, "-fill", OUTRO_COLOURS.ground, "-colorize", "55%", "+repage", ground, ], magickOpts); } else { await execFileP("magick", ["-size", `${W}x${H}`, `xc:${OUTRO_COLOURS.ground}`, ground], magickOpts); } if (end) { const placed = await drawEndCard({ W, H, title, text, brand, end, ground, mark, work, file: path.join(work, "card.png") }); await writeFile(placedFile, JSON.stringify(placed) + "\n"); await rename(path.join(work, "card.png"), file); return { file, key, cached: false, layout: L, placed }; } // The column: title, the accent rule, the call to action, centred in the box above the brand's room. const colH = t.height + L.gap + L.rule.h + L.gap + cta.height; const areaTop = L.box.y0; const areaBottom = L.box.y1 - L.brandRoom; let y = Math.round(areaTop + Math.max(0, (areaBottom - areaTop - colH) / 2)); const cx = (L.box.x0 + L.box.x1) / 2; const at = (w) => Math.round(cx - w / 2); /** @type {Record} */ const placed = {}; placed.title = { x: at(t.width), y, w: t.width, h: t.height }; y += t.height + L.gap; placed.rule = { x: at(L.rule.w), y, w: L.rule.w, h: L.rule.h }; y += L.rule.h + L.gap; placed.cta = { x: at(cta.width), y, w: cta.width, h: cta.height }; placed.brand = { x: at(mark.width), y: L.box.y1 - mark.height, w: mark.width, h: mark.height }; const tmp = path.join(work, "card.png"); await execFileP("magick", [ ground, t.file, "-geometry", `+${placed.title.x}+${placed.title.y}`, "-composite", "-fill", brand.ink, "-draw", `rectangle ${placed.rule.x},${placed.rule.y} ${placed.rule.x + placed.rule.w - 1},${placed.rule.y + placed.rule.h - 1}`, cta.file, "-geometry", `+${placed.cta.x}+${placed.cta.y}`, "-composite", mark.file, "-geometry", `+${placed.brand.x}+${placed.brand.y}`, "-composite", "-alpha", "off", "-depth", "8", tmp, ], magickOpts); await writeFile(placedFile, JSON.stringify(placed) + "\n"); await rename(tmp, file); return { file, key, cached: false, layout: L, placed }; } finally { await rm(work, { recursive: true, force: true }); } } /** * The 9:16 end card on `ground` (endCardLayout): the kicker and the title, the QR large with "Scan or search", the * host and the call to action beside it, the sources (END_CARD_SOURCES, then "+ N more in the archive"), the * brand's mark at the foot of the safe area. Returns where each part went. */ async function drawEndCard({ W, H, title, text, brand, end, ground, mark, work, file }) { const E = endCardLayout({ width: W, height: H }); const boxW = E.box.x1 - E.box.x0; const placed = {}; const comps = []; const at = (png, x, y) => comps.push(png, "-geometry", `+${Math.round(x)}+${Math.round(y)}`, "-composite"); let y = E.kicker.y; const kick = await textPng(span(END_CARD_KICKER, { px: E.kicker.px, color: brand.ink, face: "Archivo @wght=800,wdth=108" }), path.join(work, "kicker.png"), null); at(kick.file, E.box.x0, y); placed.kicker = { x: E.box.x0, y, w: kick.width, h: kick.height }; y += kick.height + E.title.gap; let t = null; for (const px of E.title.px) { t = await textPng(span(title, { px, color: OUTRO_COLOURS.ink, face: "Archivo @wght=800,wdth=108" }), path.join(work, "etitle.png"), boxW, "left"); if (t.height <= px * 1.25 * E.title.lines) break; } at(t.file, E.box.x0, y); placed.title = { x: E.box.x0, y, w: t.width, h: t.height }; y += t.height + Math.round(48 * E.u); // The QR on a white plate, its words beside it. if (end.qrUrl) { const raw = path.join(work, "qr-raw.png"); const qr = path.join(work, "qr.png"); const inner = E.qr.size - 2 * E.qr.pad; await execFileP(process.env.QRENCODE_BIN ?? "qrencode", ["-o", raw, "-s", "8", "-m", "0", "-l", "M", "--", end.qrUrl]); await execFileP("magick", [ "-size", `${E.qr.size}x${E.qr.size}`, "xc:none", "-fill", "#ffffff", "-draw", `roundrectangle 0,0 ${E.qr.size - 1},${E.qr.size - 1} ${E.qr.radius},${E.qr.radius}`, "(", raw, "-filter", "point", "-resize", `${inner}x${inner}!`, ")", "-geometry", `+${E.qr.pad}+${E.qr.pad}`, "-composite", qr, ], magickOpts); at(qr, E.box.x0, y); placed.qr = { x: E.box.x0, y, w: E.qr.size, h: E.qr.size }; const sx = E.box.x0 + E.qr.size + E.side.gap; const sw = E.box.x1 - sx; let sy = y + Math.round(10 * E.u); const head = await textPng(span("Scan or search", { px: E.side.headPx, color: OUTRO_COLOURS.ink, face: "IBM Plex Sans @wght=700" }), path.join(work, "scan.png"), null); at(head.file, sx, sy); sy += head.height + Math.round(18 * E.u); if (end.host) { const host = await textPng(span(end.host, { px: E.side.hostPx, color: brand.ink, face: "IBM Plex Sans @wght=600" }), path.join(work, "host.png"), sw, "left"); at(host.file, sx, sy); placed.host = { x: sx, y: sy, w: host.width, h: host.height }; sy += host.height + Math.round(18 * E.u); } if (text) { const cta = await textPng(span(text, { px: E.side.textPx, color: OUTRO_COLOURS.muted, face: "IBM Plex Sans @wght=500" }), path.join(work, "ecta.png"), sw, "left"); at(cta.file, sx, sy); placed.cta = { x: sx, y: sy, w: cta.width, h: cta.height }; } y += E.qr.size + E.list.gap; } // The sources: each its date, then its channel and time; the rest counted. const list = end.sources.slice(0, END_CARD_SOURCES); const more = end.sources.length - list.length; placed.sources = []; for (const [i, s] of list.entries()) { const d = await textPng(span(s.date || "—", { px: E.list.px, color: OUTRO_COLOURS.muted, face: "IBM Plex Sans @wght=500" }), path.join(work, `sd${i}.png`), null); const l = await textPng(span(s.label, { px: E.list.px, color: OUTRO_COLOURS.ink, face: "IBM Plex Sans @wght=500" }), path.join(work, `sl${i}.png`), E.box.x1 - E.box.x0 - E.list.dateW, "left"); at(d.file, E.box.x0, y); at(l.file, E.box.x0 + E.list.dateW, y); placed.sources.push({ x: E.box.x0, y, w: E.list.dateW + l.width, h: Math.max(d.height, l.height) }); y += Math.max(E.list.row, l.height + Math.round(14 * E.u)); } if (more > 0) { const m = await textPng(span(`+ ${more} more in the archive`, { px: E.list.px, color: OUTRO_COLOURS.muted, face: "IBM Plex Sans @wght=500" }), path.join(work, "more.png"), null); at(m.file, E.box.x0, y); placed.more = { x: E.box.x0, y, w: m.width, h: m.height }; } // The brand at the foot of the safe area, left. placed.brand = { x: E.box.x0, y: E.box.y1 - mark.height, w: mark.width, h: mark.height }; at(mark.file, placed.brand.x, placed.brand.y); await execFileP("magick", [ground, ...comps, "-alpha", "off", "-depth", "8", file], magickOpts); return placed; } /** * The filtergraph fragment that appends the card to a cut's `[vIn]`/`[aIn]` * (`seconds` long, its `fade` overlapping the cut's last seconds): the card * looped to its frames, the cut's sound faded out over the fade and silence * after. `cutSeconds` is the cut's length before it. * * @param {{ png: string, seconds: number, fade?: number, fps: number, cutSeconds: number, vIn: string, aIn: string, * audioRate?: number, audioChannels?: number, escape: (f: string) => string }} o */ export function outroFilterParts({ png, seconds, fade = OUTRO_FADE, fps, cutSeconds, vIn, aIn, audioRate = 48000, audioChannels = 2, escape }) { const frames = Math.round(seconds * fps); const d = (frames / fps).toFixed(6); const layout = audioChannels === 1 ? "mono" : "stereo"; const f = fade.toFixed(6); return { parts: [ `movie=filename=${escape(png)},loop=loop=${frames - 1}:size=1:start=0,setpts=N/(${fps}*TB),fps=${fps},format=yuv420p,setsar=1,settb=AVTB[ocv]`, `aevalsrc=0:channel_layout=${layout}:sample_rate=${audioRate}:duration=${d}[oca]`, `${vIn}format=yuv420p,settb=AVTB[ocin]`, `[ocin][ocv]xfade=transition=fade:duration=${f}:offset=${Math.max(0, cutSeconds - fade).toFixed(6)}[ov]`, `${aIn}aresample=${audioRate},aformat=channel_layouts=${layout}[ocain]`, `[ocain][oca]acrossfade=d=${f}:c1=tri:c2=tri[oa]`, ], vOut: "[ov]", aOut: "[oa]", frames, }; }