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.
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.
Note that much legacy documentation of ImageMagick refers to the identify (now magick identify) and convert (now magick) commands, which could be what you need depending how recent your version is.
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:
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.
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.
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.
Here's one more. Using ImageMagick, the command:
takes the first 100 frames of
Long.gif
and saves them asShort.gif
You can see how many frames you're starting with using:
The last line of the output will show the number of frames in square brackets, for example:
which indicates that
Long.gif
has 830 frames.Note that much legacy documentation of ImageMagick refers to the
identify
(nowmagick identify
) andconvert
(nowmagick
) commands, which could be what you need depending how recent your version is.