const fs=require('node:fs'),path=require('node:path'),{execFileSync}=require('node:child_process'); const bundled=path.resolve('work/frame-builder/node_modules/ffmpeg-static/ffmpeg.exe'); const ff=process.env.PVF_FFMPEG||(fs.existsSync(bundled)?bundled:'ffmpeg'); const logs=[];function run(...a){const args=['-hide_banner','-nostdin','-y',...a];try{const out=execFileSync(ff,args,{cwd:__dirname,maxBuffer:30e6,stdio:['ignore','pipe','pipe']});logs.push({args,ok:true});return out;}catch(e){logs.push({args,error:String(e.stderr)});throw e;}finally{fs.writeFileSync(__dirname+'/command-output.txt',JSON.stringify(logs,null,2));}} for(const [file,color] of [['a',[255,0,0]],['b',[0,0,255]]]){ const raw=Buffer.alloc(160*90*4*48);for(let f=0;f<48;f++)for(let y=25;y<65;y++)for(let x=60;x<100;x++){const o=((f*90+y)*160+x)*4;raw[o]=color[0];raw[o+1]=color[1];raw[o+2]=color[2];raw[o+3]=255;} fs.writeFileSync(__dirname+'/'+file+'.rgba',raw); run('-f','rawvideo','-pix_fmt','rgba','-s','160x90','-r','24','-i',file+'.rgba','-c:v','qtrle',file+'.mov'); } fs.writeFileSync(__dirname+'/list.txt','file a.mov\nfile b.mov\n'); run('-f','concat','-safe','0','-i','list.txt','-c','copy','joined.mov'); run('-i','joined.mov','-c:v','libx264','-crf','18','-pix_fmt','yuv420p','discard.mp4'); run('-f','lavfi','-i','color=white:s=160x90:r=24:d=4','-i','joined.mov','-filter_complex','[0:v][1:v]overlay=shortest=1:format=auto,format=yuv420p[v]','-map','[v]','-c:v','libx264','-crf','18','white.mp4'); const results={time:new Date().toISOString(),version:run('-version').toString().split('\n')[0],width:160,height:90,fps:24,files:{}}; for(const file of ['a.mov','b.mov','joined.mov','discard.mp4','white.mp4']){ const raw=run('-i',file,'-f','rawvideo','-pix_fmt','rgba','pipe:1');let zero=0,opaque=0;for(let o=3;oArray.from(raw.subarray(((frame*90+y)*160+x)*4,((frame*90+y)*160+x)*4+4)); results.files[file]={frames:raw.length/(160*90*4),zeroAlpha:zero,opaqueAlpha:opaque,backgroundFirst:pixel(0,10,10),centerFirst:pixel(0,80,45)}; if(results.files[file].frames>48)results.files[file].backgroundSecond=pixel(60,10,10); } fs.writeFileSync(__dirname+'/measurements.json',JSON.stringify(results,null,2));console.log(results);