from pathlib import Path
import subprocess
import argparse
p=argparse.ArgumentParser()
p.add_argument('directory', type=Path)
a=p.parse_args()
for side, start, end in [('base',18.8,33.4),('head',18.8,22.1)]:
    filters=[]
    if side == 'head':
        # Hide only fixture path subtitles; checkout names remain visible.
        for y in [287,331]:
            filters.append(f"drawbox=x=888:y={y}:w=282:h=26:color=white:t=fill:enable='between(t,0.300,0.600)+between(t,2.167,2.433)+between(t,2.733,2.967)'")
        filters.append('setpts=3*(PTS-STARTPTS)')
        filters.append('tpad=stop_mode=clone:stop_duration=2')
    title = ('Before d8f3feff0c' if side=='base' else 'After 34ba4f626c')
    title += ' | Web Chromium | 1280x1200 | light theme'
    if side=='head': title += ' | 3x slower; fixture paths redacted'
    filters += [f"drawtext=text='{title}':x=40:y=1140:fontsize=20:fontcolor=black:box=1:boxcolor=white:boxborderw=10",'fps=30']
    subprocess.run(['ffmpeg','-y','-hide_banner','-loglevel','error','-ss',str(start),'-t',str(end-start),'-i',str(a.directory/(side+'-original.webm')),'-vf',','.join(filters),'-an','-c:v','libx264','-crf','19','-pix_fmt','yuv420p','-movflags','+faststart',str(a.directory/(side+'-reproduction.mp4'))],check=True)
