How to Set Minimum QP in FFmpeg
This article explains how to set the minimum Quantization Parameter (QP) value during an FFmpeg video transcoding process. You will learn the specific command-line options for standard encoders like H.264 (libx264) and H.265 (libx265), along with practical examples of how to apply them.
The FFmpeg Option for Minimum QP
To set the minimum QP value in FFmpeg, you can use the global
-qmin option or encoder-specific parameters. The
Quantization Parameter controls the compression level of each
macroblock; a lower QP means lower compression and higher quality, while
a higher QP means higher compression and lower quality. Setting a
minimum QP prevents the encoder from using too much
bitrate on high-quality frames.
1. Using the Global
-qmin Option
For most standard encoders, FFmpeg utilizes the -qmin
flag to define the minimum quantizer scale.
ffmpeg -i input.mp4 -c:v libx264 -qmin 15 output.mp4In this command: * -qmin 15 tells the encoder not to
drop the QP below 15, preventing the video from using excessive bitrate
for near-lossless quality.
2. Encoder-Specific Options (Recommended)
Depending on whether you are transcoding to H.264 or H.265, passing the parameter directly to the encoder library provides the most reliable results.
For H.264 (libx264)
Use the -x264-params flag to set the qpmin
option:
ffmpeg -i input.mp4 -c:v libx264 -x264-params qpmin=18 output.mp4For H.265 (libx265)
Use the -x265-params flag to set the qpmin
option:
ffmpeg -i input.mp4 -c:v libx265 -x265-params qpmin=18 output.mp4Summary of QP Range
- 0: Lossless (completely uncompressed visual data).
- 18–28: Standard range for visually lossless to high-quality web encodes.
- 51: Maximum compression (lowest quality).
Setting qpmin to a value like 16 or
18 ensures that the encoder does not waste file size trying
to render details that the human eye cannot perceive.