Created
July 2, 2024 09:37
-
-
Save cpietsch/14cc64e403701e0dc4501c9d5729dce0 to your computer and use it in GitHub Desktop.
ffmpeg folder to video
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 | |
# Default values | |
parent_folder="/home/jovyan/stable-diffusion-webui/outputs/txt2img-images" | |
framerate=10 | |
output_format="mp4" | |
image_format="jpg" | |
# Function to display usage | |
usage() { | |
echo "Usage: $0 [-p parent_folder] [-f framerate] [-o output_format] [-i image_format]" | |
echo " -p: Parent folder containing subfolders with images (default: $parent_folder)" | |
echo " -f: Framerate for the video (default: $framerate)" | |
echo " -o: Output format (default: $output_format)" | |
echo " -i: Image format to process (jpg or png, default: $image_format)" | |
exit 1 | |
} | |
# Parse command-line options | |
while getopts ":p:f:o:i:" opt; do | |
case $opt in | |
p) parent_folder="$OPTARG" ;; | |
f) framerate="$OPTARG" ;; | |
o) output_format="$OPTARG" ;; | |
i) image_format="$OPTARG" ;; | |
\?) echo "Invalid option -$OPTARG" >&2; usage ;; | |
esac | |
done | |
# Check if parent folder exists | |
if [ ! -d "$parent_folder" ]; then | |
echo "Error: Parent folder does not exist: $parent_folder" | |
exit 1 | |
fi | |
# Validate image format | |
if [ "$image_format" != "jpg" ] && [ "$image_format" != "png" ]; then | |
echo "Error: Invalid image format. Use 'jpg' or 'png'." | |
exit 1 | |
fi | |
# Loop through subfolders and create video for each | |
for folder in "$parent_folder"/*; do | |
if [ -d "$folder" ]; then | |
folder_name=$(basename "$folder") | |
echo "Creating $output_format for folder: $folder_name" | |
ffmpeg -framerate "$framerate" -pattern_type glob -i "$folder/*.$image_format" -c:v libx264 -pix_fmt yuv420p "$folder_name.$output_format" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment