Branchwell

PulseCanvas / website / scripts / prepare-media.py

1"""Prepare website assets from completed app captures without operating the app."""
2from pathlib import Path
3import argparse
4import subprocess
5
6parser = argparse.ArgumentParser(description=__doc__)
7parser.add_argument("--captures", type=Path, required=True,
8 help="Directory containing finished octagon, mercury, grid, studio, audio, and style MP4 captures")
9parser.add_argument("--outputs", type=Path, required=True,
10 help="Deliverables directory containing Halo-Engine.png and Ink-Cyclone.png")
11args = parser.parse_args()
12public = Path(__file__).resolve().parent.parent / "public"
13(public / "images").mkdir(exist_ok=True)
14(public / "media").mkdir(exist_ok=True)
15
16
17def ffmpeg(arguments: list[str]) -> None:
18 subprocess.run(["ffmpeg", "-y", "-hide_banner", "-loglevel", "error", *arguments], check=True)
19
20
21for name in ["octagon", "mercury", "grid"]:
22 source = str(args.captures / f"{name}.mp4")
23 ffmpeg(["-i", source, "-an", "-vf", "scale=1112:626,fps=24", "-c:v", "libx264",
24 "-preset", "fast", "-crf", "25", "-movflags", "+faststart",
25 str(public / "media" / f"{name}.mp4")])
26 ffmpeg(["-ss", "3", "-i", source, "-frames:v", "1", "-q:v", "82",
27 str(public / "images" / f"{name}.webp")])
28
29for name, time in [("studio", 3), ("audio", 4), ("style", 4)]:
30 ffmpeg(["-ss", str(time), "-i", str(args.captures / f"{name}.mp4"), "-frames:v", "1",
31 "-q:v", "92", str(public / "images" / f"app-{name}.webp")])
32
33for source, target in [("Halo-Engine.png", "halo"), ("Ink-Cyclone.png", "ink")]:
34 ffmpeg(["-i", str(args.outputs / source), "-frames:v", "1", "-q:v", "85",
35 str(public / "images" / f"{target}.webp")])
36
37print("Prepared silent visualizer footage, poster images, and real app screenshots.")