convert (Slow process)

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Locked
emontezuma
Posts: 19
Joined: 2011-09-28T10:17:45-07:00
Authentication code: 8675308

convert (Slow process)

Post by emontezuma »

Hi friends.
I have an application which processes two images and tries to make a fade transition effect, it works very well, but the problem is the performance. I'm running ImageMagick using the CMDMagick.EXE tool. I have a Intel core i5VPro processor and this command takes almost 6 second in construcs 20 images (transition efecct between 2 images).
  • Microsoft Windows [Versión 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. Reservados todos los derechos.

    C:\Users\Elvis>convert -version
    Version: ImageMagick 6.8.4-10 2013-04-13 Q16 http://www.imagemagick.org
    Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
    Features: DPC OpenMP
    Delegates: bzlib fontconfig freetype jng jp2 jpeg lcms lzma pango png ps tiff x xml zlib
This is my command line:

Code: Select all

"...
convert  ( "c:\fondo.jpg" "c:\Act.png" -gravity center -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "2%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=41 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "5%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=43 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "7%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=44 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "10%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=46 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "12%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=47 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "C:\PubliScreen\
Temporal\ImaSig0.png" -crop "15%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=49 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "17%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=50 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "20%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=52 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "22%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=53 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "25%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=55 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "27%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=56 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "C:\Pub
liScreen\Temporal\ImaSig0.png" -crop "30%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=58 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "32%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=59 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "35%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=61 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "37%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=62 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "40%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=64 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "42%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=65 -blur 0X2 ) -composite )  ( -clone 0 -gravity west 
( "c:\Next.png" -crop "45%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=67 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "47%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=68 -blur 0X2 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "50%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=70 -blur 0X1 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "52%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=71 -blur 0X1 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "55%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=73 -blur 0X1 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "57%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=74 -blur 0X1 ) -composite )  ( -clone 0 -grav
ity west ( "c:\Next.png" -crop "60%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=76 -blur 0X1 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "62%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=77 -blur 0X1 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "65%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=79 -blur 0X1 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "67%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=80 -blur 0X1 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "70%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=82 -blur 0X1 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "72%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=83 -blur 0X1 ) -composite )  ( -clon
e 0 -gravity west ( "c:\Next.png" -crop "75%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=85 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "77%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=86 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "80%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=88 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "82%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=89 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "85%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=91 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "87%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=92 ) -composite )  ( -clone 0 -gravity west ( "C:\PubliScreen\Temporal\ImaSig
0.png" -crop "90%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=94 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "92%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=95 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "95%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=97 ) -composite )  ( -clone 0 -gravity west ( "c:\Next.png" -crop "97%x648+0+0" -geometry +140.5+0 -compose dissolve -define compose:args=98 ) -composite )  ( ( "c:\fondo.jpg"  "c:\Next.png" -compose dissolve -define compose:args=100 ) -gravity center -composite )  "c:\IM.jpg"
..."
I tried deleting the dissolve and blur effect, but the saving time is almost 0 second.
Is possible to improve the speed in this command? As you can see, I put all the image generation (20 images) in a sigle command line and it works very good. I tried generate the images separatelly (one command line per image) but it is slower.

I'am a novice imagemagick user. I dont know the technics to impove the speed, if we can save time with special commands or supressing quality in the resultant images or something like that

Best regards,

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert (Slow process)

Post by snibgo »

You are re-reading "c:\Next.png" a huge number of times. You could read it once, and use "-clone" to access it.
snibgo's IM pages: im.snibgo.com

emontezuma
Posts: 19
Joined: 2011-09-28T10:17:45-07:00
Authentication code: 8675308

Re: convert (Slow process)

Post by emontezuma »

Thanks Snigbo.
I'm going to change my command and report you the result.

Best regard,

emontezuma
Posts: 19
Joined: 2011-09-28T10:17:45-07:00
Authentication code: 8675308

Re: convert (Slow process)

Post by emontezuma »

Friends, I have tried anything -clone combinations without good results.

I couldnt refer the second image index in order to refer in my -clone argument.

This is part of the code, which is not worrking properly. The second -clone command is copying the first image and not the second image...

convert ( "c:\image1.png") ( c:\image2.png)
(-clone 0 ( -clone what index? -crop "33%x100+0+0" ) -composite ) //I need to clone the 1st image ("c:\image1.png"), then I copy the 2nd image ("c:\image2.png") and crop it 33%//
(-clone 0 ( -clone what index? -crop "66%x100+0+0" ) -composite ) //I need to clone the 1st image ("c:\image1.png"), then I copy the 2nd image ("c:\image2.png") and crop it 66%//
(-clone 0 ( -clone what index? -crop "100%x100+0+0" ) -composite ) //I need to clone the 1st image ("c:\image1.png"), then I copy the 2nd image ("c:\image2.png") and crop it 100%//
-delete 1
"c:\result.png"


In the second clone command I need to refer the ( "c:\image2.png" ) file but I don't know which index to use. I have put the 0, -1 but those are not working. I have put the index 1 but an error message appears... "no such image '-clone'

I have read in the documetation that when the -clone command is used into parenthesis (recomended) the image index to use is depend the pushed images, what mean pushed image???

Best regards friends...

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert (Slow process)

Post by snibgo »

"-clone {n}" refers to an image in the immediately previous container. For example:

Code: Select all

fileA
fileB
  ( -clone 0  <= refers to fileA
    -clone 1  <= refers to fileB
    ( -clone 0  <= refers to zeroth file in container list, ie previous clone 0, which refers to fileA
      -clone 1  <= refers to oneth file in container list, ie previous clone 1, which refers to fileA
... but ...

Code: Select all

fileA
fileB
  ( -clone 0  <= refers to fileA
    ( -clone 0  <= refers to previous clone 0, which refers to fileA
      -clone 1  <= would refer to previous clone 1, but there isn't one.
snibgo's IM pages: im.snibgo.com

emontezuma
Posts: 19
Joined: 2011-09-28T10:17:45-07:00
Authentication code: 8675308

Re: convert (Slow process)

Post by emontezuma »

Hi Snibgo, you have gave me the key. I need to insert a new clone command into the parenthesis.

Thanks a lot.

emontezuma
Posts: 19
Joined: 2011-09-28T10:17:45-07:00
Authentication code: 8675308

Re: convert (Slow process)

Post by emontezuma »

I have modified my code and I reduce the time in 33% (since 6 to 4 seconds), but I would like to reduce the time much more.

Which part of this code I would need to change in order to reduce the process time?

convert ( "c:\wallpaper.png" ) ( "c:\fadeimg.png" )
( -clone 0 -clone 1 ( -clone 1 ( -gravity west -geometry +178.5+0 -crop "33%x648+0+0" -compose dissolve -define compose:args=20 -blur 0X2 ) ) -delete 1 -composite )
( -clone 0 -clone 1 ( -clone 1 ( -gravity west -geometry +178.5+0 -crop "67%x648+0+0" -compose dissolve -define compose:args=60 -blur 0X2 ) ) -delete 1 -composite )
( -clone 0 -clone 1 ( -clone 1 ( -gravity west -geometry +178.5+0 -crop "100%x648+0+0" -compose dissolve -define compose:args=100 ) ) -delete 1 -composite )
-delete 1 "C:\Result.jpg"

The complete code has 40 similar lines, in thos sample I only wrote 3 lines.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert (Slow process)

Post by snibgo »

You have superfluous brackets, but this should have no significant impact on processing time. Brackets removed (Windows syntax):

Code: Select all

convert ^
wallpaper.png ^
fadeimg.png ^
( -clone 0 -clone 1 ( -clone 1 -gravity west -geometry +178.5+0 -crop "33%%x648+0+0" -compose dissolve -define compose:args=20 -blur 0X2 ) -delete 1 -composite ) ^
( -clone 0 -clone 1 ( -clone 1 -gravity west -geometry +178.5+0 -crop "67%%x648+0+0" -compose dissolve -define compose:args=60 -blur 0X2 ) -delete 1 -composite ) ^
( -clone 0 -clone 1 ( -clone 1 -gravity west -geometry +178.5+0 -crop "100%%x648+0+0" -compose dissolve -define compose:args=100 ) -delete 1 -composite ) ^
-delete 1 "Result.jpg"
I'm unsure what your command is doing. If you can supply the source images, someone might run your command and suggest a faster way to do the same thing.
snibgo's IM pages: im.snibgo.com

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

Re: convert (Slow process)

Post by anthony »

Also the -clone 0 -clone 1 can be merged to become -clone 0,1 or if you just want all image a common syntax is -clone 0--1 ( 0 or first image to -1 or last image)


Also you can NOT use a percent for just one argument for crop. ANY percent character present will be applied to BOTH width hand height arguments!


for any more help. we need source images, OR at least some info on what it is you are trying to do!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

emontezuma
Posts: 19
Joined: 2011-09-28T10:17:45-07:00
Authentication code: 8675308

Re: convert (Slow process)

Post by emontezuma »

Antony, thanks for your support.
My goal is develop a program in VB6 that allow me to make transition effects between 2 images.
1) It constructs the images files with MagickCMD command (slow procees, it has improved from the snigbo tips).
2) The program uses a picture box with a timer control to show all the images and simulate a transition effect.
3) I have 2 problems:
a) The command to generate the images is slow, it takes around 2 or 3 seconds to make 20 images sequence (the minimun number of images to the effect).
b) The picture box also takes so much time to show every picture.

My questions:
1) There are a way to construct with IM MPG or AVi files easily?
2) How can I to improve the time of the images generation? How ca I to reduce the image quality or something like that to save CPU time? Any tricks?

Best regards,

Locked