import subprocess,json,pathlib,sys
folder=pathlib.Path(sys.argv[1]); rows=[]
for file in folder.glob('resize-*.mp4'):
 probe=subprocess.run(['ffprobe','-v','error','-show_entries','stream=codec_name,codec_tag_string,width,height,avg_frame_rate:format=duration,size','-of','json',str(file)],capture_output=True,text=True)
 decode=subprocess.run(['ffmpeg','-v','error','-xerror','-i',str(file),'-fps_mode','passthrough','-enc_time_base','1:1000000','-f','null','-'],capture_output=True,text=True)
 rows.append({'file':file.name,'probe':json.loads(probe.stdout),'decodeExit':decode.returncode,'decoderOutput':decode.stderr})
 subprocess.run(['ffmpeg','-v','error','-i',str(file),'-vf',"fps=1,scale=480:300,tile=3x3",'-frames:v','1',str(file.with_suffix('.png'))],check=True)
(folder/'decode-report.json').write_text(json.dumps(rows,indent=2));print(json.dumps(rows,indent=2))
