#!/usr/bin/env bash # Export a square-pixel, SDR source. Read README.md for alpha/HDR/crop caveats. # Usage: bash ffmpeg-recipes.sh ./scene-master.mp4 ./media set -euo pipefail SCENE_INPUT=${1:?Pass an existing master video file} SCENE_ASSETS=${2:-./media} if [[ ! -f "$SCENE_INPUT" ]]; then printf '%s\n' 'Input video not found.' >&2 exit 1 fi if [[ -e "$SCENE_ASSETS" ]]; then printf '%s\n' 'Output path already exists. Choose a fresh folder to avoid stale frames.' >&2 exit 1 fi mkdir -p "$SCENE_ASSETS/desktop" "$SCENE_ASSETS/mobile" # fps drops/duplicates frames; it does not invent high quality motion interpolation. # No enlargement: a smaller source stays smaller. -2 keeps even output height. ffmpeg -hide_banner -loglevel warning -n -i "$SCENE_INPUT" -an \ -vf "fps=24,scale=w='min(1440,iw)':h=-2:flags=lanczos" \ -c:v libwebp -quality 82 -compression_level 4 -start_number 1 \ "$SCENE_ASSETS/desktop/frame-%04d.webp" ffmpeg -hide_banner -loglevel warning -n -i "$SCENE_INPUT" -an \ -vf "fps=24,scale=w='min(768,iw)':h=-2:flags=lanczos" \ -c:v libwebp -quality 78 -compression_level 4 -start_number 1 \ "$SCENE_ASSETS/mobile/frame-%04d.webp" # Poster exactly matches the first exported frame. cp "$SCENE_ASSETS/desktop/frame-0001.webp" "$SCENE_ASSETS/poster.webp" # A conventional opaque MP4 for playback/fallback. This export drops alpha. # A shorter GOP can help seeking but increases bitrate; test on target devices. ffmpeg -hide_banner -loglevel warning -n -i "$SCENE_INPUT" -an \ -vf "fps=24,scale=w='min(1440,iw)':h=-2:flags=lanczos" \ -c:v libx264 -preset medium -crf 22 -pix_fmt yuv420p \ -g 24 -keyint_min 24 -sc_threshold 0 -movflags +faststart \ "$SCENE_ASSETS/scene-web.mp4" printf '%s\n' 'Export complete. Count actual frames and update frameCount in the HTML.'