MEGA-WEBSITE/app/scripts/stitch-flythrough.sh
Dave b75229a5f4 Mega Infrastructure website: cinematic scroll redesign
Vite + React + Tailwind site with a scroll-scrubbed drone fly-through,
services, projects, company, team and contact sections, plus a
Dockerfile + nginx config for Coolify deployment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 22:24:49 +02:00

41 lines
1.6 KiB
Bash
Executable file

#!/usr/bin/env bash
# Stitches the fly-through from per-shot clips, in story order, with short crossfades.
# Each argument is a video clip OR a still image (stills become a slow 5 s push-in),
# so missing AI shots can be filled from photos until they are generated.
#
# Usage: scripts/stitch-flythrough.sh <out.mp4> <shot1> <shot2> ...
set -euo pipefail
OUT=${1:?output mp4}; shift
FPS=24; FADE=0.5; STILL_LEN=5
inputs=(); filters=""; durs=(); i=0
for s in "$@"; do
case "$(echo "$s" | tr '[:upper:]' '[:lower:]')" in
*.jpg|*.jpeg|*.png|*.webp)
inputs+=(-i "$s")
frames=$((STILL_LEN * FPS))
filters+="[$i:v]scale=3840:2160:force_original_aspect_ratio=increase,crop=3840:2160,"
filters+="zoompan=z='1+0.0018*on':x='iw/2-(iw/zoom/2)':y='ih/2-(ih/zoom/2)':d=$frames:s=1920x1080:fps=$FPS,"
durs+=("$STILL_LEN")
;;
*)
inputs+=(-i "$s")
filters+="[$i:v]scale=1920:1080:force_original_aspect_ratio=increase,crop=1920:1080,fps=$FPS,"
durs+=("$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$s")")
;;
esac
filters+="setsar=1,format=yuv420p,settb=AVTB[s$i];"
i=$((i + 1))
done
prev="s0"; offset=0
for ((k = 1; k < i; k++)); do
offset=$(printf "%.4f" "$(echo "$offset + ${durs[$((k - 1))]} - $FADE" | bc -l)")
filters+="[$prev][s$k]xfade=transition=fade:duration=$FADE:offset=$offset[x$k];"
prev="x$k"
done
filters=${filters%;}
ffmpeg -loglevel error -y "${inputs[@]}" -filter_complex "$filters" -map "[$prev]" \
-c:v libx264 -preset slow -crf 18 -g 1 -pix_fmt yuv420p -movflags +faststart "$OUT"
echo "wrote $OUT ($(ffprobe -v error -show_entries format=duration -of csv=p=0 "$OUT")s)"