"""Usage: python3 export-video-frames.py <scripts/.e2e/prove> <output-directory>.
Exports inspected frames from the proof recordings; the source videos are unmodified.
"""
import pathlib
import subprocess
import sys

proof = pathlib.Path(sys.argv[1])
out = pathlib.Path(sys.argv[2])
out.mkdir(parents=True, exist_ok=True)
labels = ["file-settled-app", "file-pending-appv", "file-settled-appv", "image-settled-app", "image-pending-appv", "image-settled-appv"]
for side, times in [("base", [17, 18, 19.5, 23, 24, 25]), ("head", [16.5, 17.5, 18.5, 22.5, 23.5, 24])]:
    video = next((proof / side / "results").rglob("video.webm"))
    for label, seconds in zip(labels, times):
        subprocess.run(["ffmpeg", "-y", "-ss", str(seconds), "-i", str(video), "-frames:v", "1", str(out / f"{side}-{label}.png"), "-loglevel", "error"], check=True)
    subprocess.run(["ffmpeg", "-y", "-ss", "15.5", "-i", str(video), "-c:v", "libx264", "-crf", "18", "-pix_fmt", "yuv420p", str(out / f"{side}-pickers.mp4"), "-loglevel", "error"], check=True)
