Convert movie to images - Problem with delay

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
Mike

Convert movie to images - Problem with delay

Post by Mike »

I already posted this into the mailing list. I hope it is no problem that i ask here again, because i have not very much time. But if i get the answer here, i will post it too into the mailing list.
Hello,

i tried to convert a movie to images with following command:

convert -delay 1 Mov.mp4 Mov.tif

But i can set for delay what i want... i get always the same amount of
pictures. What must i do to get for example every second one picture?

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

Re: Convert movie to images - Problem with delay

Post by fmw42 »

I don't believe that -delay is for extracting frames from an
animation. It is for setting the delay between frames when creating
an animation.

You need to find out what frame delay is in the animation/movie.
Assume it is 25 ms, then you have 1000/25=40 frames per second. So
you need to write a script and loop over every frame skipping every
40 frames. That is convert only every 40th frame to an image.

If the frame rate is in ticks, such as 25 tics, then tics are
nominally in 1/100 of second. So 25 tics would be 100/25=4 frames per
second.

There may be more elegant ways, but that is all I can suggest.

To access individual or groups of frames, see http://www.imagemagick.org/Usage/basics/#sequence
but I don't believe it allows a skip factor. So that is why you have to script a loop.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Convert movie to images - Problem with delay

Post by anthony »

-delay basically overrides whatever 'delay' setting is present in the image read in after it. On the other hand -set delay sets the delay for images ready read into memory.

To sample every second frame you would need to delete eveyr second frame.

that is tricky you could read in every second frame
Mov.mp4'[0,2,4,6,8,10,...]'
or you can delete every second frame after reading
Mov.mp4 -delete 1,3,5,7,9,....

But both can get monotonous and you need to know how many frames their are.

An alturnative may be to do some image re-arrangement (needs lots of memory)
using the image size. For example assuming the image is 120x90
convert Mov.mp4 -append -crop 120x180 +repage -crop 120x90+0+0 Mov.avi

this turns the movie into ONE massivally long image, then divides it into half the number of 'two frame' images before trashing the second frame in each image.
It is tricky but it works.

In the future when 'montage' like array handling becomes available in 'convert' you may be able to do this better by handling it only append pairs of images, rather than all the image. (saves a lot of memory copying!)

The BETTER solution however may be an API. for example in perl read in the image, (becomming a perl array of images) then loop though and delete every second image! That would be faster than the above and you don't need to know either the total number of images, or the image size before hand. Nor does it it twice as much memory for the appending and tile cropping.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply