How to Use Multiple CPU Cores with FFmpeg on macOS
This article explains how to configure and run FFmpeg commands on macOS to utilize multiple CPU cores for faster video and audio encoding. You will learn how to use the default multi-threading settings, force specific core usage using the threads flag, and leverage macOS-specific hardware acceleration for maximum performance on both Intel and Apple Silicon (M1/M2/M3) Macs.
Default Multi-Threading in FFmpeg
By default, FFmpeg is designed to automatically detect your CPU
architecture and use the optimal number of threads for the codec you are
using. To ensure FFmpeg is utilizing all available cores automatically,
you can use the -threads 0 option.
ffmpeg -i input.mp4 -c:v libx264 -threads 0 output.mp4In this command, -threads 0 tells the encoder to
automatically spawn the optimal number of threads based on your
processor’s logical cores.
Forcing a Specific Number of CPU Cores
If you want to limit FFmpeg to a specific number of cores (for
example, to keep your Mac from lagging while multitasking), or if you
want to force it to use all of them, you can replace 0 with
a specific number.
To find out how many CPU cores your macOS system has, run this command in your Terminal:
sysctl -n hw.ncpuOnce you know your core count, you can specify the exact number of threads in your FFmpeg command. For an 8-core CPU, use:
ffmpeg -i input.mp4 -c:v libx264 -threads 8 output.mp4Optimizing Codec-Specific Multi-Threading
Some encoders require additional parameters to fully utilize multiple CPU cores.
H.264 (libx264) and H.265 (libx265)
For CPU-based encoding using the popular libx264 or
libx265 codecs, you can combine the -threads
flag with the -preset option. Faster presets distribute
work across cores more quickly, while slower presets use cores for
deeper compression analysis.
ffmpeg -i input.mp4 -c:v libx265 -preset heavy -threads 0 output.mp4For libx264, you can also explicitly define the thread
pool in the encoder arguments:
ffmpeg -i input.mp4 -c:v libx264 -x264-params pools=8 output.mp4Leveraging Apple Hardware Acceleration (VideoToolbox)
While software encoding utilizes the CPU cores, macOS users can achieve significantly faster encoding speeds by offloading the task to the GPU and dedicated media engines using Apple’s VideoToolbox framework. This utilizes the hardware acceleration cores on M1, M2, M3, and Intel chips.
For H.264 encoding:
ffmpeg -i input.mp4 -c:v h264_videotoolbox output.mp4For HEVC/H.265 encoding:
ffmpeg -i input.mp4 -c:v hevc_videotoolbox output.mp4Using VideoToolbox bypasses standard CPU thread limitations, resulting in faster processing times and lower CPU temperatures on macOS.