Is it possible to shorten a .gif
file through FFmpeg
?
I need to upload a .gif
but the service I'm using only allows a max filesize of 30mb
(the file is 35.4mb
)
Is it possible to shorten a .gif
file through FFmpeg
?
I need to upload a .gif
but the service I'm using only allows a max filesize of 30mb
(the file is 35.4mb
)
.gif
is an extremely inefficient format for video files.
If you are flexible with the format, the best option is to convert the file to .mp4
: This will reduce the file size by an enormous degree without significant loss of quality. In many cases it can reduce the file size of a .gif
by a factor of 100x or more. Use the following command:
ffmpeg -i input.gif -pix_fmt yuv420p output.mp4
Replace input.gif
with the source filename and output.mp4
with the desired name for the new file.
If you need the format to be .gif
, you can shorten the animation to reduce the size. To do this, you will need to define start and end times in ffmpeg
.
Here is an example:
ffmpeg -i input.gif -ss 00:00:00 -to 00:00:03 -c copy output.gif
-ss
defines the start time in HH:MM:SS
-to
defines the end time.-t
to specify duration instead of end time.00:00:05.5
)A third option would be to scale down the dimensions of the image:
ffmpeg -i input.gif -vf "scale=iw/2:ih/2" output.gif
scale=iw/3:ih/3
will result in an image with one third the original dimensions.