Skip to content

Instantly share code, notes, and snippets.

@natpenguin
Created January 28, 2020 06:02
Show Gist options
  • Save natpenguin/90c6dcfea6bbef1976fc365d9a5d0bf7 to your computer and use it in GitHub Desktop.
Save natpenguin/90c6dcfea6bbef1976fc365d9a5d0bf7 to your computer and use it in GitHub Desktop.
Generating gif files from mov or mp4 in directory of Downloads
#!/bin/bash
# This script is going to generate .gif from .MP4 and .mov in the Downloads directory
echo 'Checking tools that are needed in this script...'
# Checking Homebrew for installing ffmpeg
if !(type 'brew' > /dev/null); then
echo 'Installing Homebrew...'
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
if !(type 'brew' > /dev/null); then
echo "Couldn't install Homebrew." >&2
exit 1
fi
fi
# Checking ffmpeg for generating gif file
if !(type 'ffmpeg' > /dev/null); then
echo 'Installing ffmpeg...'
brew install ffmpeg
if !(type 'ffmpeg' > /dev/null); then
echo "Couldn't install ffmpeg." >&2
exit 1
fi
fi
echo 'All green. Will start to generate!'
echo $IFS
IFS_BACKUP=$IFS
IFS=$'\n'
for file in $(find ~/Downloads -maxdepth 1 -name '* *.MP4' -or -name '*.MP4' -or -name '* *.mov' -or -name '*.mov'); do
if test -e $file.gif; then
echo "$(basename $file) is passed. Becasue $(basename $file).gif already exists."
else
ffmpeg -i $file -vf scale=320:-1 -r 30 $file.gif
fi
done
IFS=$IFS_BACKUP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment