Configure FFmpeg MPEG-TS max_delay Queue Size
This article explains how to configure the maximum queuing delay when
muxing audio and video streams into an MPEG-TS container using FFmpeg.
You will learn how to use the -max_delay option, understand
its measurement unit, and see practical command-line examples to
optimize stream synchronization and latency.
Understanding -max_delay in MPEG-TS Muxing
When muxing streams into the MPEG Transport Stream (MPEG-TS) format,
FFmpeg buffers incoming packets to ensure that audio and video are
properly interleaved. The -max_delay option specifies the
maximum muxing or packetization delay.
By default, FFmpeg sets a default delay to ensure stream compliance, but manual configuration is often necessary for low-latency live streaming or when dealing with high-bitrate sources.
The Value Unit
The -max_delay option expects an integer value expressed
in microseconds (1 second = 1,000,000
microseconds).
- To set a maximum delay of 100 milliseconds, use
100000. - To set a maximum delay of 500 milliseconds, use
500000. - To set a maximum delay of 1 second, use
1000000.
Command Syntax
To apply this configuration, place the -max_delay option
immediately after specifying the MPEG-TS format (-f mpegts)
or before the output destination.
Here is the standard command-line syntax:
ffmpeg -i input.mp4 -c:v libx264 -c:a aac -f mpegts -max_delay 500000 output.tsIn this example: * -f mpegts forces the output format to
MPEG-TS. * -max_delay 500000 allocates a maximum
queue/buffer delay of 500,000 microseconds (500ms) for stream
muxing.
Use Cases and Troubleshooting
1. Reducing Latency in Live Streams
For real-time streaming (such as SRT or UDP broadcast), a lower
-max_delay reduces the time FFmpeg holds packets in the
queue before sending them.
ffmpeg -re -i input.mp4 -c copy -f mpegts -max_delay 100000 udp://127.0.0.1:1234Note: Setting this value too low (e.g., below 50000) may cause packet drop or synchronization issues if the input stream suffers from jitter.
2. Resolving “Buffer Underflow” Errors
If you encounter packet loss or buffer underflow warnings in your
console, increasing the -max_delay gives FFmpeg more time
to align audio and video packets properly.
ffmpeg -i input.mp4 -c copy -f mpegts -max_delay 2000000 output.tsThis increases the queue delay limit to 2 seconds, allowing the muxer to handle larger variances in stream arrival times.