Created
March 21, 2024 15:54
-
-
Save tyhenry/fb66bcc2f98c63737f712ad4b27002f5 to your computer and use it in GitHub Desktop.
Stich PNGs in directories to MP4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
mindepth=0 | |
maxdepth=0 | |
original_dir=$(pwd) | |
print_help() { | |
echo "Usage: $0 [OPTION]..." | |
echo "Create videos from PNG files in directories." | |
echo | |
echo "Options:" | |
echo "-r search subdirectories recursively" | |
echo "-s only search subdirectories (not this directory)" | |
echo "-h display this help and exit" | |
} | |
while getopts ":srh" opt; do | |
case ${opt} in | |
s ) | |
mindepth=1 | |
maxdepth=1 | |
;; | |
r ) | |
maxdepth=10 | |
;; | |
h ) | |
print_help | |
exit 0 | |
;; | |
\? ) | |
echo "Invalid option: -$OPTARG" 1>&2 | |
print_help | |
exit 1 | |
;; | |
esac | |
done | |
while IFS= read -r -d '' D; do | |
cd "${D}" | |
if [ "$(ls -A *.png 2>/dev/null)" ]; then | |
if [ "${D}" = "." ]; then | |
video_name=$(basename "${original_dir}") | |
else | |
video_name=$(basename "${D}") | |
fi | |
if [ -f framerate ]; then | |
framerate=$(cat framerate) | |
else | |
framerate=1/5 | |
fi | |
find . -maxdepth 1 -name "*.png" -print0 | sort -zV | xargs -0 cat | ffmpeg -framerate "${framerate}" -i - -r 10 "${video_name}.mp4" | |
fi | |
cd "${original_dir}" | |
done < <(find . -mindepth ${mindepth} -maxdepth ${maxdepth} -type d -print0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment