GIF created from ffmpeg movie file is really big

I created a GIF using ffmpeg using the following command:

ffmpeg -i foo.mp4 -ss 00:00:18 -t 00:00:06 -pix_fmt rgb24 bar.gif

However, the resulting bar.gif was larger than 300 MB, and the movie file foo.mp4 was about 15 MB!

What gives?

+7
source share
2 answers

The complete answer to this question is difficult: -p In a nutshell, it comes down to how compression is performed in each format.

In GIF animations, each frame is conceptually a separate GIF image. All GIF images are then saved in one large GIF file with instructions for playing frames with a certain delay between frames. To optimize frames, you can run GIF through a program that can remove duplicate information from one frame to another (GIMP filter "Animation Optimization" is a good way to do this: GIMP - Simple animations ).

On the other hand, video formats such as MP4 have a different approach. They assume that the frames will be similar, and preserve the difference between the two frames. In addition, the amount of data for each frame is limited by the specified bit rate of the video data specified at the beginning of compression. Lossy compression is performed to bring the video file to the desired bit rate. To further optimize the video file, most video transcoders include two-pass encoding options. This is done through the video twice: the first time it simply collects information about which parts of the file are more complex, and then the second time it more aggressively compresses each non-complex part of the video.

There are many other optimizations as part of the video encoding process that are simply missing from the GIF file format. In addition, it is worth noting that the GIF animation will be limited to a palette of 256 colors, which can lead to smoothing of images. MP4 uses something more like JPEG compression for video frames (although with additional optimizations specifically designed for video ... the old MJPEG format was basically just JPEG image stacks, just like GIF animations are stacks of GIF images).

If you can provide more detailed information about your specific use case, we can help you find the best solution.

+4
source

I agree with you, using this command is not optimal:

 avconv -i input.mp4 -pix_fmt rgb24 output.gif 

Use Gimp as follows after this conversion:

enter image description here

+2
source

All Articles