Embracing the Messiness in Search of Epic Solutions

FFmpeg: High-Quality MP4 to GIF

Posted

in

PROBLEM

You want to generate high-quality GIFs from MP4 files without using extra software or online services.

SOLUTION

Install FFmpeg.

Default FFmpeg conversions often look low quality because GIFs are limited to 256 colors and use a generic color map. So, a two-pass conversion will be used.

# Pass 1: Analyze the video to generate a palette
ffmpeg -i input.mp4 \
  -vf "fps=10,scale=850:-1:flags=lanczos,palettegen" \
  palette.png

# Pass 2: Apply the palette to create the GIF
ffmpeg -i input.mp4 \
  -i palette.png \
  -filter_complex "fps=10,scale=850:-1:flags=lanczos[x];[x][1:v]paletteuse" \
  output.gif

Parameters:

  • fps=10: Reduces frame rate and file size.
  • scale=850:-1: Sets width to 850px, -1 will keep aspect ratio.
  • flags=lanczos: Sharper scaling algorithm.
  • palettegen: Generates optimal 256-color palette.
  • paletteuse: Applies the generated palette.

Tags:

Comments

Leave a Reply