Configure FFmpeg Thread Type Frame or Slice
This article explains how to configure the thread type to frame-level or slice-level in FFmpeg to optimize video encoding and decoding performance. You will learn the differences between these two threading methods, how they impact latency and CPU utilization, and the exact command-line arguments needed to implement them in your video processing workflows.
Understanding FFmpeg Thread Types
FFmpeg allows you to control how multi-threading is handled during
video decoding and encoding using the -thread_type option.
Choosing the correct thread type helps balance processing speed and
latency.
There are two primary threading types:
- Frame-level threading (
frame): Decodes or encodes multiple frames in parallel. This method offers the highest throughput and CPU utilization but introduces latency, as several frames must be buffered before outputting. - Slice-level threading (
slice): Divides a single frame into multiple horizontal chunks (slices) and processes them simultaneously. This method offers the lowest latency because frames are processed and outputted one by one, though it may be slightly less CPU-efficient than frame-level threading.
How to Configure the Thread Type
You can configure the thread type using the -thread_type
flag in your FFmpeg command. This option accepts three values:
frame, slice, or frame+slice.
1. Enable Frame-Level Threading
To prioritize maximum throughput and resource utilization when
latency is not an issue (such as offline file conversion), set the
thread type to frame:
ffmpeg -thread_type frame -i input.mp4 -c:v libx264 output.mp42. Enable Slice-Level Threading
To prioritize low latency (ideal for live streaming or real-time
playback), set the thread type to slice:
ffmpeg -thread_type slice -i input.mp4 -c:v libx264 output.mp43. Enable Both Threading Types
You can allow FFmpeg to use both frame-level and slice-level
threading concurrently by combining them with a + symbol.
This is useful for high-resolution video processing on systems with many
CPU cores:
ffmpeg -thread_type frame+slice -i input.mp4 -c:v libx264 output.mp4Setting the Thread Count
To make the most of your -thread_type configuration, you
should also specify the number of threads FFmpeg is allowed to use by
adding the -threads option.
For example, to use slice-level threading restricted to 4 threads:
ffmpeg -thread_type slice -threads 4 -i input.mp4 -c:v libx264 output.mp4If you set -threads 0, FFmpeg will automatically choose
the optimal number of threads based on your system’s CPU core count.