import asyncio,base64,json,subprocess,sys from playwright.async_api import async_playwright OUT='/home/claude/afterlight/film2/build';import os;os.makedirs(OUT,exist_ok=True) async def main(): async with async_playwright() as p: b=await p.chromium.launch();pg=await b.new_page(viewport={'width':1280,'height':720}) errs=[];pg.on('pageerror',lambda e:errs.append(str(e))) await pg.goto('http://localhost:8765/film2/smallsun.html');await pg.evaluate('SS.load()') END=await pg.evaluate('SS.T.END');n=int(END*24) ff=subprocess.Popen(['ffmpeg','-v','error','-y','-f','image2pipe','-framerate','24','-c:v','mjpeg','-i','-','-c:v','libx264','-preset','veryfast','-crf','17','-pix_fmt','yuv420p',f'{OUT}/picture.mp4'],stdin=subprocess.PIPE) for i in range(n): d=await pg.evaluate(f"(SS.frame({i}/24),document.getElementById('c').toDataURL('image/jpeg',0.93))") ff.stdin.write(base64.b64decode(d.split(',',1)[1])) if i%240==0:print(i/24,flush=True) ff.stdin.close();ff.wait() json.dump(await pg.evaluate('SS.EV'),open(f'{OUT}/events.json','w')) print('errors',errs[:3],'frames',n);await b.close() asyncio.run(main())