import { execFileSync } from "node:child_process"; import { mkdtemp, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import sharp from "sharp"; const source = "public/blog/fox-courier-first-frame.webp"; const dest = "public/blog"; const frames = await mkdtemp(path.join(tmpdir(), "clout-sketch-study-")); const staticPanel = await sharp(source).resize(600, 338).png().toBuffer(); const header = Buffer.from( `A moving crop is not a new character actionOriginal editorial illustration in a conventional six-second camera studyFixed source viewDigital push toward the same drawingWatch the ears, satchel, paws and mailboxThe drawing stays frozen while the right crop tightens by eight percentNo AI video generation, new gesture, perspective reconstruction or audio`, ); const selected: Buffer[] = []; for (let i = 0; i < 144; i++) { const zoom = 1 + (0.08 * i) / 143; const w = Math.round(600 * zoom), h = Math.round(338 * zoom); const moving = await sharp(source) .resize(w, h) .extract({ left: Math.floor((w - 600) / 2), top: Math.floor((h - 338) / 2), width: 600, height: 338, }) .png() .toBuffer(); const frame = await sharp(header) .composite([ { input: staticPanel, left: 40, top: 200 }, { input: moving, left: 660, top: 200 }, ]) .png() .toBuffer(); await writeFile(path.join(frames, `${String(i).padStart(4, "0")}.png`), frame); if ([0, 72, 143].includes(i)) selected.push(moving); if (i === 0) await sharp(frame).webp({ quality: 92 }).toFile(`${dest}/sketch-camera-study-poster.webp`); } execFileSync( "/opt/homebrew/bin/ffmpeg", [ "-y", "-framerate", "24", "-i", path.join(frames, "%04d.png"), "-c:v", "libx264", "-crf", "20", "-pix_fmt", "yuv420p", "-movflags", "+faststart", `${dest}/sketch-camera-study.mp4`, ], { stdio: "ignore" }, ); const sheet = Buffer.from( `The crop changes while the pose stays fixed${["Opening at 0 ms", "Midpoint at 3000 ms", "Last frame at 5958 ms"].map((s, i) => `${s}`).join("")}Original conventional edit — not generated character motion or a model comparison`, ); await sharp(sheet) .composite( await Promise.all( selected.map(async (input, i) => ({ input: await sharp(input).resize(510, 287).png().toBuffer(), left: 30 + i * 530, top: 155, })), ), ) .webp({ quality: 92 }) .toFile(`${dest}/sketch-camera-study-frames.webp`); await writeFile( `${dest}/sketch-camera-study.vtt`, "WEBVTT\n\n00:00.000 --> 00:06.000\nLeft: fixed fox courier illustration. Right: the same drawing slowly crops inward. The fox does not move. No audio.\n", ); console.log({ frames: 144, fps: 24, seconds: 6, dimensions: "1280x720", source, temporaryFrames: frames, });