animation/fourcell.sh

102 lines
2.1 KiB
Bash
Raw Normal View History

2023-02-25 02:27:08 +00:00
#!/bin/bash
#set -e
2023-02-25 02:27:08 +00:00
if [[ "${1}" == "" ]]; then
echo "Please provide a calibration JSON"
fi
if [[ "${2}" == "" ]]; then
echo "Please provide one video or directory of images"
exit 2
fi
2023-03-04 23:51:22 +00:00
if [[ "${3}" == "" ]]; then
echo "Please an output directory for pages"
exit 3
fi
if [ ! -d "${3}" ]; then
echo "${3} output directory does not exist"
exit 4
fi
if [ -f "${2}" ]; then
echo "Exporting frames from ${2}..."
2023-02-25 02:27:08 +00:00
OUTPUT=$(mktemp -d)
ffmpeg -y -re -i "${2}" \
2023-02-25 02:27:08 +00:00
-q:v 1 -qmin 1 -qmax 1 \
"${OUTPUT}/frame_%06d.tif"
else
if [ -d "${2}" ]; then
OUTPUT="${2}"
else
echo "Argument ${2} is neither video nor directory"
exit 43
fi
2023-02-25 02:27:08 +00:00
fi
tiff_name () {
filename=$(basename "${1}")
filename="${filename%.*}"
echo "${filename}.tif"
}
echo "Using frames in ${OUTPUT}..."
W=$(cat "${1}" | jq -r ".width")
H=$(cat "${1}" | jq -r ".height")
DPI=$(echo "${W}/8.5" | bc)
FRAMES=$(mktemp)
echo "DPI: $DPI"
ls -1 "${OUTPUT}"*.{jpg,jpeg,JPG,JPG,png,PNG,gif,GIF,tif,tiff,TIF,TIFF} > "${FRAMES}" 2> /dev/null
FC=$(wc -l < "${FRAMES}")
PAGES=$(echo "(${FC}/4)+1" | bc)
TMP=$(mktemp -d)
for ((i=0;i<${PAGES};++i)); do
f1=$(sed -n "$(((i*4)+1))p" < "${FRAMES}")
f2=$(sed -n "$(((i*4)+2))p" < "${FRAMES}")
f3=$(sed -n "$(((i*4)+3))p" < "${FRAMES}")
f4=$(sed -n "$(((i*4)+4))p" < "${FRAMES}")
args=""
if [[ "${f1}" != "" ]]; then
name=$(tiff_name "${f1}")
dest="${TMP}/${name}"
bash white_fourcell.sh $DPI "${f1}" "${dest}"
args="${args} ${dest}"
else
continue
fi
if [[ "${f2}" != "" ]]; then
name=$(tiff_name "${f2}")
dest="${TMP}/${name}"
bash white_fourcell.sh $DPI "${f2}" "${dest}"
args="${args} ${dest}"
fi
if [[ "${f3}" != "" ]]; then
name=$(tiff_name "${f3}")
dest="${TMP}/${name}"
bash white_fourcell.sh $DPI "${f3}" "${dest}"
args="${args} ${dest}"
fi
if [[ "${f4}" != "" ]]; then
name=$(tiff_name "${f4}")
dest="${TMP}/${name}"
bash white_fourcell.sh $DPI "${f4}" "${dest}"
args="${args} ${dest}"
fi
2023-03-04 23:51:22 +00:00
bash apply_image.sh ${3}/page_$i.tiff "${1}" ${args}
done
2023-02-25 02:27:08 +00:00
2023-03-04 23:51:22 +00:00
echo "Wrote ${3}/page_$i.tiff"
# x determine dpi
# convert frame to white_fourcell
2023-02-25 02:27:08 +00:00
rm "${FRAMES}"
rm -rf "${TMP}"