# Usage: python3 prepare-video.py RUN_DIRECTORY
# Trim only the initial app load, retaining three seconds before the scripted race
# through the recorded chat recovery. No frames inside the interaction are removed.
import json, pathlib, subprocess, sys
p = pathlib.Path(sys.argv[1])
t = json.loads((p / 'video-offsets.json').read_text())
subprocess.run(['ffmpeg', '-y', '-ss', str(max(0, t['raceStart'] - 3)), '-i', str(p / 'interaction.webm'), '-c:v', 'libx264', '-preset', 'fast', '-crf', '22', '-pix_fmt', 'yuv420p', '-an', '-movflags', '+faststart', str(p / 'interaction.mp4')], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
