7

I have an animated gif and I'd like to cut off the last 5 seconds. Does anyone know how to do that in Linux/Ubuntu?

  • I think an online editor would be much easier than finding some special GIF editor for Ubuntu, but if you open the file as layers in GIMP, you can manually delete the frames you don't want before exporting it as a GIF again. – TheWanderer Jan 12 '17 at 0:06
9

There are multiple ways to do this.

Option 1: Use a command line tool called gifsicle. It's available in default Ubuntu/Debian repositories.

It's fast and won't affect the quality, buy it only accepts frame numbers, not time, so if you need to cut exact time, you should figure out the frame number yourself. You can view the total number of frames and delay times between each frame with this command:

gifsicle --info YOURFILE.gif

Then you can divide the time you want to cut with the frame delay and it will give you the number of frames in this time, so you can figure out start frame and end frame.

Replace XXXX with the frame where you want your GIF to start, and YYYY with frame where you want your GIF to end.

gifsicle YOURFILE.gif '#XXXX-YYYYY' -O3 > cut.gif

Option 2: Using FFMPEG. It's also available in apt.

FFMPEG accepts time directly, so it's very straightforward, but it may worsen the quality of output gif and increase file size in some cases.

ffmpeg -i YOURFILE.gif -ss 00:00:04 -t 00:00:08 -async 1 cut.gif

Option 3: if you're ok with online tools and your GIF does not exceed 20MB, this online tool can cut GIFs by frame number or by time and won't affect the quality.

  • 1
    FYI for others, -O3 is an optimization option and not necessary (though maybe helpful) and #XXXX is just a placeholder for frame number. Use the frame numbers as they appear in the previous --info step output. In my case '#0-74' for a gif I just made. (Got hung up on four digit numbers for a moment when I first saw this.) – Hendy Dec 3 '17 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.