public
Last active

My gif workflow

  • Download Gist
.zshrc
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13
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
}
Install.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12
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
usage.sh
Shell
1 2 3 4
# Take screencast using Quicktime. Export as high quality as possible.
 
gifify screencap.mov
gifify screencap.mov --good

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?

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

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

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

Just save in native quality for best results.

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.

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

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

does this require zsh?

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

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

If that helps anyone.

Quality is pretty amazing.

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

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

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)"
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.