docs: update (#5125)

This commit is contained in:
Alessandro Ros 2025-10-29 10:51:02 +01:00 committed by GitHub
parent ff305425a5
commit 3ae5262510
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 93 additions and 72 deletions

View file

@ -0,0 +1,69 @@
# Decrease packet loss
MediaMTX is meant for routing live streams, and makes use of a series of protocol which try to minimize latency at cost of losing packets in transmit. In particular, most protocols are built on UDP, which is an "unrealiable transport", specifically picked because it allows to drop late packets in case of network congestions, preserving the real-time aspect of streams.
These packet losses are usually detected and printed in MediaMTX logs.
If you need to improve the stream reliability and decrease packet losses, the first thing to do is to check whether the network between the MediaMTX instance and the intended publishers and readers has sufficient bandwidth for transmitting the media stream. Most of the times, packet losses are caused by a network which is not fit for this scope. This limitation can be overcome by either recompressing the stream with a lower bitrate, or by changing network.
There are however some parameters that can be tuned to improve the situation, at cost of increasing RAM consumption:
- When publishing a stream with RTSP, MPEG-TS or RTP, packets might get discarded by the server because the UDP read buffer size is too small. Try increasing the UDP read buffer size:
```yml
rtspUDPReadBufferSize: 1000000
```
If the source of the stream is a camera:
```yml
paths:
test:
source: rtsp://..
rtspUDPReadBufferSize: 1000000
```
There are similar options for the MPEG-TS and RTP protocol:
```yml
paths:
test:
source: udp+mpegts://..
mpegtsUDPReadBufferSize: 1000000
```
or:
```yml
paths:
test:
source: udp+rtp://..
rtpUDPReadBufferSize: 1000000
```
All these options require the `net.core.rmem_max` system parameter to be equal or greater than `rtspUDPReadBufferSize`:
```sh
sudo sysctl net.core.rmem_max=100000000
```
- When reading a stream, packets might get discarded because the write queue is too small. This can be noticed in logs through the "reader is too slow" message. Try increasing the write queue:
```yml
writeQueueSize: 1024
```
- When publishing or reading a stream with RTSP, it's possible to switch from the UDP transport protocol to the TCP transport protocol, which is less performant but has a packet retransmission mechanism:
```yml
rtspTransports: [tcp]
```
In case the source is a camera:
```yml
paths:
test:
source: rtsp://..
rtspTransport: tcp
```