#!/bin/bash
set -e
FG=/root/nuants/dvds/family.mp4      # native 23.976fps Family Guy
RM=/root/nuants/dvds/yo.mp4          # native 23.976fps Rick & Morty
FILL=/root/nuants/rubber.webm        # Indian experiment filler stand-in
OUT=/tmp/claude-0/-root-nuants/d7958914-e6f2-4a44-a6dc-920311fe7d1d/scratchpad
cd "$OUT"
K=1.25125          # 30 / 23.976  -> turns 24 unique fps into 30 unique fps
V="scale=1920:1080:flags=lanczos,fps=30,setpts=PTS/$K"   # upscale to fake-1080p + retime 1.25x
VENC="-c:v libx264 -preset veryfast -pix_fmt yuv420p -r 30"
AENC="-c:a aac -ar 48000 -ac 2"

echo "### STAGE 1+2: FG chunk, cut intro (start @95s), retime video 1.25x, atempo audio (pitch preserved)"
ffmpeg -hide_banner -loglevel error -ss 95 -t 50 -i "$FG" \
  -vf "$V" -af "atempo=$K" $VENC $AENC seg_fg.mp4 -y

echo "### STAGE 3: splice a DIFFERENT show (R&M), same transforms"
ffmpeg -hide_banner -loglevel error -ss 130 -t 50 -i "$RM" \
  -vf "$V" -af "atempo=$K" $VENC $AENC seg_rm.mp4 -y

echo "### STAGE 4: silent filler from scraped experiment video (audio replaced with digital silence)"
ffmpeg -hide_banner -loglevel error -ss 40 -t 60 -i "$FILL" -f lavfi -t 60 -i anullsrc=r=48000:cl=stereo \
  -map 0:v -map 1:a -vf "scale=1920:1080:flags=lanczos,fps=30" $VENC $AENC -shortest seg_fill.mp4 -y

echo "### STAGE 5: concat  FG + RM + filler + filler(loop)  = padded 'full episode'"
printf "file 'seg_fg.mp4'\nfile 'seg_rm.mp4'\nfile 'seg_fill.mp4'\nfile 'seg_fill.mp4'\n" > list.txt
ffmpeg -hide_banner -loglevel error -f concat -safe 0 -i list.txt -c copy recon.mp4 -y

echo "### DONE"
ffprobe -hide_banner recon.mp4 2>&1 | grep -iE "Duration|Video:|Audio:"
ls -la recon.mp4