File size: 1,494 Bytes
6fff8e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import asyncio, sys, json, base64
from playwright.async_api import async_playwright
BASE = "http://localhost:5173/preview/production/1b822e06-b78d-4352-884d-1f8fddabf546/"
async def main():
    o = json.loads(sys.argv[1]); out = sys.argv[2]
    async with async_playwright() as p:
        b = await p.chromium.launch()
        pg = await b.new_page()
        errs = []
        pg.on("pageerror", lambda e: errs.append("PAGEERROR " + str(e)))
        pg.on("console", lambda m: errs.append(m.type + ": " + m.text) if m.type in ("error",) else None)
        await pg.goto(BASE + "?still=0&w=100")
        await pg.wait_for_function("document.title==='ready'", timeout=60000)
        r = await pg.evaluate("""async (o) => {
          const m = await import('./src/video/export.ts');
          const ac = new AbortController();
          let last;
          const t0 = performance.now();
          const res = await m.exportMp4(o, (p) => { last = p }, ac.signal);
          const buf = new Uint8Array(await res.blob.arrayBuffer());
          let bin = ''; for (let i = 0; i < buf.length; i += 0x8000) bin += String.fromCharCode.apply(null, buf.subarray(i, i + 0x8000));
          return { codec: res.codec, size: buf.length, ms: Math.round(performance.now() - t0), b64: btoa(bin), last };
        }""", o)
        open(out, 'wb').write(base64.b64decode(r.pop('b64')))
        print(json.dumps(r, ensure_ascii=False))
        for e in errs[:20]: print(e)
        await b.close()
asyncio.run(main())