animation/seq.sh

48 lines
909 B
Bash
Raw Normal View History

#!/bin/bash
2021-09-16 14:42:59 +00:00
###########################
#
# Export a video to an image sequence at a
# particular framerate.
#
###########################
2022-10-26 00:07:58 +00:00
MULTIPLE=3
2021-11-27 03:01:07 +00:00
FPS=24
RATE=`echo "scale=0;${FPS}/${MULTIPLE}" | bc`
TIMESTR=""
INPUT="${1}"
OUTPUT="${2}"
INVERT="${3}"
2021-11-27 03:01:07 +00:00
START_FRAME=${4}
END_FRAME=${5}
WIDTH=323
HEIGHT=242
2021-11-27 03:01:07 +00:00
if [[ "${INVERT}" != "" ]] && [[ "${INVERT}" == "negative" ]]; then
2021-09-10 04:36:46 +00:00
INVERT="negate,"
2021-11-27 03:01:07 +00:00
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}"
2021-12-08 22:27:00 +00:00
ffmpeg -y -re -r ${FPS} -i "${INPUT}" \
2021-11-27 03:01:07 +00:00
${TIMESTR} \
-f image2 \
-r ${RATE} \
2021-09-10 04:36:46 +00:00
-vf ${INVERT}crop=in_h/3*4:in_h,scale=$WIDTH:$HEIGHT,setsar=1:1 \
2021-11-27 03:01:07 +00:00
-q:v 1 -qmin 1 -qmax 1 \
"${OUTPUT}/image_%06d.png"