#!/usr/bin/env bash
set -euo pipefail
R=/data/video-pipeline/GacMaiAudio/project/gacmai_20260718_091744
I="$R/assets/images"; A="$R/artifacts"
ffmpeg -y -hide_banner -loglevel error -i "$I/intro_normalized.png" -vf scale=1920:1080:flags=lanczos -frames:v 1 "$I/intro_1920x1080.png"
# 9:16 to 5:9 rails: uniform height scale to 1080 then symmetric 3px crop per side.
ffmpeg -y -hide_banner -loglevel error -i "$I/left_rail_normalized.png" -vf "scale=-2:1080:flags=lanczos,crop=600:1080:(iw-600)/2:0" -frames:v 1 "$I/left_600x1080.png"
ffmpeg -y -hide_banner -loglevel error -i "$I/right_rail_normalized.png" -vf "scale=-2:1080:flags=lanczos,crop=600:1080:(iw-600)/2:0" -frames:v 1 "$I/right_600x1080.png"
ffmpeg -y -hide_banner -loglevel error -f lavfi -i color=c=0x00ff00:s=1920x1080 -i "$I/left_600x1080.png" -i "$I/right_600x1080.png" -filter_complex "[0][1]overlay=0:0[t];[t][2]overlay=1320:0" -frames:v 1 "$I/three_panel_layout.png"
python3 - <<'PY'
import json,hashlib,subprocess,datetime
from pathlib import Path
R=Path('/data/video-pipeline/GacMaiAudio/project/gacmai_20260718_091744');I=R/'assets/images';A=R/'artifacts'
def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest()
def dim(p):
 s=json.loads(subprocess.check_output(['ffprobe','-v','error','-select_streams','v:0','-show_entries','stream=width,height','-of','json',str(p)],text=True))['streams'][0];return [s['width'],s['height']]
outs={n:{'path':str(I/f),'sha256':sha(I/f),'dimensions':dim(I/f)} for n,f in {'intro':'intro_1920x1080.png','left':'left_600x1080.png','right':'right_600x1080.png','layout':'three_panel_layout.png'}.items()}
rec={'status':'assembled_pending_semantic_qa','project_id':'gacmai_20260718_091744','source_acceptance_sha256':sha(A/'visual_source_acceptance_and_normalization.json'),'operations':{'intro':'uniform_scale_only','rails':'uniform_scale_to_height_then_symmetric_3px_crop_each_side','layout':'left x=0..599, green center x=600..1319, right x=1320..1919'},'trim':{'left_rail_source_equivalent_each_side_percent':0.5625,'right_rail_source_equivalent_each_side_percent':0.5625,'contract_max_each_side_percent':0.75},'outputs':outs,'created_at':datetime.datetime.now(datetime.timezone.utc).isoformat()}
(A/'visual_composite_geometry_rev0.json').write_text(json.dumps(rec,ensure_ascii=False,indent=2)+'\n');print(json.dumps(rec,ensure_ascii=False))
PY
