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.
Method 1: Constant Quality (Recommended)
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.
Command Syntax:
ffmpeg -i input.mp4 -c:v mpeg2video -q:v 3 output.mpgHow the scale works:
- The scale ranges from 1 (highest quality, largest file size) to 31 (lowest quality, smallest file size).
- A value of 2 to 5 is generally recommended for high-quality archival or DVD preparation.
- A value of 1 is rarely used as it creates excessively large files with diminishing visual returns.
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-b:v: Sets the target average bitrate (e.g.,5Mfor 5 Mbps).-maxrate: Restricts the maximum peak bitrate (important for DVD compatibility, which maxes out at 9.8 Mbps).-bufsize: Sets the Video Buffer Verifier (VBV) buffer size. For DVD-Video, this is typically set to1835k.
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.mpgTo 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:
B-Frames (
-bf): Enabling B-frames improves compression efficiency. For MPEG-2, a value of 2 is standard:-bf 2GOP Size (
-g): Defines the distance between keyframes. For standard PAL (25 fps) or NTSC (29.97 fps) video, a GOP size of 12 or 15 is recommended:-g 15