Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert an animated video to gif from http://chrismessina.me/b/13913393/mov-to-gif
# Convert an animated video to gif
# Works best for videos with low color palettes like Dribbble shots
#
# @param $1 - video file name like `animation.mov`
# @param @optional $2 - resize parameter as widthxheight like `400x300`
#
# Example: vidtogif animation.mov 400x300
# Requirements: ffmpeg and gifsicle. Can be downloaded via homebrew
#
# http://chrismessina.me/b/13913393/mov-to-gif
function vidtogif() {
if [ -n "$1" ]
then
mkdir pngs gifs
ffmpeg -i "$1" -r 10 pngs/frame_%04d.png
sips -s format gif pngs/*.png --out gifs/
cd gifs
if [ -z "$2" ]
then
gifsicle *.gif --optimize=3 --delay=3 --loopcount > ../animation.gif
else
gifsicle *.gif --optimize=3 --delay=3 --loopcount --resize "$2" > ../animation.gif
fi
cd ..
rm -rf pngs gifs
else
echo "Use video file as first parameter"
fi
}
@imkevinxu

This comment has been minimized.

Copy link
Owner Author

@imkevinxu imkevinxu commented Feb 18, 2015

Source this in you .bash_profile for an easy shortcut to turn any .mov Quicktime screen recording into a high-quality gif! Works best for animated videos with low color palettes

If you want to convert a live action video try out https://gist.github.com/imkevinxu/e0b51ddeb5b877ed4fae

@saralkochar

This comment has been minimized.

Copy link

@saralkochar saralkochar commented Mar 17, 2015

I love this idea. I've successfully saved in my .bash_profile however it keeps giving me error as to command not found: movetogif.

Update: (after 10 mins):
I figured, the same old problem I have, instead of movtogif I was typing movetogif...oops 😄 It's all sorted..thanks for this wonderful command lines.

@asartz

This comment has been minimized.

Copy link

@asartz asartz commented Mar 28, 2015

Nice script. Worked like a charm. Thank you.

@ericodes

This comment has been minimized.

Copy link

@ericodes ericodes commented Jan 8, 2016

Looked around for so many methods, and this was the easiest, and gave the clearest gif. Thanks so much for sharing!

@JamesMcMahon

This comment has been minimized.

Copy link

@JamesMcMahon JamesMcMahon commented Apr 21, 2016

Thanks for this!

You may want to add

#!/usr/bin/env bash
#

To the top so it works if bash isn't your default shell.

@Nathan187

This comment has been minimized.

Copy link

@Nathan187 Nathan187 commented May 11, 2016

what exactly is suppose to happen. i've updated home brew, and installed ffmpeg and gifsicle like it says. when i enter the command...nothing happens. how do i know if the file is created or something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment