const fs=require('node:fs'),path=require('node:path'),crypto=require('node:crypto'),{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 commands=[]; function run(...a){const args=['-hide_banner','-nostdin','-y',...a];try{const out=execFileSync(ff,args,{cwd:__dirname,maxBuffer:30e6,stdio:['ignore','pipe','pipe']});commands.push({args,status:0});return out;}catch(e){commands.push({args,status:e.status,error:String(e.stderr)});throw e;}finally{fs.writeFileSync(__dirname+'/command-output.txt',JSON.stringify(commands,null,2));}} const W=64,H=48,N=90,frameBytes=W*H*3,raw=Buffer.alloc(N*frameBytes); // Each frame is a distinct, reproducible RGB pattern, not a hypothetical measurement. for(let n=0;ncrypto.createHash('sha256').update(b.subarray(i*frameBytes,(i+1)*frameBytes)).digest('hex'));} const h=Object.fromEntries(['master','a','b','joined','fixed'].map(f=>[f,hashes(f+'.mkv')])); let overlap=0;for(let k=1;k<=Math.min(h.a.length,h.b.length);k++)if(h.a.slice(-k).every((v,i)=>v===h.b[i]))overlap=k; const results={measuredAt:new Date().toISOString(),version:run('-version').toString().split('\n')[0],input:{width:W,height:H,fps:24,masterFrames:N,aRange:[0,48],bRange:[42,90],audio:false,codec:'lossless FFV1'},counts:Object.fromEntries(Object.entries(h).map(([k,v])=>[k,v.length])),overlapFrames:overlap,overlapSeconds:overlap/24,joinedSequenceMatchesConcatenatedInputs:JSON.stringify(h.joined)===JSON.stringify([...h.a,...h.b]),fixedSequenceMatchesMaster:JSON.stringify(h.fixed)===JSON.stringify(h.master),hashes:h}; if(overlap!==6||!results.fixedSequenceMatchesMaster||!results.joinedSequenceMatchesConcatenatedInputs)throw Error('Validation failed'); fs.writeFileSync(__dirname+'/measurements.json',JSON.stringify(results,null,2));console.log(JSON.stringify({...results,hashes:'See measurements.json'},null,2));