#!/usr/bin/env bash
# Run a VHS tape that writes PNG frames, then save its last frame (text + cursor layers) with padding.
# Usage: shoot.sh <name>   (reads <name>.tape, writes <name>.png)
set -euo pipefail
name=$1
dir="frames-$name"
rm -rf "$dir"
{ printf 'Output "%s/"\n' "$dir"; cat "$name.tape"; } > ".run-$name.tape"
vhs ".run-$name.tape" > /dev/null 2>&1
last=$(find "$dir" -name 'frame-text-*.png' | sort | tail -1)
cursor=${last/frame-text/frame-cursor}
ffmpeg -loglevel error -y -i "$last" -i "$cursor" \
  -filter_complex "[0][1]overlay,pad=iw+56:ih+48:28:24:color=black" "$name.png"
rm -rf "$dir" ".run-$name.tape"
echo "$name.png"
