Page 1 of 1

GIF animation frames in wrong order

Posted: 2012-01-20T11:11:36-07:00
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

Re: GIF animation frames in wrong order

Posted: 2012-01-20T11:53:03-07:00
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?

Re: GIF animation frames in wrong order

Posted: 2012-01-20T12:51:19-07:00
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.

Re: GIF animation frames in wrong order

Posted: 2012-01-20T16:42:44-07:00
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

Re: GIF animation frames in wrong order

Posted: 2012-01-21T13:50:36-07:00
by Demian
Pardon the hassle. It was a problem with the image naming. Everything works properly now.

Re: GIF animation frames in wrong order

Posted: 2012-01-21T14:54:09-07:00
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?

Re: GIF animation frames in wrong order

Posted: 2012-01-22T02:38:31-07:00
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.

Re: GIF animation frames in wrong order

Posted: 2012-01-22T12:47:54-07:00
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.

Re: GIF animation frames in wrong order

Posted: 2012-01-22T20:15:26-07:00
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.