#!/usr/bin/env python3 """Fixed-purpose GUI recorder: desktop capture, no command/file-import UI.""" import datetime import hashlib import json import os from pathlib import Path import signal import subprocess import time import tkinter as tk from tkinter import messagebox OUTPUT=Path('/root/rig'); LOG=Path('/logs/artifacts/recordings.jsonl') def digest(path): if not path.is_file(): return None h=hashlib.sha256() with path.open('rb') as f: for chunk in iter(lambda:f.read(1048576),b''):h.update(chunk) return h.hexdigest() def now():return datetime.datetime.now(datetime.timezone.utc).isoformat() def event(data): LOG.parent.mkdir(parents=True,exist_ok=True) with LOG.open('a') as f:f.write(json.dumps(data)+'\n') class Recorder: def __init__(self): self.root=tk.Tk();self.root.title('Record final walk');self.root.geometry('440x245') self.kind=tk.StringVar(value='straight');self.status=tk.StringVar(value='Choose a walk, then start recording.') tk.Label(self.root,text='Record one complete playback in Blender.\nKeep the whole character, travel, controls and timeline visible.',wraplength=420).pack(pady=12) for label,value in [('Straight walk → /root/rig/straight.mp4','straight'),('Curved walk → /root/rig/curved.mp4','curved')]: tk.Radiobutton(self.root,text=label,variable=self.kind,value=value).pack(anchor='w',padx=18) self.start_button=tk.Button(self.root,text='Start recording (3-second countdown)',command=self.countdown);self.start_button.pack(pady=8) self.stop_button=tk.Button(self.root,text='Stop and save',command=self.stop,state='disabled');self.stop_button.pack() tk.Label(self.root,textvariable=self.status,wraplength=420).pack(pady=8) self.process=None;self.pending=False;self.started=None;self.root.protocol('WM_DELETE_WINDOW',self.close) def countdown(self): if self.process or self.pending:return self.pending=True;self.start_button.config(state='disabled');self.root.iconify();self.root.after(3000,self.start) def start(self): if not self.pending:return self.pending=False try: display=os.environ.get('DISPLAY') if not display:raise RuntimeError('Desktop display is unavailable.') geometry=subprocess.check_output(['xdotool','getdisplaygeometry'],text=True,timeout=5).strip().split() width,height=map(int,geometry) if width%2 or height%2:raise RuntimeError('Desktop size must have even dimensions for H.264.') OUTPUT.mkdir(parents=True,exist_ok=True);self.walk=self.kind.get();self.path=OUTPUT/(self.walk+'.mp4') self.capture_id=os.urandom(16).hex();self.started=time.monotonic();self.start_time=now() self.blend_hash=digest(OUTPUT/(self.walk+'.blend')) self.err=(OUTPUT/(self.walk+'.recorder.log')).open('w') self.process=subprocess.Popen(['ffmpeg','-nostdin','-v','error','-y','-f','x11grab','-draw_mouse','0','-framerate','30','-video_size',f'{width}x{height}','-i',display+'+0,0','-an','-c:v','libx264','-preset','ultrafast','-crf','18','-pix_fmt','yuv420p','-movflags','+faststart',str(self.path)],stdout=subprocess.DEVNULL,stderr=self.err) self.stop_button.config(state='normal');self.status.set('Recording. Restore this window to stop and save.') event({'event':'capture_start','capture_id':self.capture_id,'walk':self.walk,'timestamp':self.start_time,'source':'x11grab','width':width,'height':height,'fps':30,'blend_sha256':self.blend_hash}) self.poll() except Exception as e:self.finish_error(str(e)) def poll(self): if not self.process:return if self.process.poll() is not None:self.finish_error('Capture stopped unexpectedly. Check the recorder log and record again.');return # Window titles corroborate use of Blender but do not establish playback, # visibility, the active scene or video-to-project correspondence. try: title=subprocess.check_output(['xdotool','getactivewindow','getwindowname'],text=True,stderr=subprocess.DEVNULL,timeout=2).strip() event({'event':'capture_window','capture_id':self.capture_id,'timestamp':now(),'elapsed':time.monotonic()-self.started,'title':title}) except (subprocess.SubprocessError,OSError):pass self.root.after(1000,self.poll) def stop(self): if not self.process:return self.process.send_signal(signal.SIGINT) try:rc=self.process.wait(timeout=20) except subprocess.TimeoutExpired:self.process.kill();self.process.wait();self.finish_error('Recording could not finalize. Record it again.');return self.err.close();self.process=None if rc not in (0,255):self.finish_error('Recording failed. Check the recorder log.');return after=digest(OUTPUT/(self.walk+'.blend')) event({'event':'capture_complete','capture_id':self.capture_id,'walk':self.walk,'timestamp':now(),'elapsed':time.monotonic()-self.started,'video_sha256':digest(self.path),'blend_sha256_start':self.blend_hash,'blend_sha256_end':after}) self.status.set('Saved '+str(self.path));self.start_button.config(state='normal');self.stop_button.config(state='disabled');self.root.deiconify() def finish_error(self,message): if self.process: if self.process.poll() is None:self.process.kill();self.process.wait() self.err.close();self.process=None self.start_button.config(state='normal');self.stop_button.config(state='disabled');self.root.deiconify();self.status.set(message) event({'event':'capture_error','timestamp':now(),'reason':message}) def close(self): if self.pending:self.pending=False;self.root.destroy();return if self.process:self.stop() self.root.destroy() def run(self):self.root.mainloop() if __name__=='__main__':Recorder().run()