FFmpeg - Convert video to animated gif

By xngo on June 8, 2019

Convert video to animated gif

# Simple conversion to animated gif.
    ffmpeg -hide_banner -nostdin -y -i VIDEO.mkv OUTPUT.gif
# Conversion to animated gif using palette colors.
    # 1 - Export the palette colors.
    ffmpeg -y -i VIDEO.mkv -vf fps=10,palettegen palette.png
    # 2 - Output the GIF using the palette.
    ffmpeg -y -i VIDEO.mkv -i palette.png -filter_complex "fps=10" OUTPUT.gif
    # If you want higher quality, use the followings:
    ffmpeg -y -i VIDEO.mkv \
        -vf fps=10,scale=0:-1:flags=lanczos,palettegen palette.png
    ffmpeg -y -i VIDEO.mkv -i palette.png -filter_complex \
        "fps=10,scale=0:-1:flags=lanczos[x];[x][1:v]paletteuse" OUTPUT.gif

Note: The resulting animated GIF file size will inherently be bigger than the original video. See https://stackoverflow.com/questions/12573604/gif-created-from-a-movie-file-with-ffmpeg-is-really-large-in-size.



  • http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.