NaturalKnight's picture
Release VisualArtifactSpec 1.0 dataset
077605d
Raw History Blame Contribute Delete
2.5 kB
"""Reproducible 12-second input animation; Pillow plus ffmpeg required."""
from pathlib import Path
import argparse,json,subprocess
from PIL import Image,ImageDraw,ImageFont,ImageOps
ap=argparse.ArgumentParser();ap.add_argument('--config',default='animation.json');ap.add_argument('--output',required=True);ap.add_argument('--ffmpeg',default='ffmpeg');ap.add_argument('--font',required=True);ap.add_argument('--frames-dir');a=ap.parse_args()
cpath=Path(a.config).resolve();c=json.loads(cpath.read_text());W,H=1280,720;fps=24
assert len(c['scenes'])==3 and sum(s['duration_s'] for s in c['scenes'])==12
out=Path(a.output);out.parent.mkdir(parents=True,exist_ok=True)
proc=subprocess.Popen([a.ffmpeg,'-v','error','-y','-f','rawvideo','-pix_fmt','rgb24','-s',f'{W}x{H}','-r',str(fps),'-i','-','-an','-c:v','libx264','-pix_fmt','yuv420p','-movflags','+faststart',str(out)],stdin=subprocess.PIPE)
for idx,s in enumerate(c['scenes']):
base=Image.new('RGB',(W,H),'#f5f4ed');d=ImageDraw.Draw(base)
def text(x,y,t,size,color='#183b41'):
f=ImageFont.truetype(a.font,size);box=d.textbbox((x,y),t,font=f)
if box[2]>W-24:raise ValueError('text overflow: '+t)
d.text((x,y),t,font=f,fill=color)
pic=Image.open(cpath.parent/c['image']).convert('RGB');pic=ImageOps.contain(pic,(430,480));base.paste(pic,(35+(430-pic.width)//2,130+(480-pic.height)//2))
text(500,50,c['product'],43);text(500,110,c['subtitle'],23,'#527076')
text(500,200,s['label'],26,'#c72555');text(500,280,s['headline'],58,'#c72555')
for j,t in enumerate(s['lines']):text(500,375+j*48,t,28)
text(500,565,c['price_badge'],27,'#c72555')
d.rectangle((0,640,W,H),fill='#183b41');text(30,657,'Historical launch brief | '+c['footer_product'],23,'white');text(30,690,'Local benchmark exercise. Product imagery: Raspberry Pi.',16,'#d9e8e4')
for frame in range(int(s['duration_s']*fps)):
im=base.copy();dd=ImageDraw.Draw(im);dd.rounded_rectangle((500,610,1225,618),radius=4,fill='#d9e1da');progress=(idx+frame/(s['duration_s']*fps))/3;dd.rounded_rectangle((500,610,500+725*progress,618),radius=4,fill='#c72555')
# Keep a short reveal; the title/photo/footer stay visible throughout.
if frame<12:
region=im.crop((485,190,1255,545));blank=Image.new('RGB',region.size,'#f5f4ed');im.paste(Image.blend(blank,region,(frame+1)/12),(485,190))
if a.frames_dir and frame==48:
q=Path(a.frames_dir);q.mkdir(parents=True,exist_ok=True);im.save(q/f'scene_{idx+1}.png')
proc.stdin.write(im.tobytes())
proc.stdin.close();assert proc.wait()==0