"""Redact address and code fields in a 1080x2424 pairing capture.
Usage: python redact.py INPUT OUTPUT [FORM_END_SECONDS]
For videos FORM_END_SECONDS bounds redaction to the pairing form before navigation.
"""
import subprocess,sys
source,dest=sys.argv[1:3]
enable = ":enable='lt(t,%s)'" % sys.argv[3] if len(sys.argv)>3 else ''
filters=[]
for y,label in [(1056,'Address redacted'),(1176, 'XXXX XXXX XXXX (redacted)' if 'spaces' in dest else 'XXXX-XXXX-XXXX (redacted)')]:
    filters += [f'drawbox=x=280:y={y}:w=730:h=80:color=0xf3f3f5:t=fill'+enable,
                f"drawtext=text='{label}':x=292:y={y+22}:fontsize=34:fontcolor=0x444444"+enable]
args=['ffmpeg','-y','-i',source,'-vf',','.join(filters)]
args += ['-frames:v','1'] if dest.endswith('.png') else ['-t','20','-c:v','libx264','-crf','20','-pix_fmt','yuv420p','-an']
subprocess.run(args+[dest,'-loglevel','error'],check=True)
