4
votes

I have a GIF image. I am trying to convert it to MP4.

ffmpeg -f image2 -r {delay_time_of_gif_between_each_frame}/1 -i temp/%05d.png -vcodec libx264 video.mp4

This MP4 is not running at the same speed when compared to the original GIF. How do I make it to run with the same speed?

It seems I am making mistakes with the -r property. I played with it but don't get anything useful. I even removed it. Still it isn't working.

2

2 Answers

2
votes

If you already know the time of delay between subsequent frames, then you need to take the inverse of it to convert it to a frame rate. For example, if the time between each frame is 40ms (or 0.04s), then the inverse would be 1 divided by 0.04, thus 25 fps.

You can not simply divide the time between frames by 1, since division by 1 will give you the same result as before.

So, try either of these again:

ffmpeg -f image2 -r 1/0.04 -i temp/%05d.png -c:v libx264 out.mp4
ffmpeg -f image2 -r 25 -i temp/%05d.png -c:v libx264 out.mp4

Note that the default input frame rate for image2 is 25 anyway, but this was just for illustration.

Also, you can change the frame rate of the output video as well, by putting -r after the input file, which should make a difference.

ffmpeg -f images -i temp/%05d.png -c:v libx264 -r 25 out.mp4
2
votes

Although this question is somewhat older:

Current versions of ffmpeg automatically determine the delays between the frames according to the information in the gif images, so no need to set the frame rate in the command.