import sys,csv
from pathlib import Path
from PIL import Image,ImageDraw
src=Path(sys.argv[1]); dest=Path(sys.argv[2]);dest.mkdir(exist_ok=True)
rows=list(csv.reader((src/'frames.csv').read_text().splitlines()))
lines=[]
for i,(name,t) in enumerate(rows):
 p=src/name
 if not p.exists():continue
 im=Image.open(p).convert('RGB');d=ImageDraw.Draw(im)
 # Redact machine labels and runtime locations without changing app controls.
 if 'head' in src.name:
  for box in [(454,116,530,139),(1185,64,1260,90),(472,188,620,207)]:d.rectangle(box,fill='#e5e5e5')
 elif im.getpixel((660,310))==(255,255,255):
  for box in [(996,378,1235,400),(676,400,800,415),(1010,701,1248,723),(880,460,1180,480)]:d.rectangle(box,fill='#e5e5e5')
 else:d.rectangle((454,116,530,139),fill='#e5e5e5')
 im.save(dest/name)
 lines.append("file '"+str(dest/name)+"'")
 duration=float(rows[i+1][1])-float(t) if i+1<len(rows) else .6
 lines.append('duration '+str(duration))
(dest/'frames.txt').write_text('\n'.join(lines)+'\n')
print(len(rows),'frames',rows[-1][1],'seconds')
