Skip to content

Instantly share code, notes, and snippets.

@nvcken
Forked from sahilseth/OSX-Convert-MOV-GIF.md
Created May 25, 2018 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nvcken/72f1827c3bb715faa2165894615482c6 to your computer and use it in GitHub Desktop.
Save nvcken/72f1827c3bb715faa2165894615482c6 to your computer and use it in GitHub Desktop.
Creating GIFs from .MOV files in OSX using FFmpeg and ImageMagick

Convert MOV to GIF using FFmpeg and ImageMagick

I tried a few different techniques to make a GIF via command-line and the following gives me the best control of quality and size. Once you're all setup, you'll be pumping out GIFs in no time!

Preparation

Install FFmpeg

brew install ffmpeg [all your options]
##* Example:
brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libass --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools

Install ImageMagick

  • $ brew install imagemagick

Now convert!

Grab screenshot from Quicktime (or what you want. I like Screenflow)

  • Open Quicktime > File > New Screen Recordering > After recording 'Save'

Use ffmpeg to slice .mov into high quality .png's

  • $ ffmpeg -i screencast.mov -vf scale=320:-1 -r 10 output/ffout%3d.png
    • 'screencast.mov' location of .mov
    • 'scale=320' set scale to what you want
    • '-r 10' set framerate
    • 'output/ffout%3d.png' output pngs in output folder

Use Convert from ImageMagick

  • $ convert -delay 8 -loop 0 output/ffout*.png output/animation.gif
  • 'convert' is the command-line tool from ImageMagick
  • '-dalay' is the delay of 8, you would get a FPS=100/8=12.5
  • '-loop' adds Netscape loop extension to your GIF animation
  • 'output/ffout*.png' is the directory and file names going into the GIF
  • 'output/animation.gif' is the final location and GIF output

Resources

Great Articles

@nvcken
Copy link
Author

nvcken commented May 25, 2018

# Convert video to gif file.
# Usage: video2gif video_file (scale) (fps)
video2gif() {
  ffmpeg -y -i "${1}" -vf fps=${3:-10},scale=${2:-320}:-1:flags=lanczos,palettegen "${1}.png"
  ffmpeg -i "${1}" -i "${1}.png" -filter_complex "fps=${3:-10},scale=${2:-320}:-1:flags=lanczos[x];[x][1:v]paletteuse" "${1}".gif
  rm "${1}.png"
}
video2gif input.flv 320 10

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