const {execFileSync}=require('node:child_process'); const fs=require('node:fs'),os=require('node:os'),path=require('node:path'); const cwd=fs.mkdtempSync(path.join(os.tmpdir(),'pvf-overlap-')); const ffmpeg=process.env.FFMPEG || 'ffmpeg'; const ffprobe=process.env.FFPROBE || 'ffprobe'; const run=(args)=>execFileSync(ffmpeg,['-v','error','-y',...args],{cwd}); for(const color of ['red','blue']){ run(['-f','lavfi','-i','color='+color+':s=160x90:r=24:d=2','-c:v','libx264',color+'.mp4']); } const results={}; for(const [name,filter] of [ ['hard-cut','[0:v][1:v]concat=n=2:v=1:a=0'], ['overlap','[0:v][1:v]xfade=transition=fade:duration=0.5:offset=1.5'] ]){ run(['-filter_complex_threads','1','-i','red.mp4','-i','blue.mp4','-filter_complex',filter,'-c:v','libx264',name+'.mp4']); const frames=JSON.parse(execFileSync(ffprobe,['-v','error','-select_streams','v:0','-count_frames','-show_entries','stream=duration,nb_read_frames','-of','json',name+'.mp4'],{cwd})).streams[0]; const pixels=[1.5,1.75,2].map(timestamp=>{ const rgb=run(['-ss',String(timestamp),'-i',name+'.mp4','-frames:v','1','-pix_fmt','rgb24','-f','rawvideo','pipe:1']); return {timestamp,rgb:[...rgb.subarray(0,3)]}; }); results[name]={...frames,pixels}; } console.log(JSON.stringify(results,null,2));