FFmpeg is using more threads than I expect when using -threads
<p>The number of actual threads used by FFmpeg do not line up with the number I pass using the <code>-threads</code> argument.</p>

<p>I've run tests on both my MacBook Air, which has 4 cores, and a VM I have which has 2 cores. The number of threads used are consistent across both machines.</p>

<p>Using a single thread returns what I would expect: 1 thread is used.</p>

<pre><code>$ ffmpeg -threads 1 -i clip.mp4 -threads 1 -acodec libfdk_aac -vcodec libx264 -b:v 200k -vf scale=200:-2 -y clip-200.mp4

$ cat /proc/$(pgrep ffmpeg)/status | grep Threads
Threads:        1
</code></pre>

<p>If I set the <code>-threads</code> option on the input, it increase the number of threads used to 3. This somewhat makes sense to me since the input would use 2 threads and the output would use a single thread.</p>

<pre><code>$ ffmpeg -threads 2 -i clip.mp4 -threads 1 -acodec libfdk_aac -vcodec libx264 -b:v 200k -vf scale=200:-2 -y clip-200.mp4

$ cat /proc/$(pgrep ffmpeg)/status | grep Threads
Threads:        3
</code></pre>

<p>This is where I start to get confused. If instead, I leave the input <code>-threads</code> at 1 and set the output <code>-threads</code> to 2, it uses 8 threads (not 3 like I would expect).</p>

<pre><code>$ ffmpeg -threads 1 -i clip.mp4 -threads 2 -acodec libfdk_aac -vcodec libx264 -b:v 200k -vf scale=200:-2 -y clip-200.mp4

cat /proc/$(pgrep ffmpeg)/status | grep Threads
Threads:        8
</code></pre>

<p>If I add a second output with <code>-threads 1</code>, it does not increase the number of threads used.</p>

<pre><code>$ ffmpeg -threads 1 -i clip.mp4 -threads 2 -acodec libfdk_aac -vcodec libx264 -b:v 200k -vf scale=200:-2 -y clip-200.mp4 \
                                -threads 1 -acodec libfdk_aac -vcodec libx264 -b:v 250k -vf scale=250:-2 -y clip-250.mp4

cat /proc/$(pgrep ffmpeg)/status | grep Threads
Threads:        8
</code></pre>

<p>However, if the second output also specifies two threads, the thread count jumps to 15.</p>

<pre><code>$ ffmpeg -threads 1 -i clip.mp4 -threads 2 -acodec libfdk_aac -vcodec libx264 -b:v 200k -vf scale=200:-2 -y clip-200.mp4 \
                                -threads 2 -acodec libfdk_aac -vcodec libx264 -b:v 250k -vf scale=250:-2 -y clip-250.mp4

cat /proc/$(pgrep ffmpeg)/status | grep Threads
Threads:        15
</code></pre>

<p>Every incremental bump beyond <code>-threads 2</code> will use an additional 3 threads (e.g. <code>threads 2</code> uses 8, <code>threads 3</code> uses 11, <code>threads 4</code> uses 14.</p>

<p>So it seems like anytime you use <code>-threads 2</code> the formula is something like:</p>

<pre><code>1 + [ (1 + (3 * output_n_threads)) + ... ]
</code></pre>

<p>Ultimately my question is why do the number of actual threads used wildly differ from the options I'm specifying.</p>

<p>Thanks.</p>