#!/usr/bin/env python3 """Export the isolated website/social refresh; never upload or modify production.""" import argparse import datetime import hashlib import json import os from pathlib import Path import shutil import subprocess import time ROOT = Path(__file__).resolve().parents[2] BASE = ROOT / "output/video-refresh-20261023/workspace" OUT = Path(os.environ.get("JOTLEY_DELIVERY_ROOT", str(BASE / "delivery"))) ARCHIVE = Path("/Volumes/Music/Jotley/Jotley-2.0-App-Store-Videos/refresh-website-social-20261023") def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("group", choices=["remotion", "hyperframes", "portrait"]) args = parser.parse_args() if not Path("/Volumes/Music").is_mount() or not ARCHIVE.is_dir(): parser.error("Music must be mounted; render temporaries are kept off the internal disk") logdir = OUT / "render-jobs" logdir.mkdir(parents=True, exist_ok=True) env = dict(os.environ) temporary = ARCHIVE / "render-tmp" / args.group temporary.mkdir(parents=True, exist_ok=True) env["TMPDIR"] = str(temporary) + "/" jobs = [] def save(): (logdir / f"{args.group}.json").write_text(json.dumps(jobs, indent=2) + "\n") def run(name, command, cwd=BASE): log = logdir / (name + ".log") entry = {"name": name, "command": command, "cwd": str(cwd), "log": str(log), "state": "running", "started": datetime.datetime.now(datetime.timezone.utc).isoformat()} jobs.append(entry) save() print(json.dumps({"started": name, "log": str(log)}), flush=True) start = time.monotonic() with log.open("w") as handle: result = subprocess.run(command, cwd=cwd, env=env, stdout=handle, stderr=subprocess.STDOUT) entry.update(state="complete" if result.returncode == 0 else "failed", exit_code=result.returncode, elapsed_seconds=round(time.monotonic() - start, 2)) save() print(json.dumps({"finished": name, "state": entry["state"], "seconds": entry["elapsed_seconds"]}), flush=True) if result.returncode: raise SystemExit(result.returncode) def verify(path, width, height, duration): probe = json.loads(subprocess.check_output(["ffprobe", "-v", "error", "-show_streams", "-show_format", "-of", "json", str(path)])) video = next(s for s in probe["streams"] if s["codec_type"] == "video") assert (video["width"], video["height"]) == (width, height), path assert video["avg_frame_rate"] == "60/1", (path, video["avg_frame_rate"]) assert abs(float(probe["format"]["duration"]) - duration) < .15, path assert any(s["codec_type"] == "audio" for s in probe["streams"]), path run(path.stem + "-decode", ["ffmpeg", "-v", "error", "-i", str(path), "-f", "null", "-"]) checksum = hashlib.file_digest(path.open("rb"), "sha256").hexdigest() probe.update(full_decode=True, sha256=checksum) path.with_suffix(".verification.json").write_text(json.dumps(probe, indent=2) + "\n") def renditions(master, prefix, folder, duration): for label, width, height, crf, rate in [("1080p", 1920, 1080, 16, "16M"), ("720p", 1280, 720, 18, "6M")]: dest = folder / f"{prefix}-{label}.mp4" run(dest.stem, ["ffmpeg", "-v", "error", "-y", "-i", str(master), "-map", "0:v:0", "-map", "0:a:0", "-vf", f"scale={width}:{height}:flags=lanczos,setsar=1,format=yuv420p", "-r", "60", "-c:v", "libx264", "-preset", "medium", "-crf", str(crf), "-maxrate", rate, "-bufsize", "32M" if label == "1080p" else "12M", "-g", "120", "-c:a", "copy", "-movflags", "+faststart", str(dest)]) verify(dest, width, height, duration) films = OUT / "website/films" social = OUT / "social" films.mkdir(parents=True, exist_ok=True) social.mkdir(parents=True, exist_ok=True) if args.group == "remotion": version = os.environ.get("JOTLEY_MARKETING_VERSION", "v9") assert version in {"v9", "v10", "v11"} master = films / f"jotley-marketing-{version}-2160p.mp4" run(master.stem, ["npx", "remotion", "render", f"Jotley-Website-Marketing-{version}-4K", str(master), "--codec=h264", "--crf=14", "--x264-preset=medium", "--concurrency=3", "--image-format=png"], BASE / "remotion") verify(master, 3840, 2160, 5554 / 60) renditions(master, f"jotley-marketing-{version}", films, 5554 / 60) portrait = social / f"jotley-marketing-{version}-portrait-1080p.mp4" run(portrait.stem, ["npx", "remotion", "render", f"Jotley-Social-Marketing-{version}-Portrait", str(portrait), "--codec=h264", "--crf=14", "--x264-preset=medium", "--concurrency=3", "--image-format=png"], BASE / "remotion") verify(portrait, 1080, 1920, 5554 / 60) elif args.group == "hyperframes": items = [("tutorial-iphone-16x9", "jotley-tutorial-iphone-v4", 84.333), ("tutorial-ipad-16x9", "jotley-tutorial-ipad-v5", 71.528), ("tutorial-mac-16x9", "jotley-tutorial-mac-v4", 120.182), ("social-16x9", "jotley-social-ui-20261023", 32.25), ("social-9x16", "jotley-social-ui-20261023-portrait", 32.25)] for project, prefix, duration in items: vertical = project == "social-9x16" folder = social if project.startswith("social") else films master = folder / f"{prefix}-{'1080p' if vertical else '2160p'}.mp4" command = ["npx", "hyperframes", "render", "--output", str(master), "--quality", "delivery", "--crf", "14", "--fps", "60", "--workers", "2", "--video-frame-format", "png", "--strict", "--no-best-effort", "--sdr", "--frames-cache-dir", str(ARCHIVE / "render-source-cache")] if not vertical: command += ["--resolution", "4k"] run(master.stem, command, BASE / "composition" / project) verify(master, 1080 if vertical else 3840, 1920 if vertical else 2160, duration) if not vertical: renditions(master, prefix, folder, duration) else: run("portrait-iphone-ipad", ["python3", str(BASE / "portrait/build_portrait_jotley.py"), "iphone", "ipad"]) run("portrait-mac", ["python3", str(BASE / "portrait/build_portrait_jotley_mac.py")]) destination = social / "portrait-tutorials" shutil.copytree(BASE / "final-SOCIAL-portrait", destination, dirs_exist_ok=True) for device, duration in [("iPhone", 84.333), ("iPad", 71.528), ("Mac", 120.182)]: verify(destination / f"Jotley-{device}-Portrait-Tutorial-1080x1920-60fps.mp4", 1080, 1920, duration) print(json.dumps({"group": args.group, "state": "complete"}), flush=True) if __name__ == "__main__": main()