import subprocess
from pathlib import Path
p = Path(__file__).parent

def run(*args):
    subprocess.run(["ffmpeg", "-hide_banner", "-loglevel", "error", "-y", *args], check=True)

font = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
run("-f", "lavfi", "-i", "color=c=0xf8f8fa:s=1280x800:r=30:d=3", "-vf", f"drawtext=fontfile={font}:text='T3 Code server restarted':fontsize=42:fontcolor=0x222222:x=(w-tw)/2:y=330,drawtext=fontfile={font}:text='Same T3 home and thread - no intervening message':fontsize=25:fontcolor=0x555555:x=(w-tw)/2:y=410", "-c:v", "libx264", "-pix_fmt", "yuv420p", str(p / "restart.mp4"))
for side, stop, follow in [("before", "base-stop-raw.mp4", "base-followup-raw.mp4"), ("after", "head-stop-final.mp4", "head-followup-final.mp4")]:
    run("-i", str(p/stop), "-i", str(p/"restart.mp4"), "-i", str(p/follow), "-filter_complex", "[0:v]trim=duration=12,setpts=PTS-STARTPTS,scale=1280:800,fps=30,setsar=1[a];[1:v]setpts=PTS-STARTPTS,setsar=1[b];[2:v]trim=duration=12,setpts=PTS-STARTPTS,scale=1280:800,fps=30,setsar=1[c];[a][b][c]concat=n=3:v=1:a=0[out]", "-map", "[out]", "-c:v", "libx264", "-preset", "fast", "-crf", "18", "-pix_fmt", "yuv420p", "-movflags", "+faststart", str(p/(side+".mp4")))
