Fix MPEG-TS Buffer Underflow Warnings in FFmpeg

MPEG-TS buffer underflow warnings in FFmpeg typically indicate that the encoder is not supplying data fast enough to maintain the required muxrate, or that the buffer parameters are misconfigured. This article provides a straightforward guide to diagnosing and resolving these warnings by adjusting bitrate, muxrate, and buffer size settings in your FFmpeg commands.

Understanding the Cause of Buffer Underflow

An MPEG Transport Stream (MPEG-TS) is designed for broadcasting and streaming, which requires a highly consistent flow of data. When you set a constant multiplexing rate using the -muxrate option, FFmpeg expects the combined bitrates of your video, audio, and metadata to perfectly fill that rate.

A “buffer underflow” occurs when the video encoder outputs too few bits during a complex or static scene, causing the buffer to empty. This mismatch between the actual output bitrate of the encoder and the target transmission rate of the TS container triggers the warning.

How to Resolve Buffer Underflow

To eliminate these warnings, you must align your video encoder settings with your transport stream multiplexer settings.

1. Set Strict CBR (Constant Bitrate) with VBV

To keep the bitrate stable, you must enforce the Video Buffer Verifier (VBV) by setting the bitrate, maximum bitrate, and buffer size. The -bufsize acts as the receiver’s buffer.

ffmpeg -i input.mp4 -c:v libx264 -b:v 4000k -maxrate 4000k -bufsize 8000k -f mpegts output.ts

2. Configure a Minimum Bitrate

If your video contains dark, static, or simple scenes, the encoder may naturally drop the bitrate to save space, causing an underflow. Forcing a minimum bitrate prevents this drop:

ffmpeg -i input.mp4 -c:v libx264 -b:v 4000k -maxrate 4000k -minrate 4000k -bufsize 4000k -f mpegts output.ts

3. Match the Muxrate to the Total Bitrate

If you are explicitly setting the -muxrate parameter, ensure it is roughly 10% to 15% higher than the sum of your video and audio bitrates to account for container overhead.

If the -muxrate is set too high compared to the encoder’s output, underflows will occur.

For example, if your video is 4000k and audio is 128k (total ~4128k), your muxrate should be set to approximately 4500k to 4800k:

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

4. Adjust Muxer Delay and Preload

You can adjust how early FFmpeg starts writing data to the multiplexer stream using -muxdelay and -preload. Increasing these values gives the demuxer more time to buffer data before playback begins.

ffmpeg -i input.mp4 -c:v libx264 -b:v 4000k -maxrate 4000k -bufsize 8000k -muxdelay 0.5 -preload 0.5 -f mpegts output.ts