Configure mpeg2video Quality in FFmpeg

Configuring the quality of the mpeg2video encoder in FFmpeg allows you to balance video fidelity and file size for DVDs, digital broadcasting, or legacy playback devices. This guide covers how to set the quality of MPEG-2 video streams using both constant quality scale (-qscale:v) and bitrate control flags, ensuring optimal output results for your specific use case.

The most effective way to control quality in the mpeg2video encoder is by using the constant quality parameter, represented by -qscale:v (or the alias -q:v).

This method lets the encoder automatically adjust the bitrate to maintain a consistent level of visual quality throughout the entire video.

Method 2: Bitrate Control (CBR and VBR)

If you need to target a specific file size or comply with strict hardware playback limits (such as DVD specifications), you should control the quality using bitrate limits instead of a quality scale.

Variable Bitrate (VBR)

VBR allows the bitrate to fluctuate based on the complexity of the scene, which is more efficient than a constant bitrate.

ffmpeg -i input.mp4 -c:v mpeg2video -b:v 5M -maxrate 9M -bufsize 1835k output.mpg

Constant Bitrate (CBR)

CBR forces the encoder to maintain the exact same bitrate throughout the entire video, which is useful for streaming protocols.

ffmpeg -i input.mp4 -c:v mpeg2video -b:v 6M -minrate 6M -maxrate 6M -bufsize 1835k output.mpg

To achieve true CBR, the target (-b:v), minimum (-minrate), and maximum (-maxrate) bitrates must all be set to the exact same value.

Additional Quality Tweaks

To further optimize the quality of your MPEG-2 encode, you can adjust the Group of Pictures (GOP) size and B-frames: