If you are using a Linux distribution which uses systemd, then you can use one if its utilities named systemd-run for resource control. For your case, it would be this:
sudo systemd-run --scope -p AllowedCPUs=VALUE CMD
sudo systemd-run --scope -p CPUQuota=VALUE% CMD
For AllowedCPUs
, you can mention the indice of the logical core to which you want to restrict the execution of your command. Indice is 0 for first logical core, 1 for second logical core, and so on.
For CPUQuota
, 100% equals one logical core's maximum available CPU time. 200% would be two logical cores, and so on.
Example A:
# My stress commands wants to use all 8 logical cores of my machine,
# but systemd would limit it to allowed logical cores 0 and 4.
# I chose 0 and 4 because both belongs to the same physical core.
sudo systemd-run --scope -p AllowedCPUs=0,4 stress -c 8
Example B:
# Here, my stress command despite being hungry for all CPUs would only
get 100% *available* time of one logical core only.
sudo systemd-run --scope CPUQuota=100% stress -c 8
Suggested readings: manual of systemd-run and systemd.resource-control.
-c:a copy
so it also transcodes the audio (using FFmpeg's built-in AAC encoder that's generally lowish-quality last I read), losing quality and costing CPU time. And it uses the libx264 defaults of-preset medium -crf 23
, so the quality per bitrate could be higher if you wanted to spend more CPU time, and you could spend more or less bitrate for more or less quality at similar encode speed. And some content benefits from-tune film
. See trac.ffmpeg.org/wiki/Encode/H.264