title: Start n sub-processes in bash and wait till everything is finished
body: <p>I'd like to test out several ffmpeg settings and run multiple commands as 'sub-processes'. I would not like to launch more than 4 processes at a time, though. What is a good way to do this? Maybe something like trapping the process id's before running the process in the bg and waiting till they're no longer in the process list? or xargs?</p>
  
  <p>Here's the script with no 'queuing':</p>
  
  <pre><code>#!/bin/bash
  
  for crf in 10 15 20 23 25 30 35 ; do
      for vid_preset in medium slow veryslow; do
          ffmpeg -r 25 -i pics/pic_%04d.png -vcodec libx264 -crf $crf -vpre $vid_preset anim_crf$crf\_$vid_preset.mp4
      done
  done
  </code></pre>