I have a very simple script, that will remux all files in all subfolders to mkv
#!/bin/bash
# Works with subfolders too
shopt -s nullglob
shopt -s extglob
shopt -s nocaseglob
shopt -s globstar
for file in "${1%/}/"**/*(*.mp4|*.avi); do
mkvmerge -v -M -B --no-chapters --disable-language-ietf --engage no_cue_duration --engage no_cue_relative_position --clusters-in-meta-seek --disable-lacing --engage no_simpleblocks "$file" -o "${file%.*}".mkv &
done
How can I limit the background jobs to batches of 300 ? Meaning I'd like to run this command in batches of 300 files, and wait for them to finish/wait X time and start a new batch