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 over 300 MB in size while the movie file foo.mp4
was about 15 MB!
What gives?
Unlike the original video file that you uploaded, a GIF image contains multiple frames - the longer the duration, the more frames. So your 2 seconds of video, could contain up to 20 or more images within a single GIF file.
Another option would be to resize the image: go to Image > Scale Image... and scale the image to the proportion you want.
Do you ever wonder why sometimes, if you transform an MP4 to an animated GIF, the GIF will end up having a much bigger file size than its MP4 video source? The difference can sometimes become huge, a 10-second video clip in MP4 format might be 2MB, but the same video in GIF format can take up more than 20MB.
A comprehensive answer to this question is difficult :-p In a nutshell, it comes down to how the compression is done in each format.
In GIF animations, each frame is conceptually a separate GIF image. All of the GIF images are then stored in one large GIF file, with instructions to play the frames back with a certain delay between the frames. To optimize the frames, you can run the GIF through a program that can delete duplicate information from one frame to the next (the GIMP "Animation Optimize" filter is a good way to do that: GIMP – Simple Animations).
On the other hand, video formats like MP4 have a different approach. They assume that frames are going to be similar, and only store the difference between two frames. Additionally, the amount of data for each frame is limited to the specified video bitrate given when you begin the compression. Lossy compression is performed to bring the video file down to the desired bitrate. To further optimize the video file, most video transcoders include options for "two-pass encoding". This runs through the video twice: the first time it just gathers information about what parts of the file are more complex, and then the second time it compresses every not complex portion of the video more aggressively.
There are many other optimizations as part of the video encoding process that are just plain missing from the GIF file format. Also, it's worth pointing out that a GIF animation is going to be limited to a 256-color palette, which can result in image dithering. MP4 uses something more similar to a JPEG compression for the video frames (although with additional optimizations targeted specifically at video… the old MJPEG format was basically just stacks of JPEG images, just as GIF animations are stacks of GIF images).
If you can give more information about your specific use case, we may be able to help you find a better solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With