Speed up Image Manipulation if only 2% affected

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
marcnrw2
Posts: 9
Joined: 2012-01-24T16:03:55-07:00
Authentication code: 8675308

Speed up Image Manipulation if only 2% affected

Post by marcnrw2 »

Hello!

I have an internet project which creates videos on the fly with individual inputs like images which are displayed in the video. Until now I realized this basing on flash technology because I could do a lot of video manipulation on client side. But now I need a h.264 solution what means that I must render and encode a 60 seconds clip (25 fps, 640x360) in less than 2 seconds on server side. The sources for the video are 1,500 images (jpg or else). One image for every frame. It is a question of less than a second to encode this 1,500 images with IM into a h.264 video clip (wow!). The perfomance issue is elsewhere: I have to manipulate this 1,500 images before I can encode them to the video. And I couldn't find a solution which is fast enough. The fastest was 50 seconds. But it must be MUCH faster! The point is that the special way of image manipulation I need in my imagination does not really need a complete new image rendering but obviously IM does it anyway. For every single image I need to paste a small image onto it to a given x,y coordinates. The image size and the coordinates are different for every small image which must be pasted to the large images each but this parameters are always the same for every process of rendering the 1,500 source images. (I mean, if i.e. the small image is 80x62 and must be paste with the left top edge to x=112, y=80 on source image number 423, then in every other video generation process the small image is sized and positioned all the same to source image number 423. The only difference is what the small image shows)
So, only about 2% of the image surface is changed in every source image but IM obviously renders also the other 98%. Does anyone has an idea or knows a trick how to render only the necessary part of the source images which is changed? I also tried to paste together the source image with a transparent area with another same sized image where the small image is overlaying the transparent area of the source image (composite -compose In) trusting that IM quit rendering all other area than the transparent one but obvioulsy it renders the complete image.
Or is the problem not in the rendering process but in the way of sequential batch processing in a loop? All source and target images are stored in a RAM disk so there cannot be a problem with i/o access timing.

Best regards from Germany
Marc
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Speed up Image Manipulation if only 2% affected

Post by whugemann »

I did not read all of your text in depth (it's very long and dense), but a possible solution might be to use jpegtran to exchange full JPEG blocks in the original JPEGs. Which would of course mean that the dimension of the subimages must be a multiple of 8.
Wolfgang Hugemann
marcnrw2
Posts: 9
Joined: 2012-01-24T16:03:55-07:00
Authentication code: 8675308

Re: Speed up Image Manipulation if only 2% affected

Post by marcnrw2 »

Hi Wolfgang!

That sounds interesting! Sounds to be nearly the exact answer to my long question. :-) I am just a bit surprised that this way of block-wise changeout works with jpg. I would have awaited that this method would best work for uncompressed file formats to save the decompression time (and the compression time after changing out the defined block).
May be there is a similar tool for uncompressed formats? So, may be, I do not need to match the multiple 8 condition?

Marc
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Speed up Image Manipulation if only 2% affected

Post by anthony »

See JPEGhack page by Nemo Thorx
http://wiki.thorx.net/wiki/JPEGhack
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply