How to Set FFmpeg Subpixel Motion Estimation with -subq

This article explains how to use the -subq (subpixel quality) parameter in FFmpeg to control the subpixel motion estimation quality level during video encoding. You will learn what this parameter does, how its values affect both compression efficiency and encoding speed, and how to implement it in your command-line workflows for x264 and x265 encoders.

What is -subq?

The -subq option (also known as subme in raw x264/x265 library terms) controls the sub-pixel motion estimation complexity. Motion estimation allows video encoders to find matches between frames to compress video. By looking at fractions of a pixel (subpixels), the encoder can find much more accurate matches, which significantly improves compression efficiency and video quality at the cost of processing power.

Choosing the Right -subq Level

The value you pass to -subq is an integer, typically ranging from 0 to 11 for x264 (though 0 to 10 are the most commonly utilized levels). Lower numbers prioritize encoding speed, while higher numbers prioritize video quality and file size optimization.

Here is a breakdown of the standard quality levels:

  • 0 (Fullpixel only): No subpixel refinement is done. This is extremely fast but results in very poor compression and low visual quality.
  • 1 (QPel SAD): Quarter-pixel dispersion with Sum of Absolute Differences. Fast but low quality.
  • 2 (QPel SATD): Quarter-pixel with Sum of Absolute Transformed Differences.
  • 3 to 5: Progressively older and faster methods of half-pixel and quarter-pixel refinements.
  • 6 (RD on I/P frames): Enables Rate-Distortion (RD) optimization for I and P frames. This is the default setting for most presets and offers a good balance of speed and quality.
  • 7 (RD on all frames): Enables Rate-Distortion optimization for all frame types (including B-frames).
  • 8 (RD refinement on I/P frames): Activates rate-distortion refinement on I and P frames.
  • 9 (RD refinement on all frames): Activates rate-distortion refinement on all frames.
  • 10 (QP-RD): Uses Rate-Distortion Optimization for both decisions and motion estimation. This is the slowest setting but produces the highest quality per bitrate.
  • 11 (Full RD): Extreme refinement. Rarely used due to diminishing quality returns relative to the massive increase in encoding time.

FFmpeg Command Examples

To apply -subq in your FFmpeg command, insert the flag followed by your desired integer value.

High-Quality Encoding Example

To encode a video with high-quality subpixel motion estimation (level 9) using the libx264 library:

ffmpeg -i input.mp4 -c:v libx264 -subq 9 -crf 23 output.mp4

High-Speed Encoding Example

If you need to encode a video quickly (e.g., for live streaming) and can sacrifice some compression efficiency, use a lower level like 2:

ffmpeg -i input.mp4 -c:v libx264 -subq 2 -crf 23 output.mp4

Using x264-params

Alternatively, you can set this parameter directly inside the encoder-specific options using the subme key:

ffmpeg -i input.mp4 -c:v libx264 -x264-params subme=7 -crf 23 output.mp4