main
John Lauer
Preserve board29, component assets and scaffold-fit correction candidate with reviewed footage
c54169e
#!/usr/bin/env python3
"""Render independent review drafts without assembling or approving the film."""
import json,subprocess,hashlib
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1]
scripts=json.loads((ROOT/'videos/narration/draft-scripts.json').read_text())
board=json.loads((ROOT/'videos/build-storyboard.json').read_text());clips={c['id']:c for c in board['clips']}
report=[]
previous_path=ROOT/'videos/narrated-review/additional-drafts.json'
previous={c['id']:c for c in json.loads(previous_path.read_text())['clips']} if previous_path.exists() else {}
def duration(p):return float(subprocess.check_output(['ffprobe','-v','error','-show_entries','format=duration','-of','csv=p=0',str(p)]))
for name,text in scripts.items():
old=previous.get(name,{})
if old.get("narration")==text and old.get("fullDecode")=="pass" and hashlib.sha256((ROOT/old["video"]).read_bytes()).hexdigest()==old["videoSha256"]:
report.append(old);continue
audio=ROOT/'videos/narration'/f'{name}.mp3';script=audio.with_suffix('.txt');script.write_text(text+'\n')
subprocess.run(['adom-tts','say','@'+str(script),'--out',str(audio)],check=True,stdout=subprocess.DEVNULL)
source=Path(clips[name]['raw_path']);vd,ad=duration(source),duration(audio)
row=dict(id=name,narration=text,sourceVideo=str(source.relative_to(ROOT)),sourceAudio=str(audio.relative_to(ROOT)),videoDuration=vd,audioDuration=ad,status='draft narration; human review pending')
# Preserve the documented playback speed. Never stretch or loop the picture.
if ad+.15>vd:
row['status']='needs shorter narration';report.append(row);print(name,'TOO LONG',ad,vd,flush=True);continue
out=ROOT/'videos/narrated-review'/f'{name}.mp4'
subprocess.run(['ffmpeg','-hide_banner','-loglevel','error','-y','-i',str(source),'-i',str(audio),'-map','0:v:0','-map','1:a:0','-c:v','copy','-af','adelay=75|75,apad','-c:a','aac','-b:a','128k','-t',str(vd),'-movflags','+faststart',str(out)],check=True)
subprocess.run(['ffmpeg','-hide_banner','-loglevel','error','-i',str(out),'-f','null','-'],check=True)
row.update(video=str(out.relative_to(ROOT)),videoSha256=hashlib.sha256(out.read_bytes()).hexdigest(),fullDecode='pass')
report.append(row);print(name,'rendered',round(ad,2),'/',round(vd,2),flush=True)
(ROOT/'videos/narrated-review/additional-drafts.json').write_text(json.dumps(dict(status='drafts, no approvals, no assembly',clips=report),indent=2)+'\n')
previous_path.write_text(json.dumps(dict(status="drafts, no approvals, no assembly",clips=report),indent=2)+"\n")