main
John Lauer Deliver Board34 R10 prototype review, current simulator twin and 4m34s narrated process cut 47014bd
"""Update the authorized review draft after Board34/R10 design finish; preserve history."""
from pathlib import Path
import json,subprocess,hashlib
R=Path(__file__).resolve().parents[1];O=R/'videos/full-edit-r10';S=O/'segments';S.mkdir(exist_ok=True)
B=Path('/home/adom/project/video-tools/brand/adom-video-brand/media')
def run(a):subprocess.run(['ffmpeg','-v','error','-y',*a],check=True)
def dur(p):return float(subprocess.check_output(['ffprobe','-v','error','-show_entries','format=duration','-of','default=nw=1:nk=1',str(p)],text=True))
def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest()
def new_scene(name,a,b,alen,blen,voice,delay,tag,offset=0):
 out=S/(name+'.mp4');label=O/(name+'-label.txt');label.write_text(tag)
 vf='scale=1920:1000:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:60:color=0x151923,setsar=1,fps=30'
 f=f'[0:v]trim=duration={alen},setpts=PTS-STARTPTS,{vf}[a];[1:v]trim=start={offset}:duration={blen},setpts=PTS-STARTPTS,{vf}[b];[a][b]concat=n=2:v=1:a=0,drawtext=fontfile=/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf:textfile={label}:fontcolor=white:fontsize=24:x=30:y=18[v];[2:a]adelay={delay}|{delay},apad[n]'
 run(['-i',str(a),'-i',str(b),'-i',str(voice),'-filter_complex',f,'-map','[v]','-map','[n]','-t',str(alen+blen),'-c:v','libx264','-preset','veryfast','-threads','2','-crf','21','-pix_fmt','yuv420p','-c:a','aac','-b:a','128k','-ar','48000','-ac','2',str(out)])
 return {'id':name,'source':str(a),'sourceSha256':sha(a),'additionalSource':str(b),'additionalSourceSha256':sha(b),'audio':str(voice),'audioSha256':sha(voice),'output':str(out.relative_to(R)),'duration':dur(out),'tag':tag,'narration':voice.with_suffix('.txt').read_text().strip()}
old=json.loads((R/'videos/full-edit-r9/edit-report.json').read_text())
opening=new_scene('opening-r10',B/'dark-intro-16x9.mp4',O/'r10-assembly-hero.mp4',5,12,O/'narration/opening.mp3',1500,'ADOM ELECTRONIC LOAD | Board34 / R10 | rendered nominal assembly')
# A 0.02 s narration tail is retained by the segment audio padding; opening audio ends before 17s.
closing=new_scene('closing-r10',R/'aiflow/run/window-16461108-20261013-075012-10x.mp4',B/'dark-outro-16x9.mp4',15.8,5,O/'narration/closing.mp3',0,'BOARD34 / R10 | DESIGN SCREENS PASS | PHYSICAL QUALIFICATION NEXT')
records=[opening,*old['scenes'][1:-1],closing]
for i,x in enumerate(records):
 if x['id']=='r9-simulated-fan':
  p=S/'r10-simulated-fan.mp4'
  records[i]={**x,'id':'r10-simulated-fan','source':str(p.relative_to(R)),'sourceSha256':sha(p),'output':str(p.relative_to(R)),'duration':dur(p),'tag':'R10 PROBING SIMULATION | authored RPM | blade motion x0.01','revisionScope':'Exact verified R10 model; two native Hydrogen takes cropped to the workcell pane'}

# R9 takes remain useful recorded history and are labelled as such.
for x in records:
 if x['id'].startswith('r9-'):x['revisionScope']='Historical R9 footage; superseded geometry, same authored fan behavior'
p=O/'concat.txt';p.write_text(''.join("file '"+str(R/x['output'])+"'\n" for x in records))
f=O/'electronic-load-r10-review-1080p.mp4';run(['-f','concat','-safe','0','-i',str(p),'-c','copy','-movflags','+faststart',str(f)])
assert 240<=dur(f)<=300
report={'status':'narrated-review-draft-human-editorial-review-pending','board':'Board34/R10','designFinishPassed':True,'physicalQualified':False,'youtubePublished':False,'file':str(f.relative_to(R)),'sha256':sha(f),'durationSeconds':dur(f),'scenes':records,'limitations':['Historical takes retain revision labels and original limitations.','No complete AI-token or hardware purchase cost claim.','Brand footage included; final audio/editorial polish remains review work.']}
(O/'edit-report.json').write_text(json.dumps(report,indent=2)+'\n')
t=0;chapters=[];vtt=['WEBVTT\n']
def stamp(s):m=round(s*1000);return f'{m//3600000:02}:{m//60000%60:02}:{m//1000%60:02}.{m%1000:03}'
for x in records:chapters.append({'t':round(t,3),'title':x['id'].replace('-',' ')});vtt.append(f"{stamp(t)} --> {stamp(t+x['duration'])}\n{x['narration']}\n");t+=x['duration']
(O/'chapters.json').write_text(json.dumps(chapters,indent=2)+'\n');(O/'captions.vtt').write_text('\n'.join(vtt));print(json.dumps({k:v for k,v in report.items() if k!='scenes'},indent=2))