creating an animGIF with 30 FPS?

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
cbuchner1
Posts: 2
Joined: 2015-01-15T06:23:36-07:00
Authentication code: 6789

creating an animGIF with 30 FPS?

Post by cbuchner1 »

Hi,

I was trying to create an animated GIF at 30 FPS, so playout is mostly synchronized with the typical LCD refresh rate of 60 Hz.

convert.exe -delay 1x30 -loop 0 image%03d.pgm[0-1199] image.gif

GIF specifies the delay between frames in 1/100th's of a second. So I find that the generated 1200 frame animation replays at faster frame rates because the delay it introduces between frames is always 3/100ths of a second, resulting in 33.33 FPS

Is there a way to accomplish that ImageMagick uses 4/100ths and 2x 3/100ths seconds delay for each three consecutive frames, so that the average delay becomes 33.333ms and I do get 30 FPS exactly?

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

Re: creating an animGIF with 30 FPS?

Post by fmw42 »

I believe this is correct, though not 100% sure. delay=1 is 1/100 sec per frame. So delay=100 = 1 sec per frame. So delay= 100/30 = 1sec/30frame. So you need a delay of 3.33 (100/30) to achieve 30f/sec.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: creating an animGIF with 30 FPS?

Post by fmw42 »

P.S. if IM does not like fractional delays such as

-delay 3.33 (-delay 3.33,100)

then you can scale the delay and tics per second, such as

-delay 33,1000

0r

-delay 333,10000
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: creating an animGIF with 30 FPS?

Post by snibgo »

From http://www.imagemagick.org/Usage/anim_basics/ :
GIF animation delays must be specified in hundredths of a second for correct working, which is why that is the default time unit.
It seems the metadata is stored in units of 1/100s, so "-delay 33x1000" etc will result in 3/100.
cbuchner1 wrote:Is there a way to accomplish that ImageMagick uses 4/100ths and 2x 3/100ths seconds delay for each three consecutive frames, so that the average delay becomes 33.333ms and I do get 30 FPS exactly?
Sure. Just list the frames with a "-delay" between them, eg:

Code: Select all

f:\web\im>%IM%convert -size 100x100 -delay 4 xc: -delay 3 xc: xc: x.gif

f:\web\im>%IM%identify -verbose x.gif |cgrep /i- /o- /sDelay
  Delay: 4x100
  Delay: 3x100
  Delay: 3x100
In practice, you could build the command in a script, reading each frame from one animated gif, writing to another gif.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: creating an animGIF with 30 FPS?

Post by fmw42 »

snibgo wrote:GIF animation delays must be specified in hundredths of a second for correct working, which is why that is the default time unit.
Thanks, snibgo, for posting that. I had never knew that before. I see it now in the reference link you provided. I was only looking at -delay from the options page information.

Learned something new today!

I assume tics must be integers. Do you know if that is true?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: creating an animGIF with 30 FPS?

Post by snibgo »

I haven't looked at the GIF spec or IM's code, but playing with commands like ...

Code: Select all

convert -delay 3.6 -size 100x100 xc: -duplicate 100 x.gif
convert -delay 36x1000 -size 100x100 xc: -duplicate 100 x.gif
... I find the delay parameter is always rounded to an integer number of hundredths.
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: creating an animGIF with 30 FPS?

Post by glennrp »

Actually it's truncated to an integer. -delay 1x30 and -delay 39x1000 both write a GIF with delay 3, while -delay 40x1000 writes delay 4.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: creating an animGIF with 30 FPS?

Post by snibgo »

True, "-delay 39x1000" becomes 3*. But (in v6.9.0-0) "3.9" becomes 4.

*EDIT: I wrote "4" but meant "3".
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: creating an animGIF with 30 FPS?

Post by glennrp »

Right. The components of 39x1000 are rounded in constitute.c to 39 x1000, and 3.9 is rounded to 4 Then in gif.c the
integer calculation of 100*39/1000 yields 3 while the integer calculation of 100*4/100 yields 4.
cbuchner1
Posts: 2
Joined: 2015-01-15T06:23:36-07:00
Authentication code: 6789

Re: creating an animGIF with 30 FPS?

Post by cbuchner1 »

Wouldn't it make sense to accumulate that rounding error, so that consecutive frames of an animation might use different delay values?
Post Reply