// `umtool check-joins --take [--json] [--all] [--limit ]` -- the measured check of a rendered // take's joins (report-to-video/check-joins.mjs): every boundary where the next post item draws a post the one before // showed, its planned join, and how alike the master's frames are across it. Read-only. import { existsSync } from "node:fs"; import path from "node:path"; import { checkJoins, joinsTable } from "umtool-report-to-video/check-joins"; import { REPORTS_ROOT, resolveProject } from "../projects/core.mjs"; import { takesDirOf } from "./takes.mjs"; class CliError extends Error {} export const CHECK_JOINS_USAGE = [ "usage: umtool check-joins --take [--json] [--all] [--limit ]", " Every boundary of the take's master where the next post item draws a post the one before showed (its post, a", " parent, the quote, a scene tile, a manual thread's stack): its planned join, the SSIM of the last frame before", " against the first after (over the post box), and the largest frame-to-frame change across it and its join.", " Worst first. --all: every post-to-post boundary. Read-only (ffmpeg reads the master).", ].join("\n"); export async function checkJoinsCommand(args, { reportsRoot = REPORTS_ROOT, log = console.log, err = console.error } = {}) { try { const words = []; const flags = {}; for (let i = 0; i < args.length; i += 1) { const a = args[i]; if (["--take", "--limit"].includes(a)) { if (i + 1 >= args.length) throw new CliError(`${a} needs a value`); flags[a] = args[++i]; } else if (["--json", "--all", "--help"].includes(a)) flags[a] = true; else if (a.startsWith("--")) throw new CliError(`unknown flag ${a}`); else words.push(a); } if (flags["--help"] || !words.length || !flags["--take"]) { log(CHECK_JOINS_USAGE); return flags["--help"] ? 0 : 2; } const r = await resolveProject(words[0], reportsRoot); if (r.ambiguous) throw new CliError(`"${words[0]}" is the name of ${r.ambiguous.length} projects — pass its id`); if (!r.project) throw new CliError(`no project matches "${words[0]}"`); const takeDir = path.join(takesDirOf(r.project.dir), String(flags["--take"])); if (!existsSync(path.join(takeDir, "out", "sourced", "schedule.json"))) throw new CliError(`${flags["--take"]}: no rendered take at ${takeDir} (out/sourced/schedule.json)`); const limit = flags["--limit"] ? Number(flags["--limit"]) : Infinity; if (!(limit > 0)) throw new CliError("--limit takes a positive number"); const got = await checkJoins(takeDir, { all: !!flags["--all"], onRow: flags["--json"] ? () => {} : (row) => err(` ${row.t.toFixed(2)} ${row.from} → ${row.to}: ssim ${row.ssim?.toFixed(3) ?? "-"}, jump ${row.jump}`) }); const rows = got.rows.slice(0, limit); if (flags["--json"]) { log(JSON.stringify({ take: flags["--take"], master: got.master, drift: got.offsets, rows }, null, 2)); return 0; } log(`${flags["--take"]}: ${got.rows.length} boundar${got.rows.length === 1 ? "y" : "ies"} where the next post item draws a post the one before showed${flags["--all"] ? " (--all: every post-to-post boundary)" : ""}, worst first`); if (got.offsets) log(` (the master's segments sit ${got.offsets.toFixed(3)} s after the schedule's by the end: the concat demuxer's file lengths)`); log(joinsTable(rows)); const bad = got.rows.filter((x) => x.verdict === "JUMPS" || x.verdict === "cut"); log(`${bad.length} jump or cut where a post stays on screen`); return 0; } catch (e) { err(e instanceof CliError ? `umtool check-joins: ${e.message}` : `umtool check-joins: ${e?.stack ?? e}`); return 1; } }