import hashlib import json import shutil import subprocess from pathlib import Path OUT = Path(__file__).resolve().parent VIDEO = OUT/'preview_operation.mp4' BLEND = OUT/'PerfectCoffee_Minex_Mechanism.blend' ffmpeg = shutil.which('ffmpeg') ffprobe = shutil.which('ffprobe') if not ffmpeg or not ffprobe: raise RuntimeError('FFmpeg and ffprobe are required') probe = json.loads(subprocess.check_output([ffprobe,'-v','error','-count_frames','-show_streams','-show_format','-of','json',str(VIDEO)],text=True)) stream = next(s for s in probe['streams'] if s['codec_type']=='video') result = subprocess.run([ffmpeg,'-v','error','-xerror','-i',str(VIDEO),'-f','null','-'],capture_output=True,text=True) if result.returncode: raise RuntimeError(result.stderr) expected = [f'{f:04d}.png' for f in range(1,361,2)] frames_dir = OUT/'render_frames' frames_present = frames_dir.is_dir() missing = [name for name in expected if not (frames_dir/name).is_file()] if frames_present else [] selection = 'eq(n,0)+eq(n,63)+eq(n,64)+eq(n,83)+eq(n,92)+eq(n,96)+eq(n,100)+eq(n,106)+eq(n,127)+eq(n,139)+eq(n,160)+eq(n,179)' subprocess.run([ffmpeg,'-v','error','-y','-i',str(VIDEO),'-vf',f"select='{selection}',scale=360:450,tile=4x3",'-frames:v','1',str(OUT/'preview_contact_sheet.png')],check=True) report = { 'file':VIDEO.name, 'source_blend':BLEND.name, 'source_blend_sha256':hashlib.sha256(BLEND.read_bytes()).hexdigest(), 'build_script_sha256':hashlib.sha256((OUT/'build_minex_mechanism.py').read_bytes()).hexdigest(), 'render_script_sha256':hashlib.sha256((OUT/'render_minex_mechanism.py').read_bytes()).hexdigest(), 'motion_reference':{'file':'model_assets/reference/juicer/ZMUEX_working_video.mp4','segment_seconds':[119,126],'inspected_views':['front mechanism','side close-up']}, 'inspection_view':'Front cover and centre knob are hidden only in internal mechanism renders; assembled Blender geometry remains complete', 'video_sha256':hashlib.sha256(VIDEO.read_bytes()).hexdigest(), 'codec':stream['codec_name'], 'pixel_format':stream['pix_fmt'], 'width':int(stream['width']), 'height':int(stream['height']), 'frame_rate':stream['avg_frame_rate'], 'decoded_frames':int(stream.get('nb_read_frames',stream['nb_frames'])), 'duration_seconds':float(probe['format']['duration']), 'bytes':VIDEO.stat().st_size, 'source_blender_timeline':{'start':1,'end':360,'fps':24,'seconds':15}, 'preview_sampling':'Every second Blender frame, encoded at 12 fps for the same 15-second duration', 'expected_source_images':len(expected), 'source_frames_present_at_validation':frames_present, 'missing_source_images':missing, 'decoded_without_errors':True, 'contact_sheet':'preview_contact_sheet.png', 'visual_review':'Pending final video and contact-sheet review', } report['technical_checks_passed'] = ( stream['codec_name']=='h264' and (report['width'],report['height'])==(720,900) and report['frame_rate']=='12/1' and report['decoded_frames']==180 and abs(report['duration_seconds']-15.0)<0.01 and not missing ) report['passed'] = report['technical_checks_passed'] (OUT/'video_validation.json').write_text(json.dumps(report,ensure_ascii=False,indent=2)+'\n',encoding='utf-8') print(json.dumps(report,ensure_ascii=False,indent=2)) if not report['passed']: raise RuntimeError('Video technical validation failed')