Create a gist now

Instantly share code, notes, and snippets.

@SlexAxton /.zshrc
Last active May 23, 2018

What would you like to do?
My gif workflow
gifify() {
if [[ -n "$1" ]]; then
if [[ $2 == '--good' ]]; then
ffmpeg -i $1 -r 10 -vcodec png out-static-%05d.png
time convert -verbose +dither -layers Optimize -resize 600x600\> out-static*.png GIF:- | gifsicle --colors 128 --delay=5 --loop --optimize=3 --multifile - > $1.gif
rm out-static*.png
else
ffmpeg -i $1 -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > $1.gif
fi
else
echo "proper usage: gifify <input_movie.mov>. You DO need to include extension."
fi
}
brew install ffmpeg
brew tap phinze/homebrew-cask
brew install brew-cask
brew cask install x-quartz
open /usr/local/Cellar/x-quartz/2.7.4/XQuartz.pkg
# click through the stuff
brew install gifsicle
brew install imagemagick
# I had a weird problem with Convert/imagemagick where I had to do:
ln -s /usr/local/Cellar/libtool/2.4.2/lib/libltdl.7.dylib libltdl.7.dylib
# But hopefully you don't have to
# Take screencast using Quicktime. Export as high quality as possible.
gifify screencap.mov
gifify screencap.mov --good
@SlexAxton

This comment has been minimized.

Show comment Hide comment
@SlexAxton

SlexAxton Feb 19, 2013

An example!

http://slex.me/image/2V1y1g3T3j36/gifify.mov.gif

Owner

SlexAxton commented Feb 19, 2013

An example!

http://slex.me/image/2V1y1g3T3j36/gifify.mov.gif

@patik

This comment has been minimized.

Show comment Hide comment
@patik

patik Feb 20, 2013

The GIFs work fine in a browser, but a couple image viewers (Xee, ACDSee) only show the first frame and give a vague loading error message.

Any chance of removing the movie's file extension so the name ends up as screencap.gif instead of screencap.mov.gif?

patik commented Feb 20, 2013

The GIFs work fine in a browser, but a couple image viewers (Xee, ACDSee) only show the first frame and give a vague loading error message.

Any chance of removing the movie's file extension so the name ends up as screencap.gif instead of screencap.mov.gif?

@SlexAxton

This comment has been minimized.

Show comment Hide comment
@SlexAxton

SlexAxton Feb 20, 2013

This is definitely targeted at going along with pull requests, so that's ok with me re: browsers only.

I think that's possible. I'll have to read up on bash scripting for the 10000th time, but I'm sure it's nothing crazy. Happy to take a suggestion :D

Owner

SlexAxton commented Feb 20, 2013

This is definitely targeted at going along with pull requests, so that's ok with me re: browsers only.

I think that's possible. I'll have to read up on bash scripting for the 10000th time, but I'm sure it's nothing crazy. Happy to take a suggestion :D

@commadelimited

This comment has been minimized.

Show comment Hide comment
@commadelimited

commadelimited Feb 27, 2013

Does it matter what you used to record the original video file? What did you use to record cli.mov?

Does it matter what you used to record the original video file? What did you use to record cli.mov?

@SlexAxton

This comment has been minimized.

Show comment Hide comment
@SlexAxton

SlexAxton Feb 27, 2013

I use QuickTime (free) or Screeny (pretty).

Just save in native quality for best results.

Owner

SlexAxton commented Feb 27, 2013

I use QuickTime (free) or Screeny (pretty).

Just save in native quality for best results.

@paulirish

This comment has been minimized.

Show comment Hide comment
@paulirish

paulirish Mar 5, 2013

feature request: palindromic looping (back n forth)!

also the --good setting is incredible. same quality as what i got with GifBrewery but 20% of the size. dayum.

feature request: palindromic looping (back n forth)!

also the --good setting is incredible. same quality as what i got with GifBrewery but 20% of the size. dayum.

@tednaleid

This comment has been minimized.

Show comment Hide comment
@tednaleid

tednaleid Mar 22, 2013

Looks like the location of x-quartz has moved to /usr/local/Caskroom/x-quartz/2.7.4, so line 5 in install.sh should be:

open /usr/local/Caskroom/x-quartz/2.7.4/XQuartz.pkg

Looks like the location of x-quartz has moved to /usr/local/Caskroom/x-quartz/2.7.4, so line 5 in install.sh should be:

open /usr/local/Caskroom/x-quartz/2.7.4/XQuartz.pkg
@ryanseddon

This comment has been minimized.

Show comment Hide comment
@ryanseddon

ryanseddon Mar 27, 2013

I kept getting this error:

Incompatible library version: convert requires version 11.0.0 or later, but libltdl.7.dylib provides version 10.0.0

I fixed it with this command brew link libtool --force

I kept getting this error:

Incompatible library version: convert requires version 11.0.0 or later, but libltdl.7.dylib provides version 10.0.0

I fixed it with this command brew link libtool --force

@curtisblackwell

This comment has been minimized.

Show comment Hide comment
@curtisblackwell

curtisblackwell Mar 27, 2013

does this require zsh?

edit: nope. just threw the .zshrc code into my .bashrc and it works fine.

does this require zsh?

edit: nope. just threw the .zshrc code into my .bashrc and it works fine.

@digia

This comment has been minimized.

Show comment Hide comment
@digia

digia May 21, 2013

Brew Cask put the package for XQuartz into /opt/homebrew-cask/Caskroom/x-quartz/2.7.4

If that helps anyone.

digia commented May 21, 2013

Brew Cask put the package for XQuartz into /opt/homebrew-cask/Caskroom/x-quartz/2.7.4

If that helps anyone.

@joemccann

This comment has been minimized.

Show comment Hide comment
@joemccann

joemccann Sep 28, 2013

Quality is pretty amazing.

Quality is pretty amazing.

@robertd

This comment has been minimized.

Show comment Hide comment
@robertd

robertd Oct 1, 2013

Sweet

robertd commented Oct 1, 2013

Sweet

@connor

This comment has been minimized.

Show comment Hide comment
@connor

connor Oct 1, 2013

😍

connor commented Oct 1, 2013

😍

@damncabbage

This comment has been minimized.

Show comment Hide comment
@damncabbage

damncabbage Oct 2, 2013

Regarding "screencap.mov.gif", try:

+ GIF="${1%.*}.gif"
  if [[ $2 == '--good' ]]; then
    ffmpeg -i $1 -r 10 -vcodec png out-static-%05d.png
-   time convert -verbose +dither -layers Optimize -resize 600x600\> out-static*.png  GIF:- | gifsicle --colors 128 --delay=5 --loop --optimize=3 --multifile - > $1.gif
+   time convert -verbose +dither -layers Optimize -resize 600x600\> out-static*.png  GIF:- | gifsicle --colors 128 --delay=5 --loop --optimize=3 --multifile - > $GIF
    rm out-static*.png
  else
-   ffmpeg -i $1 -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > $1.gif
+   ffmpeg -i $1 -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > $GIF
  fi

If you're wondering what the GIF line is about:

$ FOO="Yep.nope.mov"
$ echo "${FOO%.*}.gif"
Yep.nope.gif

Regarding "screencap.mov.gif", try:

+ GIF="${1%.*}.gif"
  if [[ $2 == '--good' ]]; then
    ffmpeg -i $1 -r 10 -vcodec png out-static-%05d.png
-   time convert -verbose +dither -layers Optimize -resize 600x600\> out-static*.png  GIF:- | gifsicle --colors 128 --delay=5 --loop --optimize=3 --multifile - > $1.gif
+   time convert -verbose +dither -layers Optimize -resize 600x600\> out-static*.png  GIF:- | gifsicle --colors 128 --delay=5 --loop --optimize=3 --multifile - > $GIF
    rm out-static*.png
  else
-   ffmpeg -i $1 -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > $1.gif
+   ffmpeg -i $1 -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > $GIF
  fi

If you're wondering what the GIF line is about:

$ FOO="Yep.nope.mov"
$ echo "${FOO%.*}.gif"
Yep.nope.gif
@buritica

This comment has been minimized.

Show comment Hide comment
@buritica

buritica Dec 2, 2013

use brew cask install xquartz if you get Error: No available cask for x-quartz

buritica commented Dec 2, 2013

use brew cask install xquartz if you get Error: No available cask for x-quartz

@tonycoco

This comment has been minimized.

Show comment Hide comment
@tonycoco

tonycoco Mar 26, 2014

Not sure if anyone cares about the output, but I like to make my bash functions quiet and less verbose... Here is my stab at it. The output of the command is much prettier. I also added the ability to scale it to a max width (via an argument to the gifify command)...

function gifify {
  if [ -z "$1" ]; then
    echo "$(tput setaf 1)No input file given. Example: gifify example.mov [max width (pixels)]$(tput sgr 0)"
    return 1
  fi

  output_file="${1%.*}.gif"

  echo "$(tput setaf 2)Creating $output_file...$(tput sgr 0)"

  if [ ! -z "$2" ]; then
    maxsize="-vf scale=$2:-1"
  else
    maxsize=""
  fi

  ffmpeg -loglevel panic -i $1 $maxsize -r 10 -vcodec png gifify-tmp-%05d.png
  convert +dither -layers Optimize gifify-tmp-*.png GIF:- | gifsicle --no-warnings --colors 256 --delay=10 --loop --optimize=3 --multifile - > $output_file
  rm gifify-tmp-*.png

  echo "$(tput setaf 2)Done.$(tput sgr 0)"
}

Not sure if anyone cares about the output, but I like to make my bash functions quiet and less verbose... Here is my stab at it. The output of the command is much prettier. I also added the ability to scale it to a max width (via an argument to the gifify command)...

function gifify {
  if [ -z "$1" ]; then
    echo "$(tput setaf 1)No input file given. Example: gifify example.mov [max width (pixels)]$(tput sgr 0)"
    return 1
  fi

  output_file="${1%.*}.gif"

  echo "$(tput setaf 2)Creating $output_file...$(tput sgr 0)"

  if [ ! -z "$2" ]; then
    maxsize="-vf scale=$2:-1"
  else
    maxsize=""
  fi

  ffmpeg -loglevel panic -i $1 $maxsize -r 10 -vcodec png gifify-tmp-%05d.png
  convert +dither -layers Optimize gifify-tmp-*.png GIF:- | gifsicle --no-warnings --colors 256 --delay=10 --loop --optimize=3 --multifile - > $output_file
  rm gifify-tmp-*.png

  echo "$(tput setaf 2)Done.$(tput sgr 0)"
}
@saimonmoore

This comment has been minimized.

Show comment Hide comment
@saimonmoore

saimonmoore May 22, 2014

Hmm....I'm getting the following:

convert: unable to load module `/usr/local/Cellar/imagemagick/6.8.9-1/lib/ImageMagick//modules-Q16/coders/png.la': file not found @ error/module.c/OpenModule/1282.
convert: no decode delegate for this image format `PNG' @ error/constitute.c/ReadImage/501.
convert: no images defined `GIF:-' @ error/convert.c/ConvertImageCommand/3187.

I checked and that file exists. I've reinstalled imagemagick and libpng umpteen times now. Not sure what else to try

Hmm....I'm getting the following:

convert: unable to load module `/usr/local/Cellar/imagemagick/6.8.9-1/lib/ImageMagick//modules-Q16/coders/png.la': file not found @ error/module.c/OpenModule/1282.
convert: no decode delegate for this image format `PNG' @ error/constitute.c/ReadImage/501.
convert: no images defined `GIF:-' @ error/convert.c/ConvertImageCommand/3187.

I checked and that file exists. I've reinstalled imagemagick and libpng umpteen times now. Not sure what else to try

@thatryan

This comment has been minimized.

Show comment Hide comment
@thatryan

thatryan Aug 27, 2014

Few issues getting stuff installed, Xquartz seems to have changed names and versions, but now getting an error gifify:7: command not found: ffmpeg any thoughts? :(

Few issues getting stuff installed, Xquartz seems to have changed names and versions, but now getting an error gifify:7: command not found: ffmpeg any thoughts? :(

@robcolburn

This comment has been minimized.

Show comment Hide comment
@robcolburn

robcolburn Oct 22, 2014

@thatryan It sounds like ffmpeg didn't install right.

  • Try running the command ffmpeg, if that seems to fail, try installing again brew install ffmpeg.
  • If brew seems to be unhappy about that, try brew doctor

@thatryan It sounds like ffmpeg didn't install right.

  • Try running the command ffmpeg, if that seems to fail, try installing again brew install ffmpeg.
  • If brew seems to be unhappy about that, try brew doctor
@paulirish

This comment has been minimized.

Show comment Hide comment
@paulirish

paulirish Oct 23, 2014

afaik the install.sh can now just be

brew install ffmpeg gifsicle imagemagick

i don't believe xquartz is at all neccessary. (not sure why it was.)

afaik the install.sh can now just be

brew install ffmpeg gifsicle imagemagick

i don't believe xquartz is at all neccessary. (not sure why it was.)

@samarpanda

This comment has been minimized.

Show comment Hide comment
@samarpanda

samarpanda Oct 23, 2014

Worked pretty good for me.

brew install ffmpeg gifsicle imagemagick

Thanks @paulirish & @SlexAxton

Worked pretty good for me.

brew install ffmpeg gifsicle imagemagick

Thanks @paulirish & @SlexAxton

@nwinkler

This comment has been minimized.

Show comment Hide comment
@nwinkler

nwinkler Oct 23, 2014

Wow, I like @tonycoco's solution. Well done!

Wow, I like @tonycoco's solution. Well done!

@nwinkler

This comment has been minimized.

Show comment Hide comment
@nwinkler

nwinkler Oct 23, 2014

I've added the gifify function to my bash-it fork: nwinkler/bash-it@e4bdad6

I've added the gifify function to my bash-it fork: nwinkler/bash-it@e4bdad6

@vvo

This comment has been minimized.

Show comment Hide comment
@vvo

vvo Nov 24, 2014

There's now an installable binary for that, lots of options, optimized! https://github.com/vvo/gifify

vvo commented Nov 24, 2014

There's now an installable binary for that, lots of options, optimized! https://github.com/vvo/gifify

@jeanmichelcote

This comment has been minimized.

Show comment Hide comment
@jeanmichelcote

jeanmichelcote Apr 11, 2015

I get error on that command: brew install brew-cask

Error: Failed to download resource "brew-cask"
Failure while executing: git clone --depth 1 --branch v0.53.3 https://github.com/caskroom/homebrew-cask.git /Library/Caches/Homebrew/brew-cask--git

I get error on that command: brew install brew-cask

Error: Failed to download resource "brew-cask"
Failure while executing: git clone --depth 1 --branch v0.53.3 https://github.com/caskroom/homebrew-cask.git /Library/Caches/Homebrew/brew-cask--git

@thatryan

This comment has been minimized.

Show comment Hide comment
@thatryan

thatryan May 14, 2015

Anyone come across this error?

Incompatible pixel format 'rgb24' for codec 'gif', auto-selecting format 'rgb8'

Anyone come across this error?

Incompatible pixel format 'rgb24' for codec 'gif', auto-selecting format 'rgb8'

@CharlesSmart

This comment has been minimized.

Show comment Hide comment
@CharlesSmart

CharlesSmart May 16, 2015

If this helps anyone, my XQuartz location ended up being:
open /opt/homebrew-cask/Caskroom/xquartz/2.7.7/XQuartz.pkg
I assume that's due to the update to 2.7.7?

If this helps anyone, my XQuartz location ended up being:
open /opt/homebrew-cask/Caskroom/xquartz/2.7.7/XQuartz.pkg
I assume that's due to the update to 2.7.7?

@zentrope

This comment has been minimized.

Show comment Hide comment
@zentrope

zentrope May 31, 2015

thatryan: Yes, I have that error (Yosemite). No idea what to do about it.

thatryan: Yes, I have that error (Yosemite). No idea what to do about it.

@nexdrew

This comment has been minimized.

Show comment Hide comment
@nexdrew

nexdrew Jun 18, 2015

For those looking to install @vvo's gifify with prerequisites:

# install pornel/giflossy (fork of gifsicle)
wget https://github.com/pornel/giflossy/releases/download/lossy%2F1.82.1/gifsicle-1.82.1-lossy.zip
unzip gifsicle-1.82.1-lossy.zip -d gifsicle-1.82.1-lossy
cp gifsicle-1.82.1-lossy/mac/gifsicle /usr/local/bin/
# install ffmpeg
brew install ffmpeg --with-fontconfig --with-libass
# install imagemagick
brew install imagemagick --with-fontconfig
# install gifify
npm install -g gifify

Thanks @vvo, @pornel, @paulirish, @SlexAxton, and internets.

nexdrew commented Jun 18, 2015

For those looking to install @vvo's gifify with prerequisites:

# install pornel/giflossy (fork of gifsicle)
wget https://github.com/pornel/giflossy/releases/download/lossy%2F1.82.1/gifsicle-1.82.1-lossy.zip
unzip gifsicle-1.82.1-lossy.zip -d gifsicle-1.82.1-lossy
cp gifsicle-1.82.1-lossy/mac/gifsicle /usr/local/bin/
# install ffmpeg
brew install ffmpeg --with-fontconfig --with-libass
# install imagemagick
brew install imagemagick --with-fontconfig
# install gifify
npm install -g gifify

Thanks @vvo, @pornel, @paulirish, @SlexAxton, and internets.

@neuropass

This comment has been minimized.

Show comment Hide comment
@neuropass

neuropass Jan 18, 2016

Please forgive my ignorance on the matter. I really want to use this as it seems the only method for high quality gifs.
I understand this is for MAC users only? I do have a mac pro. How can I use this script?
Thanks so much again!

Please forgive my ignorance on the matter. I really want to use this as it seems the only method for high quality gifs.
I understand this is for MAC users only? I do have a mac pro. How can I use this script?
Thanks so much again!

@vvo

This comment has been minimized.

Show comment Hide comment
@vvo

vvo Feb 6, 2016

@nexdrew could you please add this to the gifify repo as a PR? very valuable

vvo commented Feb 6, 2016

@nexdrew could you please add this to the gifify repo as a PR? very valuable

@mhulse

This comment has been minimized.

Show comment Hide comment
@mhulse

mhulse Mar 27, 2016

@nexdrew could you please add this to the gifify repo as a PR? very valuable

@vvo and @nexdrew, here's a PR that does it in a curl one-liner: vvo/gifify#46. Feedback?

mhulse commented Mar 27, 2016

@nexdrew could you please add this to the gifify repo as a PR? very valuable

@vvo and @nexdrew, here's a PR that does it in a curl one-liner: vvo/gifify#46. Feedback?

@mhulse

This comment has been minimized.

Show comment Hide comment
@mhulse

mhulse Mar 27, 2016

For anyone else interested, installing gifify locally works pretty well too.

$ npm install --save-dev gifify

… in your package.json:

"scripts": {
  "gifify": "gifify"
}

And can be run from command line like so:

$ npm run gifify -- -o test.gif test.mp4

… or js script within package.

mhulse commented Mar 27, 2016

For anyone else interested, installing gifify locally works pretty well too.

$ npm install --save-dev gifify

… in your package.json:

"scripts": {
  "gifify": "gifify"
}

And can be run from command line like so:

$ npm run gifify -- -o test.gif test.mp4

… or js script within package.

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