Page 1 of 1

Merging Animated GIFs as Layers

Posted: 2009-08-28T09:50:42-07:00
by avs84
Hello,

I have been trying to find a solution to this problem for 2 days already :shock: . A will appreciate any help here.

I have to combine 2 animated gif files with different frames number and different duration into a single animated files with a fixed duration and infinite loop. They have to be layered one above the other.
One of the images has less frames than the other, when the shorter finishes its animation it has to display the last frame until the other animation finishes and then the whole animation repeats.
I need the command to be able to work on any two random animations I decide to combine.

For example I have these two gifs here:
ImageImage
I managed to come here so far:
Image
I will really appreciate any help here. Thanks in advance.

Re: Merging Animated GIFs as Layers

Posted: 2009-08-28T12:02:35-07:00
by fmw42
The solution was posted just a few days ago in this very forum. See Anthony's solution for the post at viewtopic.php?f=1&t=12573&p=50397&hilit ... mes#p50397

Re: Merging Animated GIFs as Layers

Posted: 2009-08-29T03:21:34-07:00
by avs84
Thanks! This solved my problem.

However, is there other method than using -clone ? I thought there might be built-in command for this.

Re: Merging Animated GIFs as Layers

Posted: 2009-08-29T10:58:17-07:00
by fmw42
Not that I know about. You need to separate frames using -coalesce and then repeat frames with -clone to duplicate enough frames to have the same number of frames, set appropriate delays, then recombine the animation. Nothing automatic that I know about.

But I will defer to the IM experts on this as I do not do many animations.

Re: Merging Animated GIFs as Layers

Posted: 2009-08-30T19:32:24-07:00
by anthony
The ultimate solution to merging two animations is given as a 'psuedo-code' proceedure in...

Merging Time Disjoint Animations
http://www.imagemagick.org/Usage/anim_mods/#merge

The link to the discussion was applying this method to animations with periods of
particularly fast modifications and sections of no changes.

The key is to make the animations of the same length in time (maybe looping one animation number times, and adjusting the timings a bit. AND with the same number of frames, usually by cloning.

The solution that discussion comes up with is NOT GENERAL, but works by converting BOTH animations into a sequence where all frames have a equal time delays, and same number of frames. Sort of like converting each animation into a movie of constant frames per second.

When the timings and number of frames of both animations, you can then use -layers composite to merge the animation, and can even then use other image operators such as -layers RemoveDups to remove frames that don't change after the merger.

See Remove Duplicate Frames - merging consecutive duplicate images
http://www.imagemagick.org/Usage/anim_opt/#removedups


In summery. it is a LIMITED SOLUTION, but one that works well for most 'fast changing' animations.

A script was created but not released to me or to the general public.