GIF animation frames in wrong order

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?".
Post Reply
Demian
Posts: 9
Joined: 2012-01-18T10:00:19-07:00
Authentication code: 8675308

GIF animation frames in wrong order

Post by Demian »

ImageMagick 6.7.4-2
Windows 7
Windows command-line

Here's what I used to create the gif below. I have 180 frames in gif format numbered from 0 to 180. I have no other images in the folder.

-convert -loop 0 -delay 4 *.gif animation.gif

I've tried various -dispose methods but none of them have any effect on the output. This is the resulting gif.

Image

Some of the frames are in the wrong order so it flickers. Below is what it should look like. (Made with another program.)

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: GIF animation frames in wrong order

Post by fmw42 »

It may be how you have your images numbered and how the wild card sorts them. You may need to use numbers will leading zeroes in your filenames. How did you name them?
Demian
Posts: 9
Joined: 2012-01-18T10:00:19-07:00
Authentication code: 8675308

Re: GIF animation frames in wrong order

Post by Demian »

fmw42 wrote:It may be how you have your images numbered and how the wild card sorts them. You may need to use numbers will leading zeroes in your filenames. How did you name them?
001-009
010-090
100-180

There shouldn't be a problem with the names.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: GIF animation frames in wrong order

Post by anthony »

Can you give us an actual listing of the directory?

What order does echo *.gif produce? -- assuming that you are under UNIX.

Compare it to the order in convert *.gif info:

Also try convert '*.gif' info: which will have IM expand the '*' meta-character rather than the shell.


If you are under windows, then IM is always doing the sorting, and IM will sort it 'case-sensitive' where window file systems is NOT case-sensitive. EG: for the files: "a001.jpg" "B002.jpg" ; will put 'B' before the 'a'! As the window file system is not case sensitive you may need to change the file name via a temporary filename
EG: rename B002.jpg tmp.jpg
then rename tmp.jpg b002.jpg
It is a pain but that is the facts, as the file system considers B002.jpg and b002.jpg the same name to it, so will not let you directly rename them, even though to you they are NOT the same name. This happens to me all the time when I deal with VFAT USB sticks, even though I am a UNIX user.

Alternative... Get IM to generate the file names... convert 'image_%03d.gif[0-100]' info:
Here IM itself is generating filenames and requesting them, the filesystem can then ignore any case sensitivity.

For more information on that last method see http://www.imagemagick.org/Usage/files/#read_frames
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Demian
Posts: 9
Joined: 2012-01-18T10:00:19-07:00
Authentication code: 8675308

Re: GIF animation frames in wrong order

Post by Demian »

Pardon the hassle. It was a problem with the image naming. Everything works properly now.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: GIF animation frames in wrong order

Post by fmw42 »

Demian wrote:Pardon the hassle. It was a problem with the image naming. Everything works properly now.

I for one am curious to know how you had misnumbered them?
Demian
Posts: 9
Joined: 2012-01-18T10:00:19-07:00
Authentication code: 8675308

Re: GIF animation frames in wrong order

Post by Demian »

fmw42 wrote:
Demian wrote:Pardon the hassle. It was a problem with the image naming. Everything works properly now.

I for one am curious to know how you had misnumbered them?
Contrary to what I said, I forgot to rename the images with leading zeros. I had the images named like that at one point but I edited the animation and extracted the frames again from the GIF so the names were back to the original format. Once I added the leading zeros the images were read in correct order: 001, 002, 003 and so on.

Without the leading zeros, either Windows or ImageMagick, read the images in the following order: 0, 1, 10, 100, 101 -> 109, 11, 110, 111, 112 and so on.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: GIF animation frames in wrong order

Post by fmw42 »

Without the leading zeros, either Windows or ImageMagick, read the images in the following order: 0, 1, 10, 100, 101 -> 109, 11, 110, 111, 112 and so on.
Yes, that was why I asked about the leading zeroes. Glad you went back to check and that it work fine with leading zeroes. Thanks for letting us know what had happened.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: GIF animation frames in wrong order

Post by anthony »

You can extract the frames with leading zeros using ImageMagick
See Writing Multiple Images
http://www.imagemagick.org/Usage/files/#adjoin

This goes though number formatting as well as provides hints on alternative methods of reading images that do not have those leading zeros.

Also I have a personal script I use to re-name numbered files to either add leading zeros, or set the number of digits needed.
http://www.ict.griffith.edu.au/anthony/ ... /#mv_renum
It can also re-sequence the numbers to either remove 'gaps' set a starting number, or space out the numbers (say going up by an increment of 5 or 10 so you can insert frames in the middle of the sequence. I use it all the time for sorting numbered files.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply