sidrefresh's picture
Add files using upload-large-folder tool
92f480e verified
Raw History Blame Contribute Delete
4.44 kB
"""Recording diagnostics; reward withheld until visual criteria are calibrated.
A provenance match establishes direct desktop capture and content identity,
not that a recording depicts the right animation or keeps it in frame.
"""
import hashlib
import json
from pathlib import Path
import shutil
import subprocess
class RecordingVerifierError(RuntimeError):pass
def sha(path):
h=hashlib.sha256()
with Path(path).open('rb') as f:
for block in iter(lambda:f.read(1048576),b''):h.update(block)
return h.hexdigest()
def inspect_recording(walk,root,events):
root=Path(root);video=root/(walk+'.mp4');blend=root/(walk+'.blend')
if not video.is_file():return {'status':'missing','checks':{'recording_present':False}}
for tool in ('ffprobe','ffmpeg'):
if not shutil.which(tool):raise RecordingVerifierError(tool+' missing')
result=subprocess.run(['ffprobe','-v','error','-show_streams','-show_format','-of','json',str(video)],capture_output=True,text=True,timeout=60)
if result.returncode:return {'status':'invalid_video','checks':{'recording_present':True,'video_decodes':False}}
try:meta=json.loads(result.stdout)
except ValueError as e:raise RecordingVerifierError('Invalid ffprobe JSON') from e
stream=next((s for s in meta.get('streams',[]) if s.get('codec_type')=='video'),None)
if not stream:return {'status':'invalid_video','checks':{'recording_present':True,'video_decodes':False}}
duration=float(meta.get('format',{}).get('duration',0))
if not 0<duration<=600:return {'status':'unsupported_duration','reason':'Recording exceeds supported ten-minute inspection; review required','checks':{'recording_present':True}}
decoded=subprocess.run(['ffmpeg','-nostdin','-v','error','-i',str(video),'-map','0:v:0','-f','null','-'],capture_output=True,text=True,timeout=180)
digest=sha(video);blend_hash=sha(blend) if blend.is_file() else None
starts={e['capture_id']:e for e in events if e.get('event')=='capture_start' and e.get('walk')==walk and e.get('capture_id')}
completes=[e for e in events if e.get('event')=='capture_complete' and e.get('walk')==walk and e.get('video_sha256')==digest and e.get('capture_id') in starts]
pair=next(((starts[e['capture_id']],e) for e in reversed(completes) if starts[e['capture_id']].get('source')=='x11grab'),None)
checks={'recording_present':True,'video_decodes':decoded.returncode==0,'direct_desktop_capture':bool(pair)}
measurements={'duration':duration,'width':stream.get('width'),'height':stream.get('height'),'fps':stream.get('avg_frame_rate')}
if pair:
start,end=pair
checks['capture_dimensions_match']=stream.get('width')==start.get('width') and stream.get('height')==start.get('height')
checks['saved_before_capture']=start.get('blend_sha256') is not None
measurements['project_bytes_unchanged']=start.get('blend_sha256')==end.get('blend_sha256_end')==blend_hash
# Blender writes playback/view state when saving. Byte changes alone
# cannot prove animation edits or invalidate a legitimate recording.
windows=[e for e in events if e.get('event')=='capture_window' and e.get('capture_id')==end['capture_id']]
measurements['blender_window_samples']=sum('Blender' in e.get('title','') for e in windows)
measurements['window_samples']=len(windows)
return {'status':'diagnostic_only','checks':checks,'measurements':measurements,'video_sha256':digest,'project_sha256':blend_hash,
'unverified':['whole_character_and_route_visible','controls_grid_timeline_visible','complete_start_to_end_playback','recording_matches_saved_animation','fixed_view_and_readable_scale'],
'reward_effect':'none until visual/temporal checks are calibrated'}
def audit(root='/root/rig',log='/logs/artifacts/recordings.jsonl'):
path=Path(log);events=[]
if path.is_file():
for line in path.read_text().splitlines():
if not line.strip():continue
try:events.append(json.loads(line))
except ValueError as e:raise RecordingVerifierError('Malformed capture event log') from e
return {'version':'t19-recording-diagnostics-v1','capture_log_present':path.is_file(),
'walks':{walk:inspect_recording(walk,root,events) for walk in ('straight','curved')},
'historical_grades_unchanged':True}
if __name__=='__main__':print(json.dumps(audit(),indent=2))