Created
April 16, 2023 15:17
-
-
Save BlogBlocks/c814fdf049752e3be81c258f03793ca9 to your computer and use it in GitHub Desktop.
Takes thirty random images from a directory and makes an mp4 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 | |
#---------------------------------------------------------------- | |
# SETTINGS | |
#input_dir="/mnt/HDD500/collections/newdownloads/512x512" # Replace this by a path to your folder /path/to/your/folder | |
input_dir="$(pwd)" #use the current directory the script can be copied to and run from /usr/local/bin run from | |
n_files=30 # Replace this by a number of images | |
#files=`ls ${input_dir}/*.jpg | head -${n_files}` # Change the file type to the correct type of your images | |
files=$(ls -1 "${input_dir}"/*.jpg | shuf -n ${n_files}) # pick thirty random *.jpg | |
#output_file="video.mp4" # Name of output video | |
output_file="$(date +%s).mp4" # Use a date_file_name to keep from overwriting names | |
crossfade=0.9 # Crossfade duration between two images | |
#---------------------------------------------------------------- | |
# Making an ffmpeg script... | |
input="" | |
filters="" | |
output="[0:v]" | |
i=0 | |
for f in ${files}; do | |
input+=" -loop 1 -t 1 -i $f" | |
next=$((i+1)) | |
if [ "${i}" -ne "$((n_files-1))" ]; then | |
filters+=" [${next}:v][${i}:v]blend=all_expr='A*(if(gte(T,${crossfade}),1,T/${crossfade}))+B*(1-(if(gte(T,${crossfade}),1,T/${crossfade})))'[b${next}v];" | |
fi | |
if [ "${i}" -gt "0" ]; then | |
output+="[b${i}v][${i}:v]" | |
fi | |
i=$((i+1)) | |
done | |
output+="concat=n=$((i * 2 - 1)):v=1:a=0,format=yuv420p10le[v]\" -map \"[v]\" ${output_file}" | |
script="ffmpeg ${input} -filter_complex \"${filters} ${output}" | |
echo ${script} | |
# Run it | |
eval "${script}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment