Skip to content

Instantly share code, notes, and snippets.

@fcjurado
Created October 8, 2016 11:16
Show Gist options
  • Save fcjurado/fa02c65484696932a31ce9281bbc5dbc to your computer and use it in GitHub Desktop.
Save fcjurado/fa02c65484696932a31ce9281bbc5dbc to your computer and use it in GitHub Desktop.
Converts a mp4 to gif in batch
#!/bin/bash
if [ ! -d "./converted" ]; then mkdir "./converted"; fi
if [ ! -d "./tmp" ]; then mkdir "./tmp"; fi
for i in $(find ./ -name '*.mp4')
do
for word in $i
do
case "$word" in
*converted* )
;;
*tmp* )
;;
* )
filename=$(basename "$word")
ffmpeg -i $filename -r 4 'tmp/frame-%03d.jpg'
echo "converting ./tmp/$filename"
convert -delay 25 -loop 0 'tmp/*.jpg' "converted/$filename.gif"
rm -rf ./tmp/*
esac
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment