4

I want to convert a gif file to a video with ffmpeg. I'm using:

ffmpeg -y -i /gif/583fd7661b46d.gif -strict -2 -an -b:v 32M /gif/mp4/583fd7661b46d.avi

The duration of my gif in photoshop is 27 seconds, but the duration of the video "583fd7661b46d.avi" generated is 15 seconds. How can I get the same duration of my gif in the video generated?

ivan_pozdeev
  • 1,973

2 Answers2

3

Using your sample, I identified the problem:

In your GIF, the last (empty) frame has a duration of 10370ms. It seems to be ignored by ffmpeg, producing the difference.

If I change the output format to .mp4, the duration becomes correct. Changing encoder has no effect.

So, this is a bug in ffmpeg. This might be due to a limitation of the output format, which is very unlikely (the problem is also present for .mkv), but in that case, it should at least print a warning. Looking through their bug tracker, I found #4235 (Converting GIF to MP4 using FFmpeg produces a video that doesn't follow the GIF frame timings.) - looks like this was fixed for the .mp4 format but not for others.

ivan_pozdeev
  • 1,973
0

Just apply presentation timestamp filter with a coefficient equal to fraction original time / achieved time in your case - 27/15. So you add filter -filter:v "setpts=27/15*PTS" before output file name.

More about framerate changes at FFmpeg wiki: https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video

Pavlus
  • 548