fp/packages/scripts/thumbnail-generator.sh
2025-02-08 02:54:01 -08:00

18 lines
686 B
Bash

#!/bin/sh
input_file_path=$1
# Get the number of frames, fallback to 100 if missing
nb_frames=$(ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=noprint_wrappers=1:nokey=1 "$input_file_path")
# Fallback if nb_frames is empty or "N/A"
if [ -z "$nb_frames" ] || [ "$nb_frames" = "N/A" ]; then
echo "nb_frames was ${nb_frames} which is unsupported. Are you trying this on a .ts file? (It may not work on ts, try mp4.) Exiting."
exit 555
fi
sep=$((nb_frames/25))
# Generate a 5x5 tile thumbnail
ffmpeg -i "$input_file_path" -vf "select=not(mod(n\,max(1\,$sep))),scale=160:-1,tile=5x5" -vsync 0 -update 1 -frames:v 1 "${input_file_path%.*}-thumb.png"