Page 1 of 1

Trimming animation

Posted: 2011-12-07T06:03:35-07:00
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.

Re: Trimming animation

Posted: 2011-12-07T10:31:48-07:00
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/