#!/usr/bin/env node // The variants encoder, STUBBED (E2E_UMTOOL_VARIANTS_SCRIPT, set in // playwright.config.ts): the command line of report-to-video/variants.mjs // (`node variants.mjs `, the manifest beside the out dir), and its // outputs -- `/..mp4` per rung and variants.json -- with no // ffmpeg: each "variant" is a copy of the first bytes of the build. The suite // tests the button, the job and the list, not an encode. import { readFile, writeFile } from "node:fs/promises"; import path from "node:path"; const outDir = path.resolve(process.argv[2] ?? ""); const manifest = JSON.parse(await readFile(path.join(path.dirname(outDir), "video.manifest.json"), "utf8")); const slug = manifest.slug; const ladder = Array.isArray(manifest.render?.variants) ? manifest.render.variants : [{ name: "master" }, { name: "1080p", height: 1080, crf: 22 }, { name: "720p", height: 720, crf: 23 }, { name: "fit24", maxMiB: 24 }]; // --source : a take whose render is only its preview.mp4 (variantsView buildFileOf). const at = process.argv.indexOf("--source"); const srcFile = at > 0 && process.argv[at + 1] ? path.resolve(process.argv[at + 1]) : path.join(outDir, `${slug}.mp4`); const source = await readFile(srcFile); const items = []; for (const [i, v] of ladder.entries()) { const bytes = v.name === "master" ? source : source.subarray(0, Math.max(1, Math.floor(source.length / (i + 1)))); await writeFile(path.join(outDir, `${slug}.${v.name}.mp4`), bytes); const height = v.height ?? (v.maxMiB ? 480 : 1080); items.push({ name: v.name, path: `${slug}.${v.name}.mp4`, width: Math.round((height * 16) / 9), height, bytes: bytes.length, kbps: 1000 }); console.log(`variant ${v.name}: ${bytes.length} bytes (stub)`); } await writeFile(path.join(outDir, "variants.json"), JSON.stringify({ at: new Date().toISOString(), source: path.basename(srcFile), items }, null, 2) + "\n");