I'm converting videos into gifs with FFmpeg, but I'm running into an issue that many have encountered before: many gif players refuse to play gifs faster than 50FPS (2 hundredth of a second frame duration). The gif format technically allows up to 100FPS but not all players support that.
I have code now to limit the FPS to 50FPS, but the problem is that FFmpeg, when encoding from a weird fps like 29.97fps, will occasionally generate 1/100 s frames since each frame duration is independent.
I want to, ideally with a single ffmpeg command, generate a GIF of the right speed (not slowing down or speeding up) but without ever generating 1/100 s frames. Is this possible?
For Rotem, the code is just
outname = reserve_tempfile("gif")
fps = await get_frame_rate(video)
await run_command("ffmpeg", "-i", video,
# prevent partial frames, makes filesize worse but fixes issues with transparency
"-gifflags", "-transdiff",
"-vf",
# cap fps because gifs are wackyyyyyy
# TODO: https://superuser.com/q/1854904/1001487
("fps=fps=50," if fps > 50 else "") + \
# make and use nice palette
"split[s0][s1];[s0]palettegen=reserve_transparent=1[p];[s1][p]paletteuse=bayer",
# i hate gifs so much man
"-fps_mode", "vfr",
outname)