merging looped animations serially

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
viper-2
Posts: 23
Joined: 2011-04-20T10:29:09-07:00
Authentication code: 8675308

merging looped animations serially

Post by viper-2 »

I'm trying to merge three looped animations as a single animated .gif. I thought the solution should be really simple, but I've noted Anthony's warning "ut it may not be quite as easy as it looks" at <http://www.imagemagick.org/Usage/anim_mods/#merging>;-)

I converted 2 files, iris0.png and iris1.png, resizing each with resolutions 900x675, 720x540, 576x432. I then made 3 animations, each corresponding to 1 resolution:

convert -delay 30 iris0-900.png iris1-900.png -loop 6 iris-900.gif
convert -delay 30 iris0-720.png iris1-720.png -loop 6 iris-720.gif
convert -delay 30 iris0-576.png iris1-576.png -loop 6 iris-576.gif

I then merged the animations:

convert iris-900.gif iris-720.gif iris576.gif -loop 1 iris.gif

Instead of the resulting animation looping once, playing each component gif in sequence, iris.gif loops 6 times playing the 2 files at each resolution only once in each cycle.

I've tried using :null to mark the end of each sequence to no avail (see <http://www.imagemagick.org/Usage/anim_mods/#composite>) and coalesce doesn't seem to help.

I've uploaded the animations in the folder "splash-test" at the bottom of this page
<http://www.codeartnow.com/code/download ... -2-preview>

Have I overlooked something simple? Thanks for your patience.;-)

agt

Freedom - no pane, all gaiGN!

Code Art Now
http://codeartnow.com
Email: agt@codeartnow.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: merging looped animations serially

Post by fmw42 »

I am not an expert on animation. But ...

I believe the issue may be that there are only two files in each animation. you need to duplicate the image 6 times to get the animation to play 6 times before going to the next resolution. Just because you are telling each one to loop 6 times means nothing as I expect the merge will ignore the loop for each one.

You may also have trouble with the disposal, so you should read about that as the animations are not the same size. see http://www.imagemagick.org/Usage/anim_basics/#dispose.

see http://www.imagemagick.org/Usage/basics/#duplicate but you will need a recent version of IM to use it as it was added in IM 6.6.8-7.


Also I don't see you link to "splash-test" folder
viper-2
Posts: 23
Joined: 2011-04-20T10:29:09-07:00
Authentication code: 8675308

Re: merging looped animations serially

Post by viper-2 »

fmw42 wrote:I am not an expert on animation. But ...

I believe the issue may be that there are only two files in each animation. you need to duplicate the image 6 times to get the animation to play 6 times before going to the next resolution. Just because you are telling each one to loop 6 times means nothing as I expect the merge will ignore the loop for each one.

You may also have trouble with the disposal, so you should read about that as the animations are not the same size. see http://www.imagemagick.org/Usage/anim_basics/#dispose.

see http://www.imagemagick.org/Usage/basics/#duplicate but you will need a recent version of IM to use it as it was added in IM 6.6.8-7.


Also I don't see you link to "splash-test" folder
I may be thinking of using loop more in terms of a nested programming construct. I have IM 6.7.0-8; I'll have a look at the #duplicate page and report back tomorrow.

codeartnow.com is a google site. There's no link to the folder splash-test in the filing cabinet, but there are links to each file in the folder, just go to the bottom of the page <http://www.codeartnow.com/code/download ... -2-preview>
and you'll see the folder.

This, e.g., will take you to the final animation iris.gif:
<http://www.codeartnow.com/code/download ... ects=0&d=1>
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: merging looped animations serially

Post by fmw42 »

try this


convert -delay 20 -dispose previous \
\( -delay 20 iris-900.gif -duplicate 6,0--1 \) \
\( -delay 20 iris-720.gif -duplicate 6,0--1 \) \
\( -delay 20 iris-576.gif -duplicate 6,0--1 \) \
-loop 1 iris.gif

or this


convert -delay 20 -dispose previous \
\( -delay 20 iris-900.gif -duplicate 6,0--1 -bordercolor white -border 1 \) \
\( -delay 20 iris-720.gif -duplicate 6,0--1 -background white -gravity center -extent 902x677 \) \
\( -delay 20 iris-576.gif -duplicate 6,0--1 -background white -gravity center -extent 902x677 \) \
-loop 1 iris2.gif
viper-2
Posts: 23
Joined: 2011-04-20T10:29:09-07:00
Authentication code: 8675308

Re: merging looped animations serially

Post by viper-2 »

fmw42,

Thank you, the sequence is now correct - but the file takes 6 minutes to load, and another 3 minutes to read all 42 files (the title bar counts 42)!!

I've only tried the first solution, but this wouldn't work for a splash screen. Disposal gives the same chequerboard results as before. I'm going to forget about disposal for now and concentrate on the sequencing for a more memory efficient solution. Will post back tomorrow after reading about the -duplicate switch.

agt

Freedom - no pane, all gaiGN!

Code Art Now
http://codeartnow.com
Email: agt@codeartnow.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: merging looped animations serially

Post by fmw42 »

try the second one, it is rather slow, but the disposal works out so that the background is white and does not leave the previous image behind. (at least for me). I seem to recall your earlier message where you were getting the background from the previous image and could not avoid that. The white border is what is needed to avoid that along with -dispose previous, even though it worked for me. Seems like you are still having that problem with your version of IM/platform. The -gravity center -extent allows each size to be centered rather than put in the upper left corner, which to me looks strange.
Last edited by fmw42 on 2011-06-27T20:18:06-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: merging looped animations serially

Post by anthony »

the -loop N is just a setting that is added to a GIF animation. It tells the animation program (web browser or animate) to loop N times than stop.

However there is no control in a GIF animation beyond a simple (loop everythng N times). You can not loop 5 frames 6 times then the next 5 frames 6 times. You can only loop all 10 frames 6 times.

You can think of loop, as taking a film strip (there is only one strip) and splicing the begining to the end. and runing round the loop N times. That is it.

As Fred pointed out the only way to say loop a sub-set of frames is to duplicate those frames. A bit like making copies of a film strip and splicing them to form a longer film strip.

As for the positioning... You can simple add an relative offset to the later sequences. that is what the offsets are for!
See http://www.imagemagick.org/Usage/anim_m ... e_relative

Of just create a coalesce (full frame film strip like) sequence and use -layers optimize to remove any unnessary image data and set the right disposal method.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: merging looped animations serially

Post by fmw42 »

As for the positioning... You can simple add an relative offset to the later sequences. that is what the offsets are for!
See http://www.imagemagick.org/Usage/anim_m ... e_relative
Anthony,

Good information about repositioning that I did not know. Learn something new today.

However, for IM 7 it might be nice to allow the use of gravity so that each frame might be centered if desired when they are different sizes.

Fred
viper-2
Posts: 23
Joined: 2011-04-20T10:29:09-07:00
Authentication code: 8675308

Re: merging looped animations serially

Post by viper-2 »

I agree that positioning the image from the top left hand corner is strange.This was the reason for using backdrop in my very first post on this problem. The problem I've been having is that there is unexpected behaviour (cropping etc) whenever the image size is larger than the screen resolution.

The use of duplicate at all levels creates an unwieldy animation that's far too memory intensive for a splash screen. I'll have to simplify the animation to minimise the load+play time. I'm about to try a few things suggested by fmw42's solutions, and will post back later.

BTW Fmw42, I came across the amazing Fred's ImageMagickScripts ages ago, and had no idea that fmw42 was Fred!

agt

Freedom - no pane, all gaiGN!

Code Art Now
http://codeartnow.com
Email: agt@codeartnow.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: merging looped animations serially

Post by fmw42 »

see -page and -repage for positioning at http://www.imagemagick.org/Usage/anim_basics/

also see frame optimizations to make your animation smaller at http://www.imagemagick.org/Usage/anim_opt/
viper-2
Posts: 23
Joined: 2011-04-20T10:29:09-07:00
Authentication code: 8675308

Re: merging looped animations serially

Post by viper-2 »

fmw42 wrote:see -page and -repage for positioning at http://www.imagemagick.org/Usage/anim_basics/

also see frame optimizations to make your animation smaller at http://www.imagemagick.org/Usage/anim_opt/
Yes, I saw those pages a few days ago. I'll be spending sometime there as well as with Fred's ImageMagickScripts ( :))to learn more about IM.

I've uploaded iris3.gif to the same webpage:
<http://www.codeartnow.com/code/download ... -2-preview>

This simplifies the animation so I don't use too many duplicates; loading is dramatically faster:

convert \
\( -delay 300 iris0-900.png iris1-720.png \) \
\( -delay 30 iris0-576.png iris1-576.png -duplicate 2,0--1 \) \
-loop 1 iris3.gif

and I play iris3.gif using:

:~$ animate -title "C-Graph" -pause 3 iris3.gif

Your code for iris2.gif worked nicley with the -gravity center setting. I can see how you were trying to use the white background to compensate for my transparency issues and the chequered pattern. I prefer the stacked images to the white background, though. I'll experiment how to use -gravity center without extent. Right now, -gravity center has no effect when inserted in the code above.

agt

Freedom - no pane, all gaiGN!

Code Art Now
http://codeartnow.com
Email: agt@codeartnow.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: merging looped animations serially

Post by fmw42 »

-gravity does not affect animations. that is why you need to use -page or -repage. it worked for me because I filled out each image to the same size using -extent which is sensitive to -gravity
viper-2
Posts: 23
Joined: 2011-04-20T10:29:09-07:00
Authentication code: 8675308

Re: merging looped animations serially

Post by viper-2 »

fmw42 wrote:-gravity does not affect animations. that is why you need to use -page or -repage. it worked for me because I filled out each image to the same size using -extent which is sensitive to -gravity
Fred,

I've discovered that the -gravity switch is relevant only to options that use -geometry. C-Graph users will have different screen sizes and resolutions, so page and repage will be less useful in arriving at a general solution. I've decided to call it a day with the splash image. It's time to get some much needed rest.

Many thanks to you and Anthony for pointing out:

a) that one uses animate to play animations and not display,
b) that -duplicate and not -loop is the option needed to replay the images at each resolution.

Without your help, I could have spent ages experimenting. So to express my appreciation, I'll be mentioning you in the THANKS file for C-Graph, and I'll let you know when the package is released.

Kudos to ImageMagick, and Happy hacking!

agt

Freedom - no pane, all gaiGN!

Code Art Now
http://codeartnow.com
Email: agt@codeartnow.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: merging looped animations serially

Post by fmw42 »

That was why I suggested to Anthony above that

"However, for IM 7 it might be nice to allow the use of gravity so that each frame might be centered if desired when they are different sizes."

But I know that -gravity and -page do not mix. So it would be nice if there was some way to set the virtual canvas in some special way so that something like -page center would be possible. It is useful not only for animations but also for many -layer methods. Only -composite allows -gravity and -geometry at the moment.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: merging looped animations serially

Post by anthony »

viper-2 wrote:The use of duplicate at all levels creates an unwieldy animation that's far too memory intensive for a splash screen. I'll have to simplify the animation to minimise the load+play time. I'm about to try a few things suggested by fmw42's solutions, and will post back later.
How much control do you have over the drop screen? Can you modify the program, or monitor and change things when a specific animation ends?

For example. As a proof of concept I created a script that fades from one image to a another image.
http://www.imagemagick.org/Usage/script ... show_morph

The sequence is not fixed. The program selects the new image to display, creates a 'fade crossover' animation, then asks 'animate' to run that animation once. When the animation is complete it then replaces that animation with a new animation of just the new static image, until it is time to select the next image to fade to.

Essentually it is a wrapper that monitors and controls a "animate" sub-process. A technique known as 'co-processing'.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply