I use this snippets for generating GIFs. The following parameters can be tweaked:

  • ss - start seconds
  • t - length seconds
  • i - input file
  • vf - customize the fps, scale, crop fields
    • fps - frames per second. Should be low for a small gif.
    • scale - size of output. change 1024:-1 to correspond to width:height of output.
    • crop - crop iw:ih does nothing, since iw and ih stand for input width/height. Change these to numbers to crop to a size.

0. Record Image

  • For screen recordings, QuickTime on macOS is a good choice.
  • VirtualBox has built-in recording options via View > Recording. Results go into your VirtualBox VMs folder.

1. Generate Color Pallette.

We use this color pallette when generating the gif to step 2. It’s just a PNG file with colors used in the output.

ffmpeg \
  -y \ # - overwrite output file
  -ss 0 \ # Start Seconds
  -t 3 \ # Length of Gif
  -i input.flv \ # Src Video
  -vf fps=4,scale=1024:-1:flags=lanczos,palettegen \ # Filters
  palette.png # Output color pallette

2. Generate output GIF.

Here, we provide our pallette from step 1, as well as the input file, to generate the output.

ffmpeg \
  -ss 0 \ # Start Seconds
  -t 3 \ # Length of Gif
  -i input.flv \ # Src Video
  -i palette.png \ # Color pallette (from step 1)
  -filter_complex \ # Complex filter:
    "fps=4,crop=iw:ih,scale=1024:-1:flags=lanczos[x];[x][1:v]paletteuse" \
  output.gif # Output gif

Happy Gif-ing!

msdos-6.22

original source