const fs=require('fs'), cp=require('child_process'), path=require('path'); const ff=process.env.FFMPEG||'ffmpeg'; const logs=[]; function run(args){const r=cp.spawnSync(ff,['-hide_banner','-y',...args],{cwd:__dirname,encoding:'utf8'}); logs.push({args,stderr:r.stderr}); if(r.status!==0)throw Error(r.error||r.stderr);return r.stderr} for(const [name,color] of [['plain','red'],['base','blue']]) run(['-f','lavfi','-i',`color=${color}:s=160x90:r=24:d=2`,'-vf','drawbox=x=4:y=4:w=30:h=12:color=white:t=fill','-an','-c:v','libx264','-pix_fmt','yuv420p',name+'.mp4']); run(['-display_rotation:v:0','90','-i','base.mp4','-c','copy','rotated.mp4']); for(const [a,b,name] of [['plain','rotated','plain-first'],['rotated','plain','rotated-first']]){ fs.writeFileSync(path.join(__dirname,'list.txt'),`file '${a}.mp4'\nfile '${b}.mp4'\n`); run(['-f','concat','-safe','0','-i','list.txt','-c','copy',name+'.mp4']); } const rows={}; for(const n of ['plain','rotated','plain-first','rotated-first']){ const probe=run(['-i',n+'.mp4','-vf','showinfo','-f','null','-']); rows[n]={input:probe.split('\n').filter(x=>/Duration:|Stream #0:0.*Video|rotation of/.test(x)).slice(0,5),frames:probe.split('\n').filter(x=>/n:\s*\d+\s+pts:/.test(x)).length,display:probe.match(/ n:\s*0\s+pts:[^\n]+? s:(\d+x\d+)/)?.[1]}; } fs.writeFileSync(path.join(__dirname,'measurements.json'),JSON.stringify({rows,logs},null,2)); console.log(rows);