This kind of builds on chepner's and choroba's answers but also addresses how you get 18,000,000 images generated using all your CPU's cores. I benchmarked 3 different methods on a decent spec iMac and achieved the following results - starting with the simplest and slowest and going from there to faster methods...
Method 1 - Plain Sequential bash script
#!/bin/bash
for ((i=0; i<18000000; i++ )); do
f=$(( i % 50 ))
s=$(( (i/50) % 60 ))
m=$(( (i/(50*60)) % 60 ))
h=$(( (i/(50*60*60)) ))
convert -size 780x100 xc:#d3fff5ff -font Courier -pointsize 100 -fill black -draw "text 20,80 '$(printf "%03d:%02d:%02d.%02d" $h $m $s $f)'" $i.png
done
This takes around 4.6 days to generate 18 million images.
Method 2 - GNU Parallel script
#!/bin/bash
# Define a function for GNU Parallel to run
doit() {
i=$1
f=$(( i % 50 ))
s=$(( (i/50) % 60 ))
m=$(( (i/(50*60)) % 60 ))
h=$(( (i/(50*60*60)) ))
convert -size 780x100 xc:#d3fff5ff -font Courier -pointsize 100 -fill black -draw "text 20,80 '$(printf "%03d:%02d:%02d.%02d" $h $m $s $f)'" $i.png
}
# Export doit() function so GNU Parallel knows about it
export -f doit
ulimit -S -n 2048
for ((i=0;i<=18000000;i++)); do
echo $i
done | parallel -k doit {1}
This keeps all your CPU cores busy and takes around 32 hours to generate 18 million files. I think it's a pretty good compromise compared to having to write code and compile and build it as in the next answer.
Method 3 - Magick++ program running 8 copies in parallel
#include <Magick++.h>
using namespace std;
using namespace Magick;
int main(int argc, char* argv[]){
// Pick up parameters
if(argc!=3){
printf("ERROR: Please supply 2 arguments - start and end number\n");
exit(EXIT_FAILURE);
}
int start=atoi(argv[1]);
int end =atoi(argv[2]);
InitializeMagick(*argv);
// Create a basic template
Image img(Geometry(780,100),Color("#d3fff5ff"));
img.font("Courier");
img.fillColor(Color("black"));
img.fontPointsize(100);
// Get cycling through the images
for(int i=start;i<=end;i++){
// Work out timestamp for this frame
int f=i % 50;
int s=(i/50) % 60;
int m=(i/(50*60)) % 60;
int h=(i/(50*60*60));
char timestamp[100];
sprintf(timestamp,"%03d:%02d:%02d.%02d",h,m,s,f);
// Copy the basic template image
Image thisframe=img;
thisframe.draw(Magick::DrawableText(20,80,timestamp));
char filename[100];
sprintf(filename,"%d.gif",i);
thisframe.write(filename);
}
}
Here is how you run 8 copies in parallel:
#!/bin/bash
./main 1 2250000 &
./main 2250001 4500000 &
./main 4500001 6750000 &
./main 6750001 9000000 &
./main 9000001 11250000 &
./main 11250001 13500000 &
./main 13500001 15750000 &
./main 15750001 18000000 &
wait
This takes just under 9 hours to generate the 18 million files.
18000000.png = 99:59:59.49