// HyperFrames' distributed rendering, one step per command, for hf-fanout. // Lives in ~/render-api, next to @hyperframes/producer. Frame rate: HF_FPS, default 30. // node hf-chunks.mjs plan [quality] [variables-json] // node hf-chunks.mjs chunk // node hf-chunks.mjs assemble ... // Each prints one JSON line, prefixed "RESULT ", when it succeeds. import { readFileSync } from "node:fs"; import { join } from "node:path"; import { planV2, renderChunkV2, assembleV2 } from "@hyperframes/producer/distributed"; const [cmd, ...args] = process.argv.slice(2); const done = (o) => { console.log("RESULT " + JSON.stringify(o)); process.exit(0); }; if (cmd === "plan") { const [projectDir, planDir, chunks, quality = "standard", vars] = args; // The composition's size, from data-width/data-height in index.html. const html = readFileSync(join(projectDir, "index.html"), "utf8"); const num = (attr, dflt) => Number(html.match(new RegExp(`${attr}="(\\d+)"`))?.[1] ?? dflt); const r = await planV2(projectDir, { fps: Number(process.env.HF_FPS ?? 30), width: num("data-width", 1920), height: num("data-height", 1080), format: "mp4", quality, maxParallelChunks: Number(chunks), minParallelChunks: Number(chunks), ...(vars ? { variables: JSON.parse(vars) } : {}), }, planDir); done({ chunkCount: r.chunkCount, totalFrames: r.totalFrames, planHash: r.planHash }); } else if (cmd === "chunk") { const [planDir, index, out] = args; await renderChunkV2(planDir, Number(index), out); done({ index: Number(index), out }); } else if (cmd === "assemble") { const [planDir, out, ...chunks] = args; await assembleV2(planDir, chunks, out); done({ out }); } else { console.error("usage: hf-chunks.mjs plan|chunk|assemble ..."); process.exit(2); }