

I decided to narrow down where this problem was originating before diving into the code.

Using a nifty tool in the repo called graph2dot, I generated a plot of each step in the process: The FFmpeg codebase is large and complex, and the filter above is fairly complicated as well. What was strange, however, was that non-transparent pixels were being affected. This indicated something was going wrong when processing transparent pixels. This bug only affected Stickers, which are GIFs with some transparent pixels. The buggy renditions were traced back to an FFmpeg command that we use to re-scale GIFs while retaining the original color palette: ffmpeg -i in.gif -filter_complex "scale=100:-1, split palettegen paletteuse" out.gif

Unwilling to let the world go without pixel-perfect poop, I started hunting down the bug. To convert a video file video.mov to an animated gif with 5 frames per second and sized to 450 by (whatever height is proportionally correct for that x value) ffmpeg -i video.mov -vf fps=5,scale=450:-1 animated.gifįfmpeg will detect your movie type so you should be able to use ‘.mpg’, ‘.mp4’ without changing the command.Notice that some parts of the image get stuck (eg, the top of this GIF) And we don’t need 30 or 60 frames per second in the gif, usually we can get away with about 5, and sometimes as low as 1 or 2.Īll of this helps keep the file size lower. Instead, we want to control the x and y dimensions to make it easier to re-use on the web. The simplest command to create an animated gif would be: ffmpeg -i video.mov animated.gifīut this will create a gif file with the same dimensions as the movie and will convert every frame of video, so it might actually end up larger file size than the movie. Since I created a video, I thought I’d try and figure out how to use ffmpeg to convert the video to an animated gif. I’ve used ScreenToGif and CloudApp to create animated gifs in the past. I decided to look at ffmpeg and see if it can create animated gifs, and it can. I recorded a video, and thought it would be easier to upload as an animated gif.
