"""Original sample cuts; rerun with Pillow and FFmpeg. No client assets."""
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont
import subprocess, math, json
ROOT=Path(__file__).resolve().parent
OUT=ROOT.parent
F='/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf'
B='/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf'
def font(n,b=False): return ImageFont.truetype(B if b else F,n)
def text(d,xy,t,n=30,color='#f1f5ff',bold=False):d.text(xy,t,font=font(n,bold),fill=color)
def card(d,box,fill='#182b48',outline=None):d.rounded_rectangle(box,20,fill=fill,outline=outline,width=2)
def app_frame(t):
 im=Image.new('RGB',(720,1280),'#081321');d=ImageDraw.Draw(im)
 text(d,(52,54),'WORKDESK / PRODUCT CONCEPT',23,'#7fe3d5',True)
 heads=[('Leads slipping','through the cracks?'),('One place.','A clear next step.'),('Route the request.','Keep the owner.'),('Review first.','Then follow through.')]
 a,b=heads[min(int(t//3.5),3)];text(d,(48,125),a,48,bold=True);text(d,(48,185),b,40)
 y=310;card(d,(40,y,680,1090),fill='#eef3fc');text(d,(73,y+32),'Workdesk',35,'#10213c',True)
 text(d,(73,y+85),'SAMPLE LEAD PIPELINE',20,'#60728b',True)
 for i,(name,service,status) in enumerate([('Northline Home','Website enquiry','Review'),('Orbit Studio','Workflow automation','Assigned'),('Lakeview Clinic','Reporting brief','Draft')]):
  yy=450+i*143;card(d,(67,yy,654,yy+122),'#ffffff')
  text(d,(91,yy+18),name,27,'#152640',True);text(d,(91,yy+60),service,22,'#49617b')
  if t>3.5+i*1.5:
   d.rounded_rectangle((514,yy+21,635,yy+60),12,fill='#def5ec');text(d,(525,yy+28),status,19,'#166550',True)
 if t>7:
  yy=920;card(d,(67,yy,654,1039),'#dfe7ff');text(d,(88,yy+18),'Owner review required',25,'#243d7c',True)
  text(d,(88,yy+60),'No message is sent automatically.',21,'#334b76')
 d.rectangle((48,1150,48+int(624*t/14),1156),fill='#7fe3d5')
 text(d,(48,1180),'New AI-assisted sample / synthetic data',21,'#9cafc8')
 return im
def run(args):subprocess.run(['ffmpeg','-hide_banner','-loglevel','error','-y',*args],check=True)
if __name__=='__main__':
 app_frame(8).save(OUT/'app-poster.png')
 proc=subprocess.Popen(['ffmpeg','-hide_banner','-loglevel','error','-y','-f','rawvideo','-pix_fmt','rgb24','-s','720x1280','-r','24','-i','-','-f','lavfi','-i','sine=frequency=220:duration=14','-vf','format=yuv420p','-af','volume=0.025,afade=t=in:d=0.5,afade=t=out:st=13:d=1','-c:v','libx264','-preset','veryfast','-crf','22','-c:a','aac','-shortest','-movflags','+faststart',str(OUT/'workdesk-short.mp4')],stdin=subprocess.PIPE)
 for n in range(336):proc.stdin.write(app_frame(n/24).tobytes())
 proc.stdin.close();assert proc.wait()==0
 ass='''[Script Info]
PlayResX: 720
PlayResY: 1280
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Main,DejaVu Sans,55,&H00FFFFFF,&H00FFFFFF,&H00100704,&H66000000,-1,0,0,0,100,100,0,0,1,3,0,8,45,45,145,1
Style: Small,DejaVu Sans,22,&H00F0D4A0,&H00FFFFFF,&H00100704,&H66000000,0,0,0,0,100,100,0,0,1,2,0,2,40,40,125,1
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.00,0:00:02.50,Main,,0,0,0,,THE SIGNAL\\NFOUND YOU.
Dialogue: 0,0:00:02.50,0:00:06.00,Main,,0,0,0,,Beyond the ring...\\Nsomething is listening.
Dialogue: 0,0:00:06.00,0:00:10.00,Main,,0,0,0,,One step forward.\\NNo way back.
Dialogue: 0,0:00:10.00,0:00:14.00,Main,,0,0,0,,Then why is your\\Nvoice on the other side?
Dialogue: 0,0:00:00.00,0:00:14.00,Small,,0,0,0,,ECHO GATE / ORIGINAL FICTIONAL CONCEPT\\NAI-assisted image + motion + sound design
'''
 (ROOT/'echo.ass').write_text(ass)
 run(['-loop','1','-i',str(ROOT/'portal.png'),'-f','lavfi','-i','sine=frequency=62:duration=14','-vf',f"scale=720:1280:force_original_aspect_ratio=increase,crop=720:1280,zoompan=z='min(zoom+0.0006,1.15)':x='iw/2-iw/zoom/2':y='ih/2-ih/zoom/2':d=336:s=720x1280:fps=24,ass={ROOT/'echo.ass'},fade=t=in:d=0.25,fade=t=out:st=13:d=1,format=yuv420p",'-af','volume=0.12,tremolo=f=2:d=0.4,afade=t=in:d=1,afade=t=out:st=12:d=2','-t','14','-c:v','libx264','-preset','veryfast','-crf','22','-c:a','aac','-movflags','+faststart',str(OUT/'echo-gate.mp4')])
 run(['-ss','1','-i',str(OUT/'echo-gate.mp4'),'-frames:v','1',str(OUT/'echo-poster.jpg')])
 (OUT/'edit-manifest.json').write_text(json.dumps({'status':'New independent AI-assisted samples, not paid client work','tools':['ChatGPT image generation','Python/Pillow','FFmpeg'], 'cuts':[{'file':'echo-gate.mp4','seconds':14,'format':'720x1280, 24 fps','contribution':'AI-assisted original image/concept, timed hook and cliffhanger cards, push-in motion, synthesized sound design, encode. No Runway/After Effects delivery claimed.'},{'file':'workdesk-short.mp4','seconds':14,'format':'720x1280, 24 fps','contribution':'Original synthetic app layout, scripted motion/text states, editing and encode prepared with AI assistance. Not a screen recording of client software.'}]},indent=2))
