Last active
March 20, 2020 11:03
-
-
Save gmaze/6906205c4d9d3015d124e4b6bc8e63ec to your computer and use it in GitHub Desktop.
Create a movie from a collection of image files
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
#!/usr/bin/env bash | |
# | |
# Gerenate mp4 videos from a collection of image files | |
# | |
# Video files are saved into ./videos | |
# | |
# Folder with image files: | |
src="/home/datawork-lops-oh/somovar/WP1/data/dashboard/img/monthly" # This is an example | |
list_files_for_movie (){ | |
# Create a text file with the list of image file to use in a video | |
ls $src/*.png | sort -V | xargs -I {} echo "file '{}'" > list.txt | |
} | |
list_specific_files_for_movie (){ | |
# Create a text file with the list of image file to use in a video | |
# Use a specific file pattern: | |
ls $src/*_map.png | sort -V | xargs -I {} echo "file '{}'" > list.txt | |
} | |
create_video (){ | |
# Usage: | |
# create_video <frame_rate> <short_name_to_file_list_maker_function> | |
echo "Generating a video from images ($2)..." | |
# List image files: | |
case $2 in | |
"All") | |
list_files_for_movie | |
;; | |
"Specific") | |
list_specific_files_for_movie | |
;; | |
esac | |
# Create video: | |
# ffmpeg options: | |
# -v loglevel set logging level | |
# -y overwrite output files | |
# -r rate set frame rate (Hz value, fraction or abbreviation) | |
# -f fmt force format | |
# -safe 0 | |
# -i infile | |
ffmpeg -hide_banner -loglevel error -y -r $1 -f concat -safe 0 -i list.txt -vsync vfr -b:v 18M -vf "fps=50,format=yuv420p" videos/animation_$2.mp4 | |
# Now compress the video: | |
ffmpeg -hide_banner -loglevel error -y -i videos/animation_$2.mp4 -crf 18 videos/animation_$2_compressed.mp4 | |
} | |
echo "######################### Updating videos ..." | |
create_video 6 "All" | |
create_video 8 "Specific" | |
echo "######################### Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment