8

I would like to speed up the following command:

convert -limit memory 64 -limit map 128 -antialias -delay 1x2 final/*.png movie.mp4

I have seen other blog posts where parallel and convert were used together so I am wondering how to make it work with the command above.

admdrew
  • 3,790
  • 4
  • 27
  • 39
aeupinhere
  • 2,883
  • 6
  • 31
  • 39
  • I suspect that can't be readily parallelised with GNU Parallel because, in essence, you only have one process (i.e. one `convert`) and GNU Parallel is good at spreading MULTIPLE processes over multiple CPU cores. How many `PNG` files do you have? And how long does it currently take? – Mark Setchell Oct 02 '14 at 20:23
  • @MarkSetchell It currently takes over an hour to process ~100 images that are 10000x8000 pixels. I may try downsampling the images to see if that will speed things up. – aeupinhere Oct 02 '14 at 20:31

1 Answers1

12

If downsizing is an option, yes, you can readily do that with GNU Parallel

parallel -j 8 convert {} -resize ... {} ::: *.png

where {} stands for the filename, and the files to be processed are listed after the :::.

-j gives the number of jobs to run in parallel.

I just created 100 PNGs of 10,000 x 8,000 and resized them to 2,000 x 1,200 sequentially in 8 minutes using

#!/bin/bash
for f in *.png; do
    convert $f -resize 2000x1200! $f
done

then, the same original images again, but with GNU Parallel

parallel convert {} -resize 2000x1200! {} ::: *.png

and it took 3 minutes 40 seconds. Subsequently making those 100 PNGs into a movie took 52 seconds.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Thanks! Does Parallel allow me to name the output the same as the input? This syntax is weird to say the least. – aeupinhere Oct 02 '14 at 21:13
  • You have a choice. You can name output same as input with `convert {} ... {}`, or you can strip and replace extension, with say `.jpg` instead of `.png` if you do `convert {} ... {.}jpg`, or you can write to a new subdirectory with `convert {} ... new/{}` – Mark Setchell Oct 02 '14 at 21:24
  • The performance when using Parallel was roughly about twice as fast as just using a for loop. Thanks again for taking the time to take a look at this for me! – aeupinhere Oct 06 '14 at 17:26