GIF to frames omits repeated frames

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
corey
Posts: 3
Joined: 2011-09-19T12:25:56-07:00
Authentication code: 8675308

GIF to frames omits repeated frames

Post by corey »

Hello. I am creating an image slideshow with version 6.7.2-6 for Windows. My questions are in bold. Thanks for reading.

I am starting with a bunch of JPGs and combining them into a large ( 20 meg GIF, 75 meg MIFF ) file using this at the command line:

Code: Select all

convert.exe ( -delay 999 image001.jpg ) ( -delay 0 -morph 4 image001.jpg image002.jpg ) ( -delay 999 image002.jpg ) ( -delay 0 -morph 4 image002.jpg image003.jpg ) ( -delay 999 image003.jpg ) ( -delay 0 -morph 4 image003.jpg image004.jpg ) ( -delay 999 image004.jpg ) ( -delay 0 -morph 4 image004.jpg image005.jpg ) ( -delay 999 image005.jpg ) ( -delay 0 -morph 4 image005.jpg image006.jpg ) ( -delay 999 image006.jpg ) ( -delay 0 -morph 4 image006.jpg image007.jpg ) ( -delay 999 image007.jpg ) ( -delay 0 -morph 4 image007.jpg image008.jpg ) ( -delay 999 image008.jpg ) ( -delay 0 -morph 4 image008.jpg image009.jpg ) ( -delay 999 image009.jpg ) ( -delay 0 -morph 4 image009.jpg image010.jpg ) ( -delay 999 image010.jpg ) -coalesce -quality 100 result.miff
This shows each image for 10 seconds before a morph transition to the next image. The result is nice, but I want to end up with a movie format like AVI. I learned elsewhere on this forum I should extract the frames to separate image files and use ffmpeg to do so. My problem is this next command creates about 60 PNG images, and my 10 second delays are reduced to the same number of frames as the -morph 4 transitions.

Code: Select all

convert.exe  result.miff -resize 640x480 -quality 100 -coalesce result%%05d.png
The 10 second delay on each photo is lost, but the transitions are intact. How can I make sure no frame will be lost when converting the MIFF to PNG? I thought -coalesce would do it, but this does not seem to be the case.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: GIF to frames omits repeated frames

Post by anthony »

Only GIF and MIFF formats (that I know of) can use variable delays between frames.
Most video formats use a fixed delay between frames, or a constant frame-rate.
As such the solution is to simply repeat your 'constant frames' as many times as it is nessary.

NOTE the later versions of IM has a image sequence operation, -duplicate
http://www.imagemagick.org/Usage/basics/#duplicate

that will let you repeat a single, or multiple frames N times, appending them to the current sequence. It is very efficient due to internal data sharing.

If you have an older version of IM you can also use -morph to generate extra copies of images, however it will not do data sharing so will use up a lot of memory very quickly.

When generating videos, outputting a stream of images (generally PPM format) in a pipeline to your video generating command will often be much more efficient as you only need to hold the images you are currently processing in memory, rather than the whole sequence.

EG: this is using shell to generate a sequence of images, and is an example only...

Code: Select all

( convert image1.png  image2.png -morph 20 +delete ppm:-
  convert image2.png -duplicate 99 ppm:-
  convert image2.png image3.png -morph 20 +delete ppm:-
  convert image3.png -duplicate 99 ppm:-
  # ... and so on ...
) | ffmpeg -f image2pipe -vcodec jpeg output.mpg
Note it is possible to output a image stream with minimal memory requirements all in one command by the appropriate use of -write and -delete operations.
http://www.imagemagick.org/Usage/files/#write
http://www.imagemagick.org/Usage/basics/#delete

I envisage doing this type of thing would be much more common in the new IMv7 scripting and co-processing which I am about to start work on.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
corey
Posts: 3
Joined: 2011-09-19T12:25:56-07:00
Authentication code: 8675308

Re: GIF to frames omits repeated frames

Post by corey »

Anthony:

Thanks for the reply. I have some learning to do to catch up to what you're suggesting, here. I appreciate the time you've put forth to help me.
corey
Posts: 3
Joined: 2011-09-19T12:25:56-07:00
Authentication code: 8675308

Re: GIF to frames omits repeated frames

Post by corey »

I should have mentioned that I avoided using pipes because this is happening on a Windows machine, and I'm not sure how that works.
Post Reply