singe/util/demoRecord.sh
2026-10-06 16:54:44 -05:00

27 lines
1.4 KiB
Bash
Executable file

#!/bin/bash
# Records one of the demos, start to finish, to an MP4 with its music, using Singe's own recorder:
#
# util/demoRecord.sh neonCoast screenshots/demos/neonCoast.mp4
#
# The demos folder is copied to a scratch folder and run from there headless with --deterministic
# and --record, so every frame is kept and the sound is mixed in step with the picture. Nothing
# appears on screen and nothing is heard. SCRATCH defaults to a folder under /tmp. For stretches
# of a demo as pictures to look at, see util/demoCapture.sh.
set -euo pipefail
DEMO=$1
OUT=$(realpath -m "$2")
STEP=20
REPO=$(cd "$(dirname "$0")/.." && pwd)
BIN=$(ls "$REPO"/.builddir/Singe-v*-Linux-x86_64 | head -1)
# The demo's size, from its games.dat: the canvas the script draws and the window it is shown in.
WIDTH=$(grep -o 'CANVAS_X *= *[0-9]*' "$REPO/demos/$DEMO/games.dat" | grep -o '[0-9]*$')
HEIGHT=$(grep -o 'CANVAS_Y *= *[0-9]*' "$REPO/demos/$DEMO/games.dat" | grep -o '[0-9]*$')
SCRATCH=${SCRATCH:-/tmp/demoRecord-$DEMO}
rm -rf "$SCRATCH"
mkdir -p "$SCRATCH/run"
cp -r "$REPO/demos/." "$SCRATCH/run/"
cd "$SCRATCH/run"
SDL_VIDEODRIVER=offscreen SDL_AUDIO_DRIVER=dummy timeout -k 10 7200 "$BIN" -k -C ${WIDTH}x$HEIGHT -x $WIDTH -y $HEIGHT --deterministic=$STEP --record="$OUT" -p -d "$SCRATCH/data" "$DEMO/$DEMO.singe" > "$SCRATCH/run.log" 2>&1 || true
grep -E "Recording|Recorded|rror" "$SCRATCH/run.log" || true