import json, pathlib, subprocess, sys
proof = json.loads(pathlib.Path(sys.argv[1]).read_text())
out = pathlib.Path(sys.argv[2]); out.mkdir(exist_ok=True)
for side, start, y in [('base',12.5,388), ('head',14,340)]:
    capture = next(p for p in proof[side]['captures'] if p.endswith('002-search-t3-connect.png'))
    subprocess.run(['convert',capture,'-fill','#fafafc','-draw',f'rectangle 430,{y} 886,{y+18}','-fill','#82828c','-font','DejaVu-Sans','-pointsize','11','-annotate',f'+434+{y+13}','[workspace path redacted]',str(out/f'{side}-search-t3-connect.png')],check=True)
    video=proof[side]['videos'][0]
    subprocess.run(['ffmpeg','-y','-ss',str(start),'-i',video,'-t','4','-vf','crop=576:250:352:80,tpad=stop_mode=clone:stop_duration=3','-an','-c:v','libx264','-pix_fmt','yuv420p',str(out/f'{side}-search.mp4')],check=True,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
    subprocess.run(['ffmpeg','-y','-i',str(out/f'{side}-search.mp4'),'-vf','fps=2,tile=4x4','-frames:v','1',str(out/f'{side}-contact.png')],check=True,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
