Configure MPEG-TS Constant Bitrate in FFmpeg

This article explains how to configure the muxrate parameter in FFmpeg to output a constant bitrate (CBR) MPEG-TS stream. You will learn the specific command-line arguments required to force a constant mux rate, configure the video encoder for CBR, and ensure the stream is padded with null packets for compatibility with broadcast equipment.

To output a constant bitrate (CBR) MPEG-TS stream in FFmpeg, you must use the -muxrate option. By default, FFmpeg muxes MPEG-TS streams with a variable bitrate (VBR). Specifying a -muxrate forces the multiplexer to output a strict, constant bitrate by automatically inserting null packets (PID 0x1fff) to fill any bandwidth gaps.

The Basic Command

To set a constant bitrate, specify your target total stream bitrate using the -muxrate flag. The value can be represented in bits per second (e.g., 5000000) or with a unit suffix (e.g., 5M or 5000k).

ffmpeg -i input.mp4 -c:v libx264 -b:v 4000k -c:a aac -b:a 128k -f mpegts -muxrate 5000k output.ts

Ensuring Stream Stability with Video Bitrate Limits

Setting -muxrate alone is not always sufficient for a stable stream. The combined bitrate of your video, audio, metadata, and container overhead must always remain below the specified muxrate. If the combined payload exceeds the muxrate, the stream will suffer from buffer overflows and dropped packets.

To prevent this, you must constrain the video encoder using the Video Buffer Verifier (VBV) system. This is done by setting -b:v (target bitrate), -maxrate:v (maximum bitrate), and -bufsize:v (buffer size):

ffmpeg -i input.mp4 \
  -c:v libx264 -b:v 4000k -maxrate:v 4000k -bufsize:v 2000k \
  -c:a aac -b:a 128k \
  -f mpegts -muxrate 5000k \
  output.ts

Key Parameter Breakdown

  • -muxrate 5000k: Forces the output MPEG-TS container to have an exact, constant bitrate of 5 Mbps. If the encoded video and audio require less than 5 Mbps, FFmpeg pads the remaining bandwidth with null packets.
  • -maxrate:v 4000k: Restricts the video encoder from exceeding 4 Mbps, leaving a 1 Mbps buffer for audio, overhead, and padding.
  • -bufsize:v 2000k: Defines the receiver's buffer size (usually set to 1–2 seconds of video bitrate). It controls how strictly the encoder enforces the maxrate limit.