"""Keep measured frames/timestamps; cover navigation containing environment labels.
Crop to the first three file headers to focus the interaction. The native
recording remains the measurement source; no measured transition is removed.
Usage: publish-video.py ORIGINAL MEASUREMENT_JSON OUTPUT_MP4
"""
import sys,json,subprocess
video,measurement,out=sys.argv[1:];m=json.load(open(measurement));start=(m['series'][0]['transitions'][-1]['tMs']+500)/1000;end=(m['series'][1]['transitions'][0]['tMs']-1000)/1000
vf=f"crop=1080:700:0:0,drawbox=x=0:y=0:w=iw:h=ih:color=black:t=fill:enable='between(t,{start},{end})',drawtext=text='Switching to the two-file baseline':fontcolor=white:fontsize=32:x=(w-tw)/2:y=(h-th)/2:enable='between(t,{start},{end})'"
subprocess.run(['ffmpeg','-v','error','-i',video,'-vf',vf,'-an','-c:v','libx264','-crf','18','-fps_mode','passthrough','-enc_time_base','demux',out],check=True)
