animation/stipple.sh

117 lines
2.1 KiB
Bash
Raw Normal View History

#!/bin/bash
2021-09-16 14:42:59 +00:00
###########################
#
# Run the stipple_gen script on a sequence
# of PNG images and then render the resulting
# preview images into a video.
#
###########################
2021-09-10 04:37:08 +00:00
if [[ "${1}" == "" ]]; then
echo "Please provide a directory of images as the first argument"
exit 1
fi
INPUT=`realpath "${1}"`
OUTPUT=`realpath "${2}"`
2021-12-08 22:27:00 +00:00
CONFIG="${3}"
SINGLE="${4}"
2021-09-09 00:53:52 +00:00
2021-09-10 04:37:08 +00:00
if [ ! -d "${INPUT}" ]; then
echo "Directory ${1} doesn't exist"
exit 2
2021-09-09 00:53:52 +00:00
fi
2021-09-10 04:37:08 +00:00
mkdir -p "${OUTPUT}"
2022-10-26 00:07:58 +00:00
MULTIPLE=3
2021-12-08 22:27:00 +00:00
FPS=24
RATE=`echo "scale=0;${FPS}/${MULTIPLE}" | bc`
WIDTH=404
HEIGHT=374
2021-12-08 05:18:56 +00:00
DOTSIZE=2
MAXGENERATIONS=25
MAXPARTICLES=1200
MINDOTSIZE=1.5
LINE=1.5
FILL=true
2021-11-27 03:01:07 +00:00
MODE="stipple" #stipple/tsp
2021-12-08 22:27:00 +00:00
if [[ "${CONFIG}" == "" ]]; then
echo "Please provide a config file"
exit 1
2021-11-27 03:01:07 +00:00
fi
IMAGES=""
stipple () {
png="${1}"
2021-11-30 15:20:06 +00:00
frame="${2}"
filename=`basename "${png}"`
name=`echo "${filename}" | cut -d'.' -f1`
num=`echo "${name}" | awk -F'_' '{print $(NF)}'`
tmp=`mktemp`.png
bash white.sh "${png}" "${tmp}"
2021-12-08 22:27:00 +00:00
source "${CONFIG}"
cd ~/src/stipple_gen/
bash stipple_gen.sh \
--inputImage "${tmp}" \
--outputImage "${OUTPUT}/${name}_rendered.png" \
--outputSVG "${OUTPUT}/${name}.svg" \
2021-12-08 22:27:00 +00:00
--config "${CONFIG}"
if [[ "${invert}" == "true" ]]; then
2021-09-10 04:37:08 +00:00
convert "${OUTPUT}/${name}_rendered.png" -channel RGB -negate "${OUTPUT}/${name}_rendered.png"
fi
rm "${tmp}"
cd ~/src/animation/
2021-11-27 03:01:07 +00:00
if [ "${MODE}" != "tsp" ]; then
opt=`mktemp`.svg
CURRENT=$(pwd)
cd /
svgsort --no-adjust "${OUTPUT}/${name}.svg" "${opt}"
cd $CURRENT
mv "${opt}" "${OUTPUT}/${name}.svg"
fi
}
2021-11-30 15:20:06 +00:00
if [[ "${SINGLE}" != "" ]]; then
i=0;
echo "Rendering a single frame, #${SINGLE}"
#files in dir
for png in "${INPUT}/"*.png ; do
if [[ ${i} -eq ${SINGLE} ]]; then
stipple "${png}" ${i}
break
fi
i=$((i+1))
done
exit
fi
i=0;
#files in dir
for png in "${INPUT}/"*.png ; do
2021-11-30 15:20:06 +00:00
stipple "${png}" ${i}
i=$((i+1))
done
if [[ "${IMAGES}" == "" ]]; then
part=`echo "${name}" | awk -F'_0' '{print $1}'`
IMAGES="${OUTPUT}/${part}_%06d_rendered.png"
VIDEO="${OUTPUT}/${part}.mov"
fi
2021-12-08 22:27:00 +00:00
ffmpeg -y -r ${RATE} -f image2 -i "${IMAGES}" \
-r ${FPS} \
-c:v prores_ks -profile:v 3 \
"${VIDEO}"