Configure FFmpeg MPEG PS Muxrate and Buffer Size
Configuring the multiplexing rate and video buffer size in FFmpeg’s
MPEG Program Stream (MPEG-PS) muxer is crucial for producing streams
that comply with strict hardware decoding standards, such as DVD-Video
or legacy broadcast hardware. This article explains how to use the
-muxrate option to control the total stream output rate and
how to configure the video encoder’s -bufsize and
-maxrate parameters to manage the Video Buffer Verifier
(VBV) system.
Setting the Multiplexing Rate (-muxrate)
The multiplexing rate defines the constant bit rate of the combined audio, video, and metadata packets in the output Program Stream. By default, FFmpeg calculates a variable mux rate based on the input streams, but legacy systems often require a strict constant rate.
To set a constant multiplexing rate, use the -muxrate
option. The value is specified in bits per second (bps), but you can use
metric suffixes like k (kilobits) or M
(megabits).
ffmpeg -i input.mp4 -f mpeg -muxrate 10080000 output.mpgIn this example, -f mpeg specifies the MPEG Program
Stream format, and -muxrate 10080000 forces a constant
multiplex rate of 10.08 Mbps (the standard maximum rate for
DVD-Video).
Setting the Video Buffer Size (-bufsize and -maxrate)
To prevent the decoder’s buffer from overflowing or underflowing, you
must configure the Video Buffer Verifier (VBV) parameters at the video
encoder level. This requires setting both the maximum video bitrate
(-maxrate) and the buffer size (-bufsize).
-maxrate: Sets the absolute peak bitrate allowed for the video stream.-bufsize: Sets the size of the decoder’s input buffer. This controls how often the bitrate is recalculated to prevent buffer violations.
For standard DVD-compliant MPEG-2 Program Streams, the maximum video
bitrate is typically capped at 9.8 Mbps, and the VBV buffer size is
strictly limited to 224 KB (which translates to 1,835,008 bits, or
1835k).
ffmpeg -i input.mp4 -c:v mpeg2video -b:v 5000k -maxrate 9000k -bufsize 1835k output.mpgComplete Configuration Example
When configuring both parameters, the multiplexing rate
(-muxrate) must always be higher than the combined maximum
bitrates of your video and audio streams to account for container
overhead.
The following command demonstrates a complete configuration for an MPEG-2 Program Stream with a fixed mux rate and an explicit VBV buffer configuration:
ffmpeg -i input.mp4 \
-c:v mpeg2video -b:v 6000k -maxrate 8000k -bufsize 1835k \
-c:a mp2 -b:a 224k \
-f vob -muxrate 10080000 \
output.mpgParameter Breakdown: *
-c:v mpeg2video: Encodes the video stream
to MPEG-2. * -b:v 6000k: Targets an
average video bitrate of 6 Mbps. *
-maxrate 8000k: Prevents the video bitrate
from exceeding 8 Mbps. * -bufsize 1835k:
Sets the VBV buffer size to 224 KB (DVD standard). *
-c:a mp2 -b:a 224k: Encodes the audio to
MP2 at 224 kbps. * -f vob: Selects the
DVD-Video variant of the MPEG Program Stream muxer. *
-muxrate 10080000: Locks the final
multiplexed file to a constant 10.08 Mbps stream.