Wednesday, May 15, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 5793  / 3 Years ago, mon, may 10, 2021, 10:51:37

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)


More From » ffmpeg

 Answers
0

.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.

  • You can also use -t to specify duration instead of end time.

  • You can add a decimal point to indicate milliseconds. (ex. 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


  • This will halve the image dimensions, and roughly quarter the file size. You can scale this down even further by changing the value. For example, scale=iw/3:ih/3 will result in an image with one third the original dimensions.


[#2280] Wednesday, May 12, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rofity

Total Points: 182
Total Questions: 98
Total Answers: 115

Location: Albania
Member since Sat, Jan 7, 2023
1 Year ago
rofity questions
Mon, Apr 25, 22, 12:28, 2 Years ago
Tue, Jul 5, 22, 16:53, 2 Years ago
Sat, Apr 8, 23, 05:32, 1 Year ago
Tue, May 17, 22, 02:46, 2 Years ago
;