#!/usr/bin/env python3
from pathlib import Path
import subprocess, hashlib, json
R=Path('/data/video-pipeline/GacMaiAudio/project/gacmai_20260718_075153');I=R/'assets/images'
def raw_panel(src,out):
    subprocess.run(['ffmpeg','-y','-v','error','-i',str(src),'-vf','scale=600:1080:force_original_aspect_ratio=increase,crop=600:1080:(iw-ow)/2:(ih-oh)/2,format=rgb24','-frames:v','1','-f','rawvideo',str(out)],check=True)
    b=out.read_bytes();assert len(b)==600*1080*3;return b
L=raw_panel(I/'left_campaign_native_rev2.png',I/'left_native_rev2.rgb');Q=raw_panel(I/'right_campaign_native_rev2.png',I/'right_native_rev2.rgb');green=b'\x00\xff\x00'*720
raw=b''.join(L[y*1800:(y+1)*1800]+green+Q[y*1800:(y+1)*1800] for y in range(1080));assert len(raw)==1920*1080*3
out=I/'main_frame_campaign_native_rev2.png';subprocess.run(['ffmpeg','-y','-v','error','-f','rawvideo','-pixel_format','rgb24','-video_size','1920x1080','-i','-','-frames:v','1',str(out)],input=raw,check=True)
check=subprocess.check_output(['ffmpeg','-v','error','-i',str(out),'-f','rawvideo','-pix_fmt','rgb24','-']);center=outside=0
for y in range(1080):
    for x in range(1920):
        i=(y*1920+x)*3;g=check[i:i+3]==b'\x00\xff\x00'
        if 600<=x<1320:center+=g
        else:outside+=g
assert center==777600 and outside==0,(center,outside)
print(json.dumps({'status':'passed','path':str(out),'sha256':hashlib.sha256(out.read_bytes()).hexdigest(),'geometry':[600,720,600],'method':'uniform_cover_center_edge_trim_raw_rgb','green_center_pixels':center,'green_outside_pixels':outside}))
