import pathlib,json,subprocess
root=pathlib.Path(__file__).parent
for side,label in [('base','before'),('head','after')]:
 data=json.loads((root/(side+'-focus')/'measurements.json').read_text())
 last=data['results'][-1]['elapsedMs']/1000
 source=next((root/(side+'-focus')).glob('*.webm'))
 subprocess.run(['ffmpeg','-hide_banner','-loglevel','error','-sseof',str(-last-1.3),'-i',str(source),'-vf','tpad=stop_mode=clone:stop_duration=2','-c:v','libx264','-preset','fast','-crf','23','-an','-y',str(root/(label+'-focus.mp4'))],check=True)
