FFmpeg Constant UDP Output

By default ffmpeg writes to the socket as soon as new data is available.  This leads to traffic bursts which may cause the receiver buffer to overflow or underflow.

Example for a 720p @ 2500 kbps CBR MPEG-2 transport stream:

ffmpeg -re -i <input> -s 1280x720 -r 24 -c:v libx264 -x264opts nal-hrd=cbr:force-cfr=1 \
-b:v 2300k -minrate 2300k -maxrate 2300k -bufsize 95k -c:a libfdk_aac -b:a 192k \
-flush_packets 0 -f mpegts "udp://127.0.0.1:10000?pkt_size=1316"

FFmpeg UDP Traffic

Two new UDP options have been added to address the issue:

bitrate use the specified constant bitrate if the input has enough packets to sustain it
burst_bits maximum number of bits in packet bursts

For now they work solely with UDP and not RTP.

Updated example taking into account a ~10% muxing overhead:

ffmpeg -re -i <input> -s 1280x720 -r 24 -c:v libx264 -x264opts nal-hrd=cbr:force-cfr=1 \
-b:v 2300k -minrate 2300k -maxrate 2300k -bufsize 95k -c:a libfdk_aac -b:a 192k \
-flush_packets 0 -f mpegts "udp://127.0.0.1:10000?pkt_size=1316&bitrate=2700000"

ffmpeg_udp_bitrate

Advertisements

One thought on “FFmpeg Constant UDP Output

  1. Thank you for this inspiring post. I had to solve a similar problem. But instead of making the video bitrate constant (nal-hrd=cbr), I’ve set the option “-muxrate”. The mpegts muxer is stuffing the transport stream with null packets to get a CBR during transfer when the option is used.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s