// `umtool vertical` (lane vertical, 5 Nov): a vertical short (1080x1920) of a // take's items -- a reel's beats, or a list of items -- built NATIVELY: each // clip cut again in its vertical layout, each post item drawn again in a // portrait box (report-to-video/vertical.mjs), through build-video in the // heavy slot. `--reframe` instead recomposes the take's finished 16:9 master // (report-to-video/reframe.mjs): the cheapest, for any finished cut. // // umtool vertical --take (--reel | --beats FILE | --items a,b,…) // [--clip full|framed|quote] [--post card|stack|media] [--side split|overlay] // [--hook title|section|""] [--captions l|xl] [--lines 1|2] // [--loudness -14] [--max 60] [--name N] [--out FILE] [--reframe] [--dry-run] [--json] // // The plan is report-to-video/vertical-plan.mjs. Writes // takes//out/...vertical.mp4 and a .json beside it. import { spawn } from "node:child_process"; import { existsSync } from "node:fs"; import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises"; import path from "node:path"; import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs"; import { kindMakesTakes } from "../projects/kinds.mjs"; import { takesDirOf } from "./takes.mjs"; import { readTrailerBeats, reelFileOf } from "./trailerBeats.mjs"; import { resolveOutro } from "umtool-report-to-video/outro"; import { PIPELINE_DIR, UMTOOL_DIR } from "./driver.mjs"; import { ensureWriteDir } from "./storage.mjs"; /** * The look keys a short is built from that a batch's record keeps (lib/report/shortsBatch.mjs `--again`): what the * render draws a per-clip build with, as the take resolved them then. */ export const LOOK_SNAPSHOT_KEYS = Object.freeze(["palette", "fontRegular", "fontBold", "fps", "captions", "loudness", "qr", "vertical", "desktop", "promo", "zooms", "tallWindows", "maxHeightSource", "blur", "transition", "transitionStyle", "headerHeight", "footerHeight"]); const FONT_KEYS = ["fontRegular", "fontBold"]; const PIPELINE_FONTS = path.join(/* turbopackIgnore: true */ PIPELINE_DIR, "fonts"); /** * The snapshot of `render`'s look. Its fonts are kept BY NAME (one of the pipeline's fonts/: its file name) or * relative to the project (`projectDir`), never as an absolute path of this checkout -- a record outlives a move. */ export function lookSnapshotOf(render, { projectDir = null } = {}) { const out = Object.fromEntries(LOOK_SNAPSHOT_KEYS.filter((k) => render?.[k] !== undefined).map((k) => [k, render[k]])); for (const k of FONT_KEYS) { const v = out[k]; if (typeof v !== "string" || !path.isAbsolute(v)) continue; if (path.dirname(v) === PIPELINE_FONTS) out[k] = path.basename(v); else if (projectDir && !path.relative(projectDir, v).startsWith("..")) out[k] = path.relative(projectDir, v); } return out; } /** A recorded look made usable again: a font by name is the pipeline's, a relative one the project's. */ export function lookFromSnapshot(look, { projectDir }) { const out = { ...look }; for (const k of FONT_KEYS) { const v = out[k]; if (typeof v !== "string" || path.isAbsolute(v)) continue; out[k] = !v.includes("/") && existsSync(path.join(/* turbopackIgnore: true */ PIPELINE_FONTS, v)) ? path.join(/* turbopackIgnore: true */ PIPELINE_FONTS, v) : path.join(/* turbopackIgnore: true */ projectDir, v); } return out; } export const VERTICAL_USAGE = [ "usage: umtool vertical --take (--reel | --beats FILE | --items ,…)", " [--clip full|framed|quote] [--post card|stack|media] [--side split|overlay]", " [--hook title|section|\"\"] [--captions l|xl] [--lines 1|2]", " [--loudness -14] [--max 60] [--name N] [--out FILE] [--reframe | --landscape | --desktop] [--dry-run] [--json]", " [--intro | --no-intro] [--no-outro] [--deck stacked|bare] [--qr on|off] [--qr-corner tr|tl]", " [--promo | --no-promo] [--promo-lead 4.5] [--promo-fade 0.7] [--promo-hold 1.5] [--no-cold-open]", "", "A vertical short (1080x1920, the take's fps) of a take's items: a reel's beats (promo/-beats.json, as", "`umtool trailer --reel` reads them), a beats file, or whole items. Built natively: each clip cut again in", "its layout -- full (a 9:16 crop, big captions lit word by word, a source tag), framed (the whole picture in", "the middle third over a blurred enlargement, a hook above, captions below) or quote (the picture in the top", "40 %, the words set large under it) -- each post item drawn again in a portrait box -- card (its attachment", "under the words), stack (over them, the thread below) or media (the attachment large over the words) -- and", "a clip with a side post (`umtool set

side.item=` …) in split (the clip on top, the post", "rising into the bottom half) or overlay (the post floating over the lower third). Text keeps out of the", "safe edges (top 8 %, bottom 20 %, right 12 %). The short is brought to -14 LUFS (--loudness), and one over", "60 s (--max) is said so. A clip's vertical crop and layout and its side post are read from the PROJECT's", "manifest over the take's. The hook only ever says the cut's own words: a clip's title, its section's title,", "or a line you give it from the cut's copy.", "--landscape builds the same items in the take's own 16:9 look instead (its header, QR and deck), to compare.", "--desktop builds them 16:9 with minimal chrome (render.desktop): the picture full frame, one thin source line on a", "plate, the words lit along its foot, a code in a corner only with --qr (--qr-corner br|bl|tr|tl); -14 LUFS.", "--reframe recomposes the take's finished 16:9 master instead (each item's region -- the footage, the post's", "card and attachment, the deck's date line -- laid out 9:16): nothing is cut again, any finished take.", "Writes takes//out/...vertical.mp4 (--out: that file) and a .json beside it. The build", "runs in the heavy slot, as a take's does.", "--intro opens the short on the brand intro re-laid 9:16 (centred in the safe area; the take's render.intro,", "else boot-dark with the mark on the chime); a reel whose `intro` is on opens on it too (its own intro when it", "has one; --no-intro: not). A reel whose `outro` is on ends on its card, laid out 9:16 inside the safe area", "(--no-outro: not). Both are counted in the length the --max note reads.", "--deck stacked (the default for a cut with a deck: render.vertical.deck) keeps the deck in 9:16 -- the rail", "under the top band, the picture at full width, the captions under it, the instruments in two columns, the", "source line and its QR above the bottom band; --deck bare is the vertical with no deck, as it first shipped.", "--qr on (or --qr-corner tr|tl) puts a code at the top of the safe area linking the source at the second each", "clip plays from (render.vertical.qr; a clip's own `qr` speaks over it); off by default.", "The channel promo (render.promo: the streamer's portrait, name, page and its code) ends the short's last clip when", "the take sets one: the picture dissolves into the card over the clip's last --promo-lead seconds (its sound on", "under it, the captions over it), then the card holds --promo-hold seconds in silence; --no-promo ends without it.", "A clip with a cold open (its `coldOpen`: a span of its cut, 1-4 s) plays it first, then cuts to its start;", "--no-cold-open plays the clips as cut.", ].join("\n"); export class CliError extends Error {} const VALUED = new Set(["--take", "--reel", "--beats", "--items", "--clip", "--post", "--side", "--hook", "--captions", "--lines", "--loudness", "--max", "--name", "--out", "--deck", "--qr", "--qr-corner", "--promo-lead", "--promo-hold", "--promo-fade"]); const BOOL = new Set(["--reframe", "--landscape", "--desktop", "--promo", "--no-promo", "--no-cold-open", "--dry-run", "--json", "--help", "--intro", "--no-intro", "--no-outro"]); export function parse(args) { /** @type {Record} */ const flags = {}; const positional = []; for (let i = 0; i < args.length; i += 1) { const a = args[i]; if (a.startsWith("--")) { if (VALUED.has(a)) { if (i + 1 >= args.length) throw new CliError(`${a} needs a value`); flags[a] = args[++i]; } else if (BOOL.has(a)) flags[a] = ""; else throw new CliError(`unknown flag ${a}`); } else positional.push(a); } return { flags, positional, has: (n) => n in flags }; } /** The vertical knobs the flags ask for (render.vertical's shape), over the cut's own. */ export function knobsOfFlags(flags) { /** @type {Record} */ const k = {}; if (flags["--deck"]) k.deck = flags["--deck"]; if (flags["--clip"]) k.clip = flags["--clip"]; if (flags["--post"]) k.post = flags["--post"]; if (flags["--side"]) k.side = flags["--side"]; if (flags["--hook"]) k.hook = ["title", "section", "false"].includes(flags["--hook"]) ? (flags["--hook"] === "false" ? false : flags["--hook"]) : { text: flags["--hook"] }; if (flags["--captions"] || flags["--lines"]) { k.captions = {}; if (flags["--captions"]) k.captions.size = flags["--captions"]; if (flags["--lines"]) k.captions.lines = Number(flags["--lines"]); } if (flags["--loudness"] !== undefined) k.loudness = Number(flags["--loudness"]); if (flags["--max"] !== undefined) k.maxSeconds = Number(flags["--max"]); // The short's code (clip-kit.mjs): --qr on|off, --qr-corner tr|tl (a corner alone turns it on). if (flags["--qr"] !== undefined || flags["--qr-corner"] !== undefined) { const on = flags["--qr"] === undefined ? true : ["on", "true"].includes(flags["--qr"]) ? true : ["off", "false"].includes(flags["--qr"]) ? false : flags["--qr"]; k.qr = on === true && flags["--qr-corner"] !== undefined ? { corner: flags["--qr-corner"] } : on; } return k; } const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); /** * The desktop knobs (render.desktop's shape) the flags ask for: their captions, hook, loudness, length and code. A * caption size or corner only a short has is left to the desktop's own default. */ export function desktopKnobsOf(knobs = {}) { /** @type {Record} */ const d = {}; if (knobs.hook !== undefined) d.hook = knobs.hook; if (isObj(knobs.captions)) { const c = {}; if (["m", "l", "xl"].includes(knobs.captions.size)) c.size = knobs.captions.size; if (knobs.captions.lines !== undefined) c.lines = knobs.captions.lines; if (Object.keys(c).length) d.captions = c; } if (knobs.loudness !== undefined) d.loudness = knobs.loudness; if (knobs.maxSeconds !== undefined) d.maxSeconds = knobs.maxSeconds; if (knobs.qr !== undefined) d.qr = knobs.qr; return d; } /** * A short's 9:16 end card (outro.mjs) -- the archive's link as a QR and the short's sources, each clip's date, channel * and time from the stacked deck's schedule -- or null: a short that keeps no deck (`--deck bare`, a cut without one) * ends on the outro card it always did. */ export async function endCardOf({ render, knobs = {}, provenance = {}, timeline = [], schedule = null }) { const V = await import("umtool-report-to-video/vertical"); if (!V.stackedDeckWanted({ ...render, format: "vertical", vertical: { ...(render?.vertical ?? {}), ...knobs } })) return null; const { endCardSources } = await import("umtool-report-to-video/outro"); return { qrUrl: provenance.qrLink ?? provenance.siteOrigin ?? null, sources: endCardSources(timeline, schedule, render?.channelNames ?? null, provenance) }; } /** The heavy slot (report-to-video/heavy-gate.mjs), loaded at run time: `(cmd, fn) => …` with a declared estimate. */ async function heavySlot() { const gate = new URL("./heavy-gate.mjs", import.meta.resolve("umtool-report-to-video/package.json")).href; const { withRenderSlot } = await import(/* webpackIgnore: true */ gate); return (cmd, fn) => withRenderSlot(cmd, fn, { estimateMb: 2500 }); } const readJson = (file) => readFile(file, "utf8").then((t) => JSON.parse(t), () => null); /** Run a process, its output to `log`; resolves to its exit code. */ function run(argv, { cwd, log }) { return new Promise((resolve, reject) => { const child = spawn(argv[0], argv.slice(1), { cwd, stdio: ["ignore", "pipe", "pipe"] }); const lines = (b) => { for (const line of b.toString().split("\n")) if (line.trim()) log(line); }; child.stdout.on("data", lines); child.stderr.on("data", lines); child.on("error", reject); child.on("close", (code) => resolve(code ?? 1)); }); } /** * The channel promo the flags ask for (promo-card.mjs): `promo` false (--no-promo) or true (--promo: the cut's, refused * when it sets none), and its timing over the cut's (--promo-lead, --promo-fade, --promo-hold). */ export function promoOptionsOf(flags) { /** @type {{ promo?: boolean, promoKnobs?: Record }} */ const o = {}; if ("--no-promo" in flags) o.promo = false; else if ("--promo" in flags) o.promo = true; const k = {}; for (const [f, key] of [["--promo-lead", "lead"], ["--promo-fade", "fade"], ["--promo-hold", "hold"]]) if (flags[f] !== undefined) k[key] = Number(flags[f]); if (Object.keys(k).length) o.promoKnobs = k; return o; } /** The options `umtool vertical`'s flags ask for (buildShort's), read from its parsed flags. */ export function shortOptionsOf(p) { return { project: p.positional[0], take: p.flags["--take"] ?? null, reel: p.flags["--reel"] ?? null, beats: p.has("--beats") ? p.flags["--beats"] : null, items: p.has("--items") ? p.flags["--items"].split(",").map((s) => s.trim()).filter(Boolean) : null, knobs: knobsOfFlags(p.flags), name: p.flags["--name"] ?? null, out: p.flags["--out"] ?? null, reframe: p.has("--reframe"), landscape: p.has("--landscape"), desktop: p.has("--desktop"), ...promoOptionsOf(p.flags), ...(p.has("--no-cold-open") ? { coldOpen: false } : {}), dryRun: p.has("--dry-run"), intro: p.has("--intro"), noIntro: p.has("--no-intro"), noOutro: p.has("--no-outro"), }; } /** * ONE SHORT, BUILT (the builder behind `umtool vertical` and `umtool shorts`): a take's items -- a reel's beats, a * beats file or a list of items -- natively in a 9:16 layout, recomposed from the master (`reframe`), or in the * take's 16:9 look (`landscape`). Writes the mp4 and its record beside it and returns the record; `dryRun` returns * what it would do instead. Throws a CliError (or the plan's VerticalPlanError) for a refusal. * * `overrides` (`{: {: value}}`, a batch's snapshot): laid over the PROJECT's own entries before the * plan reads them, so a rebuild from a record frames each clip as it was then. * * @param {{ project: string, take?: string | null, reel?: string | null, beats?: string | null, items?: string[] | null, * knobs?: Record, name?: string | null, out?: string | null, reframe?: boolean, landscape?: boolean, * dryRun?: boolean, intro?: boolean, noIntro?: boolean, noOutro?: boolean, overrides?: Record> | null, * desktop?: boolean, promo?: boolean, promoKnobs?: Record, coldOpen?: boolean, look?: Record | null }} o * @param {{ reportsRoot?: string, say?: (s: string) => void }} [ctx] * @returns {Promise<{ dryRun: Record } | { record: Record }>} */ export async function buildShort(o, { reportsRoot = REPORTS_ROOT, say = () => {} } = {}) { const V = await import("umtool-report-to-video/vertical"); const P = await import("umtool-report-to-video/vertical-plan"); const r = await resolveProject(o.project, reportsRoot); if (r.ambiguous) throw new CliError(`"${o.project}" is the name of ${r.ambiguous.length} projects — pass its id`); if (!r.project) throw new CliError(`no project matches "${o.project}"`); if (!kindMakesTakes(r.project.kind)) throw new CliError(`${r.project.id} is a ${r.project.kind}, not a report video`); const dir = r.project.dir; const reel = o.reel ?? null; let take = o.take ?? null; let beats = null; /** The reel's settings (its intro, outro and crossfade), when the short is a reel. */ let reelSettings = /** @type {Record} */ ({}); if (reel) { const doc = await readTrailerBeats(dir, { reel }); if (!doc.exists) throw new CliError(`no reel ${reel}: ${reelFileOf(reel)} is not there`); beats = P.beatsOf(doc.beats); reelSettings = doc.settings ?? {}; take ??= doc.settings?.take ?? null; } else if (o.beats) { const doc = await readJson(path.resolve(o.beats)); if (!doc) throw new CliError(`--beats ${o.beats}: not a JSON file`); beats = P.beatsOf(doc); } const items = o.items?.length ? o.items : null; if (!beats && !items) throw new CliError("--reel , --beats FILE or --items ,…: what the short is made of"); if (!take) throw new CliError("--take : the take whose items the short is cut from"); if (!/^[a-z0-9][a-z0-9-]*$/.test(take)) throw new CliError(`--take ${take}: a take id`); const takeDir = path.join(takesDirOf(dir), take); const takeManifestFrozen = await takeManifestOf(dir, take); const projectManifest0 = await readJson(path.join(dir, "video.manifest.json")); // The PROJECT's recording boxes (render.censor) are added to a take's -- a rendered take's render is frozen, and a // region hidden since must never show in a short of it. ADD-ONLY: the take's own boxes stay. const takeManifest0 = withProjectCensor(takeManifestFrozen, projectManifest0?.render?.censor); // A rebuild from a batch's record (`o.look`, LOOK_SNAPSHOT_KEYS) lays the look it was built with over the take's. const takeManifest = isObj(o.look) ? { ...takeManifest0, render: { ...(takeManifest0.render ?? {}), ...lookFromSnapshot(o.look, { projectDir: dir }) } } : takeManifest0; const projectManifest = await readJson(path.join(dir, "video.manifest.json")); const outDir = path.join(takeDir, "out"); const sourced = path.join(outDir, "sourced"); const schedule = await readJson(path.join(sourced, "schedule.json")); const knobs = o.knobs ?? {}; // A desktop build reads its own knobs (render.desktop: a corner a short does not have is one it does). const errors = o.desktop || o.landscape ? [] : V.validateVerticalRender({ render: { format: "vertical", vertical: { ...(takeManifest.render?.vertical ?? {}), ...knobs } } }); if (errors.length) throw new CliError(errors.join("; ")); const name = P.shortName({ reel, name: o.name ?? null }); const reframe = !!o.reframe; // `landscape`: the same items in the take's own 16:9 look (a side post as a panel), for comparison. const landscape = !!o.landscape; // `desktop` (lane clip-kit): the same clips 16:9 with minimal chrome, by this builder (vertical.mjs desktopGeometry). const desktop = !!o.desktop; if ([landscape, reframe, desktop].filter(Boolean).length > 1) throw new CliError("one of --landscape, --desktop and --reframe"); const dknobs = desktop ? desktopKnobsOf(knobs) : null; if (desktop) { const derr = V.validateDesktopRender({ render: { desktop: { ...(takeManifest.render?.desktop ?? {}), ...dknobs } } }); if (derr.length) throw new CliError(derr.join("; ")); } const tag = landscape ? "landscape" : desktop ? "desktop" : P.layoutTag(knobs, { reframe }); // The channel promo (promo-card.mjs): a per-clip build's; --promo asks for the cut's (none set: refused). if ((o.promo === true || o.promoKnobs) && !takeManifest.render?.promo) { throw new CliError(`--promo: the take sets no channel promo -- umtool look ${r.project.id} promo='{"name":"…","url":"https://…"}' (or a take's patch)`); } const promoArgs0 = o.promo === false ? ["--no-promo"] : o.promoKnobs ? ["--promo-knobs", JSON.stringify(o.promoKnobs)] : []; const slug = takeManifest.slug ?? r.project.id.split("/").pop(); const outFile = o.out ? path.resolve(o.out) : path.join(outDir, `${slug}.${name}.${tag}${landscape || desktop ? "" : ".vertical"}.mp4`); const cuts = new Map(); for (const e of takeManifest.timeline ?? []) { if (e?.type !== "clip") continue; const c = await readJson(path.join(sourced, "segments", `${e.id}.cut.json`)); if (c) cuts.set(e.id, c); } // The brand intro (9:16) and the reel's outro card (outro.mjs), added after the short is made. const introSpec = o.noIntro ? null : isObj(reelSettings.intro) ? reelSettings.intro : (o.intro || reelSettings.intro === true) ? true : null; let outro = null; const ro = o.noOutro ? null : resolveOutro(reelSettings.outro, { reelTitle: reelSettings.title ?? null, projectTitle: projectManifest?.title ?? null }); if (ro) { if (!ro.title) throw new CliError(`the reel ${reel}'s outro has no title: give it one (\`umtool trailer-beats ${r.project.id} --reel ${reel} outro '{"title":"…"}'\`)`); const imageFile = ro.image ? path.join(dir, ro.image) : null; if (imageFile && !existsSync(imageFile)) throw new CliError(`the reel ${reel}'s outro image ${ro.image} is not a file of ${r.project.id}`); outro = { ...ro, imageFile }; } const project = P.withOverrides(projectManifest?.timeline ?? [], o.overrides ?? null); // A clip's cold open (vertical-plan.mjs coldOpenEntry) plays in a short or a desktop clip of the bare builder: not // in the take's 16:9 look, a reframe or the stacked deck (each cut from a finished or crossfaded cut). const stacked = !desktop && !landscape && !reframe && V.stackedDeckWanted({ ...(takeManifest.render ?? {}), format: "vertical", vertical: { ...(takeManifest.render?.vertical ?? {}), ...knobs } }); const coldOpens = o.coldOpen !== false && !landscape && !reframe && !stacked; const plan = P.planVerticalCut({ timeline: takeManifest.timeline ?? [], beats, items, schedule, cuts, project, coldOpens }); // The channel promo ends the short only when its last piece is a whole clip (promo-card.mjs): then a reel's outro // card is not added after it (one ending, said). const notes = []; const lastPiece = plan.pieces.at(-1); const lastEntry = lastPiece ? plan.timeline.find((e) => e.id === lastPiece.id) : null; const promoEnds = !landscape && !reframe && !stacked && o.promo !== false && !!takeManifest.render?.promo && lastEntry?.type === "clip" && lastEntry.promo !== false && lastPiece.to === null && !lastPiece.from; const promoArgs2 = !landscape && !reframe && !stacked && o.promo !== false && takeManifest.render?.promo && !promoEnds ? ["--no-promo"] : []; if (!promoEnds && promoArgs2.length && lastEntry) notes.push(`the short ends on ${lastEntry.id}${lastEntry.type === "clip" ? " cut short of its end" : `, a ${lastEntry.type}`}: no channel promo (it ends a whole clip)`); if (promoEnds && outro) { notes.push(`the channel promo ends the short: the reel's outro card is not added after it`); outro = null; } // Every clip's hidden regions as this build draws them (the take's, the project's added: clip-censor.mjs). A reframe // cuts the take's FINISHED picture, which hides only what the take was rendered with: a region hidden since is // refused by name, never cut showing. const C = await import("umtool-report-to-video/clip-censor"); const baseId = (id) => String(id).replace(/~(?:\d+|co)$/, ""); const frozenById = new Map((takeManifestFrozen.timeline ?? []).map((e) => [e?.id, e])); const hidden = Object.fromEntries(plan.timeline.filter((e) => e?.type === "clip").map((e) => [e.id, C.censorRegionsOf(e, takeManifest.render ?? {}, takeManifest.provenance ?? {}).length])); if (reframe) { const since = plan.timeline.filter((e) => e?.type === "clip").filter((e) => { const was = frozenById.get(baseId(e.id)); const now = C.censorRecordOf(C.censorRegionsOf(e, takeManifest.render ?? {}, takeManifest.provenance ?? {})); const then = was ? C.censorRecordOf(C.censorRegionsOf(was, takeManifestFrozen.render ?? {}, takeManifestFrozen.provenance ?? {})) : []; return JSON.stringify(now) !== JSON.stringify(then); }); if (since.length) { throw new CliError(`--reframe cuts take ${take}'s finished picture, which does not hide the regions set since it was rendered on ${since.map((e) => `${baseId(e.id)} (${hidden[e.id]} box(es))`).join(", ")}: render the take again, or build the short without --reframe`); } } if (o.dryRun) { return { dryRun: { project: r.project.id, take, name, layout: tag, wouldWrite: outFile, hidden, intro: introSpec ? (introSpec === true ? "the take's render.intro, else the default" : introSpec) : null, outro: outro ? { title: outro.title, text: outro.text, image: outro.image, seconds: outro.seconds } : null, pieces: plan.pieces, items: plan.timeline.map((e) => ({ id: e.id, type: e.type, start: e.start, end: e.end })), promo: promoEnds, notes } }; } const started = Date.now(); // The project's fetched windows (and narration) are the take's too, as a made take's are (takeMaker.mjs // linkSharedOut): a draft take that was never rendered has no out/clips-raw of its own to cut from. if (!reframe) { // Through ensureWriteDir: a tiered project's out/ is a link to the media root, never replaced by a directory. const { linkSharedOut } = await import("./takeMaker.mjs"); await linkSharedOut(dir, await ensureWriteDir(outDir)); if (landscape) await linkSharedOut(dir, await ensureWriteDir(path.join(takeDir, `out-landscape-${name}`))); } let made; if (reframe) { const RF = await import("umtool-report-to-video/reframe"); made = await RF.reframeTake({ takeDir, outDir, slug, beats, items, plan, render: { ...takeManifest.render, vertical: { ...(takeManifest.render?.vertical ?? {}), ...knobs } }, outFile, log: say }); } else if (landscape) { const renderPath = path.join(dir, `.vertical-${take}-${name}.render.json`); await writeFile(renderPath, JSON.stringify({ ...takeManifest, render: P.renderForPart(takeManifest.render, plan.timeline), timeline: plan.timeline }, null, 2) + "\n", "utf8"); const own = path.join(takeDir, `out-landscape-${name}`); const argv = [process.execPath, path.join(PIPELINE_DIR, "build-video.mjs"), renderPath, "--out", own, "--skip-fetch", "--no-chapters"]; say(`vertical --landscape: building ${plan.timeline.length} item(s) 16:9 in the heavy slot …`); const code = await run(argv, { cwd: path.join(UMTOOL_DIR, ".."), log: say }).finally(() => rm(renderPath, { force: true })); if (code !== 0) throw new CliError(`the landscape build exited ${code}`); const RF = await import("umtool-report-to-video/reframe"); await mkdir(path.dirname(outFile), { recursive: true }); await writeFile(outFile, await readFile(path.join(own, `${slug}.mp4`))); made = { seconds: await RF.probeSeconds(outFile), loudness: null }; } else if (desktop) { // The desktop build (build-video --desktop): the take's render, the planned items, the desktop knobs over its own. const renderPath = path.join(dir, `.desktop-${take}-${name}.render.json`); await writeFile(renderPath, JSON.stringify({ ...takeManifest, render: P.renderForPart(takeManifest.render, plan.timeline), timeline: plan.timeline }, null, 2) + "\n", "utf8"); const work = `desktop-${name}`; const built = path.join(outDir, `${slug}.${name}.desktop-build.mp4`); const sections = V.sectionTitlesOf(takeManifest); const argv = [ process.execPath, path.join(PIPELINE_DIR, "build-video.mjs"), renderPath, "--out", outDir, "--skip-fetch", "--no-chapters", "--desktop", "--desktop-knobs", JSON.stringify(dknobs), "--vertical-work", work, "--vertical-out", built, ...(promoArgs2.length ? promoArgs2 : promoArgs0), "--vertical-sections", JSON.stringify(Object.fromEntries(plan.timeline.map((e) => [e.id, sections.get(e.id.replace(/~(?:\d+|co)$/, "")) ?? null]))), ]; say(`vertical --desktop: building ${plan.timeline.length} item(s) 16:9 in the heavy slot …`); const code = await run(argv, { cwd: path.join(UMTOOL_DIR, ".."), log: say }).finally(() => rm(renderPath, { force: true })); if (code !== 0) throw new CliError(`the desktop build exited ${code}`); const RF = await import("umtool-report-to-video/reframe"); const dk = V.desktopKnobs({ desktop: { ...(takeManifest.render?.desktop ?? {}), ...dknobs } }); made = await RF.assembleShort({ pieces: plan.pieces, segmentsDir: path.join(outDir, work, "segments"), built, outFile, schedule: null, render: { ...takeManifest.render, vertical: { loudness: dk.loudness } }, log: say, }); } else { // The build's manifest: the take's render, the planned items; beside the project's manifest, so its files resolve. const renderPath = path.join(dir, `.vertical-${take}-${name}.render.json`); const doc = { ...takeManifest, timeline: plan.timeline }; await writeFile(renderPath, JSON.stringify(doc, null, 2) + "\n", "utf8"); const work = `vertical-${name}-${tag}`; const sections = V.sectionTitlesOf(takeManifest); const built = path.join(outDir, `${slug}.${name}.${tag}.vertical-build.mp4`); const argv = [ process.execPath, path.join(PIPELINE_DIR, "build-video.mjs"), renderPath, "--out", outDir, "--skip-fetch", "--no-chapters", "--vertical", "--vertical-knobs", JSON.stringify(knobs), "--vertical-work", work, "--vertical-out", built, ...(promoArgs2.length ? promoArgs2 : promoArgs0), // The hook "section" names a clip's section in the WHOLE take (each planned entry under its source's id). "--vertical-sections", JSON.stringify(Object.fromEntries(plan.timeline.map((e) => [e.id, sections.get(e.id.replace(/~(?:\d+|co)$/, "")) ?? null]))), ]; say(`vertical: building ${plan.timeline.length} item(s) 9:16 in the heavy slot …`); const code = await run(argv, { cwd: path.join(UMTOOL_DIR, ".."), log: say }).finally(() => rm(renderPath, { force: true })); if (code !== 0) throw new CliError(`the vertical build exited ${code}`); const RF = await import("umtool-report-to-video/reframe"); made = await RF.assembleShort({ pieces: plan.pieces, segmentsDir: path.join(outDir, work, "segments"), built, outFile, // A stacked vertical deck's pieces are cut from the built cut (its deck laid over it), at the build's places. schedule: V.stackedDeckWanted({ ...(takeManifest.render ?? {}), format: "vertical", vertical: { ...(takeManifest.render?.vertical ?? {}), ...knobs } }) ? await readJson(path.join(outDir, work, "schedule.json")) : null, render: { ...takeManifest.render, vertical: { ...(takeManifest.render?.vertical ?? {}), ...knobs } }, log: say, }); } // The intro before and the card after, in one pass, in the heavy slot (the intro is a HyperFrames render, cached). let wrapped = { intro: null, outro: null }; if ((introSpec || outro) && !landscape && !desktop) { const { wrapShort } = await import("umtool-report-to-video/reel-intro"); const RF = await import("umtool-report-to-video/reframe"); const slot = await heavySlot(); // The 9:16 end card (outro.mjs) -- the stacked deck's only: a bare short's outro is the card it always was. const endCard = await endCardOf({ render: takeManifest.render ?? {}, knobs, provenance: takeManifest.provenance ?? {}, timeline: plan.timeline, schedule: reframe || landscape ? null : await readJson(path.join(outDir, `vertical-${name}-${tag}`, "schedule.json")), }); wrapped = await slot(["umtool", "vertical", r.project.id, "--take", take, ...(reel ? ["--reel", reel] : []), "(intro/outro)"], () => wrapShort({ file: outFile, takeDir, render: takeManifest.render ?? {}, manifest: takeManifest, introSpec, outro, xfade: typeof reelSettings.xfade === "number" ? reelSettings.xfade : 0.3, log: say, endCard, })); made = { ...made, seconds: await RF.probeSeconds(outFile) }; } const record = { version: 1, kind: "vertical-short", project: r.project.id, take, name, layout: tag, reframe, knobs, ...(o.promo === false ? { promo: false } : o.promoKnobs ? { promo: o.promoKnobs } : {}), ...(o.coldOpen === false ? { coldOpen: false } : {}), pieces: plan.pieces, ...(wrapped.intro ? { intro: wrapped.intro } : {}), ...(wrapped.outro ? { outro: wrapped.outro } : {}), seconds: made.seconds, loudness: made.loudness ?? null, look: lookSnapshotOf(takeManifest.render, { projectDir: dir }), notes: [...notes, ...V.verticalNotes({ format: "vertical", vertical: desktop ? { maxSeconds: V.desktopKnobs({ desktop: { ...(takeManifest.render?.desktop ?? {}), ...dknobs } }).maxSeconds } : knobs }, made.seconds)], out: outFile, madeAt: new Date().toISOString(), buildSeconds: Math.round((Date.now() - started) / 1000), }; await writeFile(outFile.replace(/\.mp4$/, ".json"), JSON.stringify(record, null, 2) + "\n", "utf8"); return { record }; } /** A take's render with the project's recording boxes added (each once); the take as it is when there are none. */ export function withProjectCensor(take, projectCensor) { if (!Array.isArray(projectCensor) || !projectCensor.length) return take; const have = Array.isArray(take?.render?.censor) ? take.render.censor : []; const added = projectCensor.filter((r) => !have.some((x) => JSON.stringify(x) === JSON.stringify(r))); return added.length ? { ...take, render: { ...(take.render ?? {}), censor: [...have, ...added] } } : take; } /** A take's manifest as rendered, else (a draft, never rendered) the project's with the take's patch laid on. */ export async function takeManifestOf(dir, take) { const rendered = await readJson(path.join(takesDirOf(dir), take, "video.manifest.json")); if (rendered) return rendered; const { resolveTakeManifest } = await import("./takeManifest.mjs"); return resolveTakeManifest(dir, take).then((x) => x.manifest, (e) => { throw new CliError(`take ${take}: ${e instanceof Error ? e.message : e}`); }); } /** * `umtool vertical …` * @param {string[]} args everything after `vertical` * @param {{ reportsRoot?: string, log?: (s: string) => void, err?: (s: string) => void }} [opts] * @returns {Promise} */ export async function verticalCommand(args, { reportsRoot = REPORTS_ROOT, log = console.log, err = console.error } = {}) { try { const p = parse(args); if (p.has("--help") || !p.positional.length) { log(VERTICAL_USAGE); return p.has("--help") ? 0 : 2; } const json = p.has("--json"); const say = json ? err : log; const done = await buildShort(shortOptionsOf(p), { reportsRoot, say }); if ("dryRun" in done) { const out = done.dryRun; log(json ? JSON.stringify(out, null, 2) : [`would write ${out.wouldWrite}`, ...(out.intro ? [" (intro, 9:16)"] : []), ...out.pieces.map((x) => ` ${x.id}${x.to === null ? "" : ` ${x.from}–${x.to}`}`), ...(out.outro ? [` (outro card "${out.outro.title}", ${out.outro.seconds} s)`] : [])].join("\n")); return 0; } const record = done.record; if (json) log(JSON.stringify(record, null, 2)); else { for (const n of record.notes) log(`note: ${n}`); log(`wrote ${record.out} (${record.seconds.toFixed(1)} s, ${record.layout === "landscape" || record.layout === "desktop" ? "1920x1080" : "1080x1920"})`); } return 0; } catch (e) { if (isRefusal(e)) { err(`umtool vertical: ${e.message}`); return 2; } throw e; } } /** A refusal (said, exit 2) rather than a crash. */ export const isRefusal = (e) => e instanceof CliError || e?.name === "VerticalPlanError";