Although this question is already considered answered, I believe it lacks an answer that doesn't involve tuning the command parameters and yet can be used with other tools or commands and not just FFmpeg.
The CPUlimit tool is designed exactly for this purpose and will effectively work not just for FFmpeg but also for any other CPU intensive process you want to reduce this resource utilization.
The most important argument of CPUlimit is -l
, which allows you to specify the CPU percentage the process will be allowed to use (as its top limit).
Please, also observe that this limit depends on the number of CPUs/Cores/Threads the machine has, for example, if the machine has 8 CPUs, CPULimit -l
valid values will range from 0 to 800 (0 being useless, of course, and 800 meaning not limiting the process at all as 800% means all the machine processing capacity).
Example for using half the capacity for an 8 CPUs machine:
cpulimit -l 400 ffmpeg ...
Hope this helps for this specific question as well as similar needs in the future.
Update: 2020/04/19
The original CPUlimit project seems to have moved to github and is now being maintained by user denji
here. I'm leaving the original link because the new project must be compiled and does not offer a binary download.
Also, regarding the original question, if you're trying to limit a bash script (or anything that forks a child process) make sure to add the option -i
or --include-children
and specify the location of the script if it's not in PATH.
Example update:
cpulimit -l 400 -i ./script.sh