"""Convert the scenario recorder's padded webm to the browser's full 1440x1000 viewport.

Usage: python3 process-captures.py <prove-directory> <output-directory>
Only the recorder's empty right padding is removed; app content is preserved.
"""
import pathlib
import subprocess
import sys

proof = pathlib.Path(sys.argv[1])
output = pathlib.Path(sys.argv[2])
output.mkdir(parents=True, exist_ok=True)
for side in ("base", "head"):
    video = next((proof / side / "results").glob("*/attempt-1/video/*.webm"))
    subprocess.run([
        "ffmpeg", "-v", "error", "-i", str(video),
        "-vf", "crop=1152:800:0:0,scale=1440:1000",
        "-c:v", "libx264", "-preset", "fast", "-crf", "20",
        "-pix_fmt", "yuv420p", "-movflags", "+faststart",
        str(output / f"{side}.mp4"),
    ], check=True)
subprocess.run([
    "ffmpeg", "-v", "error", "-sseof", "-0.05", "-i", str(output / "head.mp4"),
    "-frames:v", "1", str(output / "head-custom-closed-settled.png"),
], check=True)
