Résumé: GIF-creation

Written by  on July 2, 2016 

Creating a GIF is not hard, actually it’s a one-liner.
But if you have a shaky video as source with slight over-exposure and to regard a size-limit for the final result, then the challenge rises.
Article deals with deshaking, greyscaling, cropping, size-reduction and a palette-optimized GIF-output without the infamous dithering.

The following settings are listed in best order. Trimming can be done first, because then no unnecessary video-material is processed.
Best for a 2 MiByte-limit are 12 fps, 500px wide, greyscaled (if necessary) GIF of 3-4 s length. Together with some minor cropping.

  1. update to latest ffmpeg-version:
    Not doing so can result in issues with x264-codec and the palette-feature is not working (because not implemented yet)
  2. deshake:

    Uses a typical default setting for deshaking. For worse cases, try this manually configured setting.
  3. crop:

    -1 as second parameter for scale means “proportionally scaled”; combined video-filtering-flags are separated by commas
  4. trim (length and starting position):

    Read: copy from second 12 the following 34 seconds to the output. If smaller parts are needed, use a decimal dot after the second.
  5. crop:

    Crop a block with width 320 px and height of 240 px starting from (x,y)=(20,430). I prefer to measure the best position and size via GIMP’s selection-tool and a still-frame of the current video.
  6. final conversion to GIF (palette-optimized):
    Use the suggested palette-based rendering skript from this page. In short: it first generates a palette for all the frames for the whole animation. Then renders using ffmpeg the GIF from the source.

    Sometimes I load the resulting GIF into GIMP, crop it again and run its “GIF-animation-optimization” (not really helpful, because ffmpeg renders already with “combine” frame-disposal) to squeeze even the last bits out of it. Or delete manually some frames at the beginning or end.

One of the better examples (just 2 MiByte!) would be this: an almost perfect loop of a purring kitty :3
short.mp4

Category : ffmpeg

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.