How to Configure FFmpeg Named Pipe Buffer Size
Using named pipes (FIFOs) with FFmpeg often leads to frame drops or buffer overflow errors when writing or reading rates fluctuate. While FFmpeg does not have a single dedicated command-line flag specifically to resize the operating system's raw named pipe buffer, you can eliminate data loss by adjusting FFmpeg's internal thread packet queues, modifying the operating system's pipe limits, or utilizing intermediate memory buffers.
1. Increase FFmpeg's Thread Queue Size
When reading real-time audio or video streams from a named pipe, FFmpeg uses an internal processing queue. If the demuxer cannot process data fast enough, it drops packets and prints a "Thread message queue full" warning.
Add the -thread_queue_size option before the input pipe
declaration to allocate a larger packet queue in memory:
ffmpeg -thread_queue_size 1024 -i /tmp/my_pipe output.mp4For high-bitrate video or high-latency operations, increase this
value to 2048 or 4096. This controls the
number of unhandled packets buffered internally before drops occur.
2. Adjust Linux OS Pipe Buffer Size
By default, Linux assigns a small 64 KB capacity to named pipes
created with mkfifo. When data bursts exceed this limit,
writer processes block, leading to latency or dropped packets.
Option A: Using
mbuffer or pv
The most effective way to attach an arbitrary buffer size (e.g., 64 MB) to a named pipe without modifying kernel configuration is to pass the stream through an intermediate memory buffer tool:
# Read from the pipe with a 64MB buffer
mbuffer -i /tmp/my_pipe -m 64M | ffmpeg -thread_queue_size 1024 -i - output.mp4Option B: System-Wide Pipe Limit Adjustment
You can inspect the maximum pipe size allowed by the kernel:
cat /proc/sys/fs/pipe-max-sizeTo allow processes to request larger pipe allocations, increase the system limit by executing:
echo 1048576048 | sudo tee /proc/sys/fs/pipe-max-size3. Buffer Named Pipe Outputs Using the FIFO Muxer
If you are writing to a named pipe and the downstream
consumer is periodically slow, FFmpeg may stall or drop output frames.
Use FFmpeg’s native fifo pseudo-muxer to create an internal
queue in an independent thread:
ffmpeg -i input.mp4 -map 0 -c copy -f fifo -fifo_queue_size 3000 -drop_pkts_on_overflow 0 /tmp/my_pipeKey parameters:
-fifo_queue_size: Number of packets stored in the RAM buffer.-drop_pkts_on_overflow 0: Forces FFmpeg to block rather than discard frames if the buffer reaches capacity, preventing data loss.