The answer from @Stephane is very good. But it will get a warning like Buffer queue overflow, dropping.
for some video, and the generated gif
has some frame dropped.
Here is a better version with fifo
filter to avoid Buffer queue overflow
when using paletteuse
filter. By using split
filter to avoid the creation of intermediate palette PNG file.
ffmpeg -i input.mp4 -filter_complex 'fps=10,scale=320:-1:flags=lanczos,split [o1] [o2];[o1] palettegen [p]; [o2] fifo [o3];[o3] [p] paletteuse' out.gif