Fix RTP Missed Packet Warnings in FFmpeg RTSP
When capturing an RTSP stream using FFmpeg, encountering “RTP: missed packet” warnings usually points to network congestion, packet loss, or buffer overflows. This article provides actionable solutions to resolve these warnings by switching transport protocols, increasing buffer sizes, and optimizing FFmpeg configuration settings for a stable stream capture.
1. Switch from UDP to TCP
By default, RTSP often stream over UDP, which does not guarantee packet delivery. If your network experiences even minor congestion, UDP packets will be dropped, resulting in “RTP: missed packet” warnings.
Forcing FFmpeg to use TCP ensures packet delivery through
retransmission. You can do this by adding the
-rtsp_transport tcp flag before your input
URL:
ffmpeg -rtsp_transport tcp -i rtsp://your_camera_stream_url -c copy output.mp42. Increase the Thread Queue Size
If FFmpeg cannot process incoming packets quickly enough, the input buffer will overflow, causing packet loss. Increasing the thread queue size allocates more memory to buffer the incoming stream before processing.
Add the -thread_queue_size option before the input:
ffmpeg -thread_queue_size 1024 -i rtsp://your_camera_stream_url -c copy output.mp4For high-resolution or high-framerate streams, you can increase this
value further (e.g., 2048 or 4096).
3. Adjust the Input Buffer Size
You can explicitly increase the ring buffer size used by FFmpeg to ingest the RTSP stream. This gives the system more breathing room during temporary CPU or disk I/O spikes.
Use the -buffer_size parameter to allocate more memory
(defined in bytes):
ffmpeg -buffer_size 1024000 -i rtsp://your_camera_stream_url -c copy output.mp44. Increase System-Level Socket Buffers (Linux)
If you are running FFmpeg on Linux, the operating system’s default
network socket receive buffer might be too small for high-bitrate video
streams. You can temporarily increase the maximum receiver buffer size
using sysctl:
sudo sysctl -w net.core.rmem_max=26214400
sudo sysctl -w net.core.rmem_default=26214400To make these changes permanent, add the following lines to
/etc/sysctl.conf:
net.core.rmem_max=26214400
net.core.rmem_default=26214400
Summary of an Optimized Command
For the most reliable capture, combine these parameters into a single command:
ffmpeg -rtsp_transport tcp -thread_queue_size 2048 -buffer_size 10M -i rtsp://your_camera_stream_url -c copy output.mp4