const fs=require('node:fs'),path=require('node:path'),{spawnSync}=require('node:child_process'); const local=path.resolve('work/frame-builder/node_modules/ffmpeg-static/ffmpeg.exe'); const ff=process.env.PVF_FFMPEG||(fs.existsSync(local)?local:'ffmpeg'),d=__dirname,log=[]; function run(a,mayFail=false){const r=spawnSync(ff,['-hide_banner','-nostdin','-y',...a],{cwd:d,maxBuffer:20e6});log.push({args:a,status:r.status,stderr:String(r.stderr)});fs.writeFileSync(d+'/command-output.txt',JSON.stringify(log,null,2));if(r.status&&!mayFail)throw Error(String(r.stderr));return r;} const w=65,h=49,frames=12,raw=Buffer.alloc(w*h*frames); for(let n=0;n/divisible|Error initializing/.test(l))},outputs:{}}; for(const [name,filter,ow,oh] of [['cropped','crop=64:48:0:0',64,48],['padded','pad=66:50:0:0:color=black',66,50]]){ run(['-i','joined.mkv','-vf',filter,'-c:v','libx264','-qp','0','-pix_fmt','yuv420p',name+'.mp4']); const out=run(['-i',name+'.mp4','-f','rawvideo','-pix_fmt','gray','-']).stdout; let bright=0;for(let j=0;j200)bright++; results.outputs[name]={width:ow,height:oh,decodedFrames:out.length/(ow*oh),brightBorderPixelsInFirstFrame:bright,seconds:out.length/(ow*oh)/12}; } fs.writeFileSync(d+'/measurements.json',JSON.stringify(results,null,2));console.log(JSON.stringify(results,null,2));