Created
January 28, 2020 06:02
-
-
Save natpenguin/90c6dcfea6bbef1976fc365d9a5d0bf7 to your computer and use it in GitHub Desktop.
Generating gif files from mov or mp4 in directory of Downloads
This file contains hidden or 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 | |
# 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