Skip to content

Instantly share code, notes, and snippets.

@frdmn
Last active December 28, 2015 15:59
Show Gist options
  • Save frdmn/7525976 to your computer and use it in GitHub Desktop.
Save frdmn/7525976 to your computer and use it in GitHub Desktop.
Bash function for OS X to convert a .mov file into a .gif but in a reasonable quality.

mov2gif converter

Bash function for OS X to convert a .mov file into a .gif but in a reasonable quality.

Demonstration

.mov example (414 KB)

Click here for a example .mov

.gif example (190 KB)

example gif

Requirements

XQuartz

wget -O /tmp/XQuartz-2.7.5.dmg http://xquartz.macosforge.org/downloads/SL/XQuartz-2.7.5.dmg
open /tmp/XQuartz-2.7.5.dmg

ffmpeg and gifsicle

brew install ffmpeg 
brew install gifsicle

Installation

Put the following function into your .bashrc or .zshrc:

function mov2gif {
  file="$1"
  if [ $1 ]; then
    if [[ "$file" == *.mov || "$file" == *.MOV ]]; then
      echo -n "Generating gif from movie '$1' ... "
      rm "$1".gif &> /dev/null
      ffmpeg -i "$1" -r 10 -f image2pipe -vcodec ppm - 2>/dev/null | convert -verbose +dither -layers Optimize -resize 600x600\> - gif:- 2>/dev/null | gifsicle --colors 128 --delay=5 --loop --optimize=3 --multifile - 2>/dev/null > "$1".gif
      echo -n "done\nMoving gif to '$1.gif' ... done\n"
    else
      echo -n "Error: '$1' is not a .mov file!\n"
    fi
  else
    echo -n "Error: no argument"
  fi
}    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment