Skip to content

PasteFerry (隔空贴): clipboard and file sync across macOS, Windows and Linux. Direct-first, end-to-end encrypted. Optional official access: no server to host. Independent self-hosting remains available.

1.8 KB
Raw Blame
// Deterministic portrait frames. Only the local, synthetic film is rendered.
const puppeteer=require('puppeteer-core');
const fs=require('fs'),path=require('path');
const out=path.resolve(process.argv[2]||'dist/shorts');
const mode=process.argv[3]||'stills';
const film=path.resolve(process.env.FILM||__dirname);const story=JSON.parse(fs.readFileSync(path.join(film,'story.json'),'utf8'));const fps=story.fps||30;const assets=process.env.ASSETS?'&assets='+encodeURIComponent(path.resolve(process.env.ASSETS)):'';
(async()=>{fs.mkdirSync(out,{recursive:true});const browser=await puppeteer.launch({executablePath:process.env.CHROME||'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',headless:true,args:['--hide-scrollbars','--force-color-profile=srgb','--font-render-hinting=none']});try{async function page(){const p=await browser.newPage();await p.setViewport({width:1080,height:1920,deviceScaleFactor:1});await p.goto('file://'+path.join(film,'video.html')+'?render'+assets);await p.evaluate(s=>ready(s),story);return p;}if(mode==='stills'){const p=await page();for(const t of story.stills||[.9,2.6,5.2,10.5,14.8,18.8,23]){await p.evaluate(t=>seek(t),t);await p.screenshot({path:path.join(out,`still-${t}.png`)});}await p.evaluate(t=>seek(t),story.cover??5.2);await p.screenshot({path:path.join(out,'cover-1080x1920.png')});}else{const pages=await Promise.all([page(),page(),page(),page()]);const total=Math.round(story.duration*fps);let done=0;await Promise.all(pages.map(async(p,w)=>{for(let f=w;f<total;f+=pages.length){await p.evaluate(t=>seek(t),f/fps);await p.screenshot({type:'jpeg',quality:94,path:path.join(out,`frame-${String(f).padStart(5,'0')}.jpg`)});if(++done%150===0)console.log(`${done}/${total} frames`);}}));console.log('Rendered',total,'frames');}}finally{await browser.close();}})().catch(e=>{console.error(e);process.exit(1)});