#!/bin/sh # settings ms_per_frame=5000 resolution=1920x1080 output=output.mkv # dependency check ! command -v ffmpeg > /dev/null && echo "Missing dependency: ffmpeg" && exit 1 ! command -v magick > /dev/null && echo "Missing dependency: magick" && exit 1 # calc runtime (for fun) intdiv() { echo $(($1 / $2)).$((($1 % $2) * 1000 / $2)); } # calc decimal using integer arithmetic hms_from_ms() { printf '%02d:%02d:%02d' $(($1 / 3600000)) $((($1 % 3600000) / 60000)) $((($1 % 60000) / 1000)); } ctime() { t=$(date +%s) && echo $(( t * 1000 )); } framerate=$(intdiv 1000 $ms_per_frame) runtime=$(hms_from_ms $((ms_per_frame * $#))) echo "Creating a slideshow ($output) consisting of $# images at $(intdiv $ms_per_frame 1000) seconds per frame for a total runtime of approximately $runtime" count=0 stime=$(ctime) # slideshow for img in "$@"; do count=$((count + 1)) etime=$(ctime) elapsed=$(hms_from_ms $(( etime - stime ))) printf '[%0*d/%d] (elapsed %s) %s\n' ${##} $count $# $elapsed "$img" >&2 magick "$img" \ -auto-orient \ -resize $resolution \ -background black \ -gravity center \ -extent $resolution \ -depth 8 \ rgb:- done | ffmpeg -y -v error \ -f rawvideo \ -video_size $resolution \ -pixel_format rgb24 \ -framerate $framerate \ -probesize 32 \ -analyzeduration 0 \ -i - \ -vf "fps=1,framerate=30:interp_start=0:interp_end=255:scene=100" \ -c:v libx264 \ -crf 22 \ -preset ultrafast \ -tune stillimage \ $output