Blog
All posts
0:00

Abdul Jamjoom
Edited on 11/1/22
Created on November 1, 2022 at 2:41 pm
Edited on November 1, 2022 at 5:35 pm
·
threads-blog

threads-blog
Improve GIF quality with ffmpeg
Watch narration
0:00
0:00
Let's skip straight to the result before diving into the details
The left side is old, right is new.
s/o to .this post on the pkh blog that offers great insights into this process!

:sparkles
0:00
Pro-tip: replace gifs w/ muted looping videos if you can
0:00
So, how did we create GIFs?
We relied on defaults:
ffmpeg -i <input_video>.mp4 -t 5 -vf fps=15,scale=480:-1 ./generated_gif.gif
0:00
[GIF internals] Color Pallet
0:00
[GIF internals] Dithering
Approximate colors not available in your pallet by diffusing colored pixels from your pallet
0:00
How do we create GIFs now with improved quality?
stats_mode=diff
(focus on the moving object)floyd_steinberg
dithering 0:00
Code for generating HQ GIFs
./<file_name>.sh <video_file_name>.mp4
#!/bin/bash
filename=$(basename -- "$1")
palette_png="./palette_png.png"
ffmpeg -t 5 -i "$1" -vf "$filters_new,palettegen=stats_mode=diff" -y $palette_png
ffmpeg -t 5 -i "$1" -i $palette_png -lavfi "$filters_new [x]; [x][1:v] paletteuse=dither=floyd_steinberg" -y "./generated_GIF.gif"
0:00
References
0:00
Have questions or suggestions?
©2022 Threads, Inc.