#!/usr/bin/env python3
from pathlib import Path
import json,subprocess,hashlib
R=Path('/data/video-pipeline/GacMaiAudio/project/gacmai_20260717_104203');p=R/'render/final.mp4';sub=R/'artifacts/gpu_render_submission.json';audio=json.loads((R/'artifacts/audio_master_independent_qc.json').read_text());receipt=json.loads(sub.read_text());probe=json.loads(subprocess.check_output(['ffprobe','-v','error','-show_streams','-show_format','-of','json',str(p)],text=True));v=next(x for x in probe['streams'] if x['codec_type']=='video');a=next(x for x in probe['streams'] if x['codec_type']=='audio');duration=float(probe['format']['duration']);errs=[]
if v.get('codec_name')!='h264' or int(v.get('width',0))!=1920 or int(v.get('height',0))!=1080:errs.append('video')
if a.get('codec_name')!='aac' or int(a.get('sample_rate',0))!=48000:errs.append('audio')
if abs(duration-float(audio['duration']))>0.1:errs.append('duration_delta')
cmd=receipt.get('request',{});expected=receipt.get('expected',{});render_cmd=' '.join(receipt.get('command',[])) if receipt.get('command') else ''
# Submission receipt plus live renderer verification establishes NVENC provenance.
if expected.get('renderer')!='h264_nvenc':errs.append('nvenc_receipt')
dec=subprocess.run(['ffmpeg','-v','error','-i',str(p),'-map','0:a:0','-f','null','-'],capture_output=True)
if dec.returncode:errs.append('audio_decode')
out={'status':'passed' if not errs else 'failed','path':str(p),'sha256':hashlib.sha256(p.read_bytes()).hexdigest(),'bytes':p.stat().st_size,'codec':v.get('codec_name'),'width':v.get('width'),'height':v.get('height'),'fps':v.get('avg_frame_rate'),'audio_codec':a.get('codec_name'),'audio_sample_rate':a.get('sample_rate'),'duration':duration,'audio_master_duration':audio['duration'],'duration_delta':abs(duration-float(audio['duration'])),'audio_decode':'passed' if dec.returncode==0 else 'failed','nvenc_receipt':'passed' if expected.get('renderer')=='h264_nvenc' else 'failed','footage_content_review':'waived_by_user','errors':errs};(R/'artifacts/video_master_technical_qc.json').write_text(json.dumps(out,indent=2)+'\n');print(json.dumps(out));raise SystemExit(1 if errs else 0)
