"""Redact connection addresses only; preserve original timing and UI states."""
import subprocess,sys
from PIL import Image,ImageDraw
src,dst=sys.argv[1:3];w,h=1080,2424
p=subprocess.Popen(['ffmpeg','-v','error','-i',src,'-vf','fps=15','-f','rawvideo','-pix_fmt','rgb24','-'],stdout=subprocess.PIPE)
q=subprocess.Popen(['ffmpeg','-y','-v','error','-f','rawvideo','-pix_fmt','rgb24','-s',f'{w}x{h}','-r','15','-i','-','-an','-c:v','libx264','-crf','21','-pix_fmt','yuv420p','-movflags','+faststart',dst],stdin=subprocess.PIPE)
while True:
 data=p.stdout.read(w*h*3)
 if len(data)!=w*h*3:break
 im=Image.frombytes('RGB',(w,h),data);d=ImageDraw.Draw(im)
 # The confirmation dialog hides the route addresses itself.
 modal=sum(im.getpixel((10,200)))<540
 rows=[(350,405),(425,475),(700,750)]
 if not modal:rows += [(975,1045),(1155,1220)]
 for y1,y2 in rows:d.rectangle((0,y1,w,y2),fill=(210,213,217))
 q.stdin.write(im.tobytes())
p.wait();q.stdin.close();q.wait()
