Trimming animation

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
amlamlaml
Posts: 1
Joined: 2011-12-07T05:45:39-07:00
Authentication code: 8675308

Trimming animation

Post by amlamlaml »

Hi,

I made an animation from a sequence of PNG images. So far, so good.
Now, I would like to automatically trim the animation just like we do
when we trim images but I need all images to preserve their relative
position. AFAICS, this means that I have to compute a minimal
bounding box that includes all the relevant pixels from all images
and then I should use that bounding box to trim each image.

My first attempt was this:

convert frame-*.png -trim -layers TrimBounds -coalesce +repage film.pdf

The result is not what I want because it looks like each image was
trimmed independently. As a result, if the next image is smaller
than the previous one, we still see fragments of the previous one.

I managed to "solve" the problem by taking advantage of the fact
that the trimmed areas are black:

convert frame-*.png -background Black -layers TrimBounds -dispose Background -trim +repage film.pdf

However, this is not a general solution and, moreover, it sometimes
show some artifacts, such as very thin lines that appear and disappear
during the animation.

So, my question is: how can I trim an animation?

Thanks a lot,
António.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trimming animation

Post by fmw42 »

You might try to merge all the frames into one by averaging them (-evaluate sequence mean) or compositing them if they have transparency. Then calculate the bounding box you need or just do -trim and get the geometry size and offset from the verbose information. Any way you can decide on the bounding box is fine. Then

see
http://www.imagemagick.org/Usage/anim_m ... p_viewport
or
http://www.imagemagick.org/Usage/anim_mods/#trim

also in general see
http://www.imagemagick.org/Usage/anim_opt/
http://www.imagemagick.org/Usage/anim_mods/
Post Reply