animation/seq.sh

48 lines
909 B
Bash

#!/bin/bash
###########################
#
# Export a video to an image sequence at a
# particular framerate.
#
###########################
MULTIPLE=3
FPS=24
RATE=`echo "scale=0;${FPS}/${MULTIPLE}" | bc`
TIMESTR=""
INPUT="${1}"
OUTPUT="${2}"
INVERT="${3}"
START_FRAME=${4}
END_FRAME=${5}
WIDTH=323
HEIGHT=242
if [[ "${INVERT}" != "" ]] && [[ "${INVERT}" == "negative" ]]; then
INVERT="negate,"
else
INVERT=""
fi
if [[ "${START_FRAME}" != "" ]]; then
START=`echo "scale=6;${START_FRAME}/${FPS}" | bc`
TIMESTR="${TIMESTR} -ss ${START}"
fi
if [[ "${END_FRAME}" != "" ]]; then
TIME=`echo "scale=6;(${END_FRAME}-${START_FRAME})/${FPS}" | bc`
TIMESTR="${TIMESTR} -t ${TIME}"
fi
mkdir -p "${OUTPUT}"
ffmpeg -y -re -r ${FPS} -i "${INPUT}" \
${TIMESTR} \
-f image2 \
-r ${RATE} \
-vf ${INVERT}crop=in_h/3*4:in_h,scale=$WIDTH:$HEIGHT,setsar=1:1 \
-q:v 1 -qmin 1 -qmax 1 \
"${OUTPUT}/image_%06d.png"