Configure SRT Maxbw in FFmpeg
Configuring the maxbw (maximum bandwidth) parameter in
FFmpeg allows you to set a strict upper limit on the network bandwidth
consumed by a Secure Reliable Transport (SRT) stream. This article
explains what the maxbw parameter does, how to calculate
the correct value in bytes per second, and how to format your FFmpeg
command line to implement it effectively for stable, predictable live
streaming.
Understanding the maxbw Parameter
In SRT streaming, maxbw defines the maximum sending
bandwidth ceiling. This limit accounts for both the original payload
(audio and video data) and the extra bandwidth required for
retransmissions (ARQ) and SRT protocol overhead.
Key characteristics of maxbw:
- Unit of Measurement: Measured in bytes per second (Bps), not bits per second (bps).
- Default Behavior: If set to
0(or omitted), SRT calculates bandwidth dynamically based on the input bitrate and theoverheadbwsetting. If the input rate cannot be determined, it may fall back to an internal default (often up to 1 Gbps), which can lead to network congestion during packet loss recovery. - Purpose: Prevents SRT recovery bursts from saturating the network upload pipe during periods of packet loss.
Calculating the maxbw Value
Because FFmpeg expects maxbw in bytes per second, you
must convert your target megabits per second (Mbps) or kilobits per
second (kbps):
\[\text{Bytes per second} = \frac{\text{Target Bitrate in bps}}{8}\]
When setting this ceiling, always include an overhead buffer (typically 20% to 33% above your media bitrate) to allow SRT room to retransmit dropped packets.
- Example for a 5 Mbps media stream with a 25% recovery buffer
(6.25 Mbps total ceiling):
- \(6,250,000 \text{ bps} / 8 = 781,250 \text{ bytes/sec}\)
- Parameter:
maxbw=781250
- Example for an 8 Mbps total ceiling:
- \(8,000,000 \text{ bps} / 8 = 1,000,000 \text{ bytes/sec}\)
- Parameter:
maxbw=1000000
Syntax and FFmpeg Configuration
The maxbw parameter is appended directly to the SRT
destination URI as a query parameter.
URI Format
srt://<destination_ip>:<port>?maxbw=<value_in_bytes_per_second>
Complete FFmpeg Command Example
The following example encodes a live video input to an H.264 stream
at 4.5 Mbps with 128 kbps audio (~4.63 Mbps media bitrate) and sets an
SRT maxbw limit of 6 Mbps (750,000 bytes/second):
ffmpeg -re -i input.mp4 \
-c:v libx264 -b:v 4500k -maxrate 4500k -bufsize 9000k -pix_fmt yuv420p \
-c:a aac -b:a 128k \
-f mpegts "srt://192.168.1.100:9000?mode=caller&maxbw=750000&latency=2000000"Best Practices
- Do not set
maxbwequal to the video bitrate: If packet loss occurs, SRT must send missing packets in addition to the live data. Ifmaxbwis too low, the sender cannot retransmit packets in time, leading to dropped frames and stream failure. - Combine with
latency: Ensure yourlatency(in microseconds) is high enough to allow the necessary retransmissions within the bandwidth cap specified bymaxbw. - Separate parameters with
&: In Unix shells, wrap the entire SRT output URL in quotes to prevent the shell from interpreting&as a background execution command.