Created
February 20, 2015 22:23
-
-
Save vitovalov/5cd969a2989c9752a5cb to your computer and use it in GitHub Desktop.
mp4 to gif using ffmpeg and gifsicle(brew)
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
# Author: @vitovalov | |
# Description: pass it a mp4 and you will have a gif | |
# Dependencies: ffmpeg, gifsicle | |
if [ "$#" -le 1 ]; then | |
echo "\nUsage: sh gifit.sh <source path to original mp4> <delay between frames>" | |
echo "Warning! filenames shouldn't contain the extension\n" | |
exit 1 | |
fi | |
ffmpeg -i $1.mp4 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=$2 > $1.gif |
Here is my version which I tried to optimise ~ hovever Gifsicle seems to not reduce the file size much when already using a palette.
for f in "$@"
do
scale="fps=20,scale='min(480,iw)':'min(480,ih)':force_original_aspect_ratio=decrease"
/usr/local/bin/ffmpeg -hwaccel videotoolbox -i "$f" -vf "$scale,palettegen" "$f.png"
/usr/local/bin/ffmpeg -hwaccel videotoolbox -i "$f" -i "$f.png" -filter_complex "$scale,paletteuse" "$f.gif"
rm "$f.png"
done
This script can be used as a service in Mac Automator for a quick right click action.
Outside of mac you'll have to either remove -hwaccel videotoolbox
or replace it with the corresponding hwaccel implementation available on your platform.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great stuff. Your second argument is undocumented. I passed zero as the second argument like
gifit mymovie 0
and it worked flawlessly. Thank you!