#!/usr/bin/env bash
set -euo pipefail
R=/data/video-pipeline/GacMaiAudio/project/gacmai_20260718_091744
I="$R/assets/images"; A="$R/artifacts"
# Uniform scale only for intro; portrait rails use uniform cover scale with negligible symmetric edge trim.
ffmpeg -y -hide_banner -loglevel error -i "$I/intro_typography_rev1.png" -vf scale=1920:1080:flags=lanczos -frames:v 1 "$I/intro_typography_rev1_1920x1080.png"
ffmpeg -y -hide_banner -loglevel error -i "$I/left_typography_rev1.png" -vf "scale=-2:1080:flags=lanczos,crop=600:1080:(iw-600)/2:0" -frames:v 1 "$I/left_typography_rev1_600x1080.png"
ffmpeg -y -hide_banner -loglevel error -i "$I/right_typography_rev1.png" -vf "scale=-2:1080:flags=lanczos,crop=600:1080:(iw-600)/2:0" -frames:v 1 "$I/right_typography_rev1_600x1080.png"
ffmpeg -y -hide_banner -loglevel error -f lavfi -i color=c=0x00ff00:s=1920x1080 -i "$I/left_typography_rev1_600x1080.png" -i "$I/right_typography_rev1_600x1080.png" -filter_complex "[0][1]overlay=0:0[t];[t][2]overlay=1320:0" -frames:v 1 "$I/three_panel_typography_rev1.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']]
files={'intro_source':'intro_typography_rev1.png','left_source':'left_typography_rev1.png','right_source':'right_typography_rev1.png','intro':'intro_typography_rev1_1920x1080.png','left':'left_typography_rev1_600x1080.png','right':'right_typography_rev1_600x1080.png','layout':'three_panel_typography_rev1.png'}
rec={'status':'assembled_pending_exact_composite_qa','project_id':'gacmai_20260718_091744','revision':'typography_rev1','exact_text':{'intro':['Bàn Số Bốn','Gác Mái Audio','Truyện độc quyền, nghiêm cấm sao chép dưới mọi hình thức'],'left':['Gác Mái Audio','Like','Share','Subscribe'],'right':['Bàn Số Bốn']},'source_qa':{'intro':'pass','left':'pass','right':'pass'},'operations':{'intro':'uniform_scale','rails':'uniform_scale_to_height_then_negligible_symmetric_outer_trim','layout':'geometry_only_600_720_600'},'files':{k:{'path':str(I/v),'sha256':sha(I/v),'dimensions':dim(I/v)} for k,v in files.items()},'created_at':datetime.datetime.now(datetime.timezone.utc).isoformat()};p=A/'visual_typography_assembly_rev1.json';p.write_text(json.dumps(rec,ensure_ascii=False,indent=2)+'\n');print(json.dumps({'status':rec['status'],'receipt_sha256':sha(p),'layout_sha256':rec['files']['layout']['sha256']}))
PY
