当前位置:网站首页>Why is the UDP stream set to 1316 bytes

Why is the UDP stream set to 1316 bytes

2022-06-11 17:38:00 ,,,, Nanshan light rain

When we use udp When pushing streams, you often see pkt_size=1316, as follows :
ffmpeg -re -i westLife.mp4 -f mpegts udp://127.0.0.1:5000?pkt_size=1316
In the above order pkt_size=1316 What does that mean? , It means udp When sending audio and video streams , Every udp The size of the payload contained in the package .
Set the following in the code :
AVDictionary*dic = NULL;
av_dict_set(&dic, “pkt_size”, “1316”, 0); //Maximum UDP packet size

So why is the size 1316 Well , Ethernet MTU(Maximum Transmission Unit) Usually 1500 bytes, therefore , It is better to control the length of the sent message to 1500 bytes following , With TS over UDP Take the scene , Usually every TS The size of the bag is 188 bytes, therefore , Every UDP The package can contain up to TS The number of packages is floor((1500 – 8 -20 )/ 188) = 7, That is, the valid data is 188 * 7 = 1316bytes,8 and 20 Respectively UDP Baotou and IP The length of Baotou .

Add :
MTU(Maximum Transmission Unit) The maximum packet size transmitted on the network .

MTU In bytes byte, The mainstream network is Ethernet (Ethernet)MTU yes 1500, Ethernet related network equipment MTU yes 1500.

MTU Are actually OSI Refer to model no 2 layer ( Data link layer ), The purpose is to limit 【MAC The data part of the frame (payload) Size 】 Value , Will affect 【 The first 3 Entire of layer IP Packet size 】, This size includes IP The header of the packet ; And in the end IP Packets are to be put into MAC frame .

28 The size of bytes , yes 【IP Baotou 20 byte 】+ 【ICMP The baotou 8 byte 】.

1500 bytes (Ethernet mtu) – 20 byte (IP header) – 8 byte (ICMP header) = 1472 byte

ping -s 1472 -M do 192.168.100.79

as follows :

PING 192.168.100.79 (192.168.100.79) 1472(1500) bytes of data.
1480 bytes from 192.168.100.79: icmp_seq=1 ttl=64 time=0.196 ms
1480 bytes from 192.168.100.79: icmp_seq=2 ttl=64 time=0.208 ms
^C
--- 192.168.100.79 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1032ms
rtt min/avg/max/mdev = 0.196/0.202/0.208/0.006 ms
ping -s 1473 -M do 192.168.100.79
PING 192.168.100.79 (192.168.100.79) 1473(1501) bytes of data.
ping: local error: Message too long, mtu=1500
ping: local error: Message too long, mtu=1500
ping: local error: Message too long, mtu=1500
ping: local error: Message too long, mtu=1500
ping: local error: Message too long, mtu=1500
^C
--- 192.168.100.79 ping statistics ---
5 packets transmitted, 0 received, +5 errors, 100% packet loss, time 4099ms

 Insert picture description here

原网站

版权声明
本文为[,,,, Nanshan light rain]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111716458338.html