main
John Lauer
Keep all six R11 review clips clean; deliver captions through the Wiki player
e1f6118
"""Prepare individual narrated review clips, never assemble an unapproved final."""
from pathlib import Path
import subprocess,json,hashlib,sys
R=Path(__file__).resolve().parents[1];O=R/'videos/compact-r11/chapter'
def run(args): subprocess.run(args,check=True,cwd=R)
def stamp(t):
ms=round(t*1000);return f'{ms//3600000:02}:{ms//60000%60:02}:{ms//1000%60:02}.{ms%1000:03}'
scenes=[
dict(id='01-board',title='Compact PCB revision',raw='window-3147662-20261014-004758.mp4',start=0,end=16.16,audioEnd=16.85,tempo=1.08,
description='Actual compact-board geometry orbit. Copper and silk are omitted by the STEP view; cooler not fitted.',
cues=[(0,3.274,'The compact revision is 72 millimeters square.'),(3.711,6.066,'Large corner pins stay on the scaffold grid,'),(6.405,8.395,'and USB-C sits at the edge.'),(8.832,12.425,'The four-wire fan connector and its control circuit\nare now routed.'),(12.863,14.38,'This is a geometry review;'),(14.799,16.735,'cooling qualification is still open.')]),
dict(id='02-fan',title='RPM-controlled fan digital twin (simulated)',raw='window-3147662-20261014-001710.mp4',start=8,end=30,audioEnd=18.24,tempo=1,
description='Recorded simulated fan state ramp with fixed housing and wires. Visual slow motion, no hardware measurement.',
cues=[(0,3.973,'The new fan has separate speed feedback\nand PWM control wires.'),(4.418,8.591,'Its digital twin keeps the housing and wires fixed\nwhile the rotor turns.'),(9.04504,11.7106,'The simulated cycle gently varies the speed'),(11.9933,13.0531,'and returns to rest.'),(13.5084,15.4349,'The animation runs in slow motion;'),(15.7612,18.131,'measured cooling still needs an actual test.')])]
manifest=O/'storyboard.json'
if not manifest.exists():run(['adom-video-post','manifest','init',str(manifest),'--title','Electronic load R11 — design progression review'])
reports=[]
for s in scenes:
if len(sys.argv)>1 and s['id'] not in sys.argv[1:]: continue
duration=s['audioEnd']/s['tempo'];speed=(s['end']-s['start'])/duration
vtt='WEBVTT\n\n'+''.join(f"{stamp(a/s['tempo'])} --> {stamp(b/s['tempo'])}\n{text}\n\n" for a,b,text in s['cues'])
(O/(s['id']+'.vtt')).write_text(vtt)
srt='\n'.join(f"{i+1}\n{stamp(a/s['tempo']).replace('.',',')} --> {stamp(b/s['tempo']).replace('.',',')}\n{text}\n" for i,(a,b,text) in enumerate(s['cues']))
(O/(s['id']+'.srt')).write_text(srt)
vf=f"[0:v]trim=start={s['start']}:end={s['end']},setpts=(PTS-STARTPTS)/{speed},crop=2560:1396:0:132,scale=1280:698,pad=1280:720:0:0,fps=30[v];[1:a]atrim=end={s['audioEnd']},asetpts=PTS-STARTPTS,atempo={s['tempo']},loudnorm=I=-16:TP=-1.5:LRA=7[a]"
out=O/(s['id']+'-review.mp4')
run(['ffmpeg','-y','-loglevel','error','-i',str(R/'videos/compact-r11'/s['raw']),'-i',str(O/(s['id']+'.mp3')),'-filter_complex',vf,'-map','[v]','-map','[a]','-c:v','libx264','-preset','fast','-crf','23','-g','30','-pix_fmt','yuv420p','-c:a','aac','-b:a','96k','-movflags','+faststart','-t',str(duration),str(out)])
check=subprocess.run(['ffmpeg','-hide_banner','-i',str(out),'-af','silencedetect=noise=-40dB:d=0.7','-f','null','-'],capture_output=True,text=True,check=True)
(O/(s['id']+'-silence.log')).write_text(check.stderr)
assert 'silence_start' not in check.stderr,'Review long silence before publishing'
run(['adom-video-post','manifest','add',str(manifest),'--id',s['id'],'--title',s['title'],'--description',s['description'],'--raw',str(out),'--narration',(O/(s['id']+'.txt')).read_text().strip(),'--warning','Review clip only; not assembled design or physical qualification.'])
reports.append({**s,'videoSpeed':speed,'durationSeconds':duration,'file':str(out.relative_to(R)),'sha256':hashlib.sha256(out.read_bytes()).hexdigest(),'captions':'Phrase boundaries from source audio silence intervals, transformed to final audio timing; human audiovisual review pending.','silenceAtLeast700ms':False})
prior=json.loads((O/'review-report.json').read_text()) if (O/'review-report.json').exists() else []
byid={s['id']:s for s in prior};byid.update({s['id']:s for s in reports})
(O/'review-report.json').write_text(json.dumps(list(byid.values()),indent=2)+'\n')
print('Individually narrated and captioned review scenes; final assembly awaits review.')