Skip to content
Advertisement

Bash – Insert number variables into command

I’ve been wanting to have a count-up timer overlaying a video but all I could find online for doing so was using Adobe After Effects which isn’t really an option as I’m on Linux and am unwilling to pay for it.

So, if I could get a series of images or a video, then it could be imported into Openshot to overlay a video quite nicely, but it’s been a struggle getting said series of images or video.

I’ve started work on a script to make the series of images but have no idea how to place variables into the command. Here’s the script in its current form:

JavaScript

What I would like is for 0.png to essentially be $i.png, so it increments up to 18,000,000. The time (shown as 000:00:00.00) I could probably work out for myself after knowing how to insert variables into commands. The time format is hours, minutes, seconds and frames.

Here’s an example for if I’ve poorly explained things (sorry for the spacing – only double new lines only work on here for some reason):

0.png = 000:00:00.00

1.png = 000:00:00.01

49.png = 000:00:00.49

50.png = 000:00:01.00

51.png = 000:00:01.01

18000000.png = 100:00:00.00

Advertisement

Answer

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

JavaScript

This takes around 4.6 days to generate 18 million images.

Method 2 – GNU Parallel script

JavaScript

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

JavaScript

Here is how you run 8 copies in parallel:

JavaScript

This takes just under 9 hours to generate the 18 million files.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement