I was doing an ingame video capture and I needed to have it in a GIF format. A few frames of the animation could be optimized as there were sometimes still images. So if I wanted to remove those unnecessary frames (while keeping the correct duration, of course), one can simply use ImageMagick.
ImageMagick should be included by default in Debian and probably other distributions. So you just have to use the
convert command. Here is an example:
convert "gifToOptimize.gif" -layers RemoveDups -layers OptimizeFrame "removedDups.gif"
It will remove duplicate frames and try to optimize frames by looking at similar areas of the pictures across the animation so they don’t appear twice.
Now, if you have specific needs, you better check the documentation here: http://www.imagemagick.org/Usage/anim_opt. There are some examples which will give you an idea of how to perform the best optimization.