当前位置: 首页 > 工具软件 > RTP Tools > 使用案例 >

FFmpeg的那些坑-RTP missed xxx packets

邢俊悟
2023-12-01

前言

文章首发于Noah Sun’s Home FFmpeg的那些坑-RTP missed xxx packets

FFmpeg使用场景

使用FFmpeg将两路RTP流合成一路流

ffmpeg -acodec libopus -i ../var/tmp/1024_0.sdp -acodec libopus -i ../var/tmp/1024_1.sdp -filter_complex "[0:v]setpts=PTS-STARTPTS,setsar=1[left];[1:v]setpts=PTS-STARTPTS,setsar=1[right];[left][right]hstack[vout];[0:a][1:a]amix[aout]" -map [vout] -map [aout] -vcodec libx264 -profile:v high -preset veryfast -strict -2 -acodec aac -f flv rtmp://localhost:1935/live/1024

问题

FFmpeg日志提示RTP: missed xxx packets
合流视频花屏。

[h264 @ 0x45c05a0] Invalid level prefix
[h264 @ 0x45c05a0] error while decoding MB 11 19
[h264 @ 0x45c05a0] concealing 53 DC, 53 AC, 53 MV errors in I frame
[sdp @ 0x42e5c20] max delay reached. need to consume packet
[sdp @ 0x42e5c20] RTP: missed 16 packets
[sdp @ 0x42e5c20] max delay reached. need to consume packet
[sdp @ 0x42e5c20] RTP: missed 4 packets
[h264 @ 0x45c05a0] negative number of zero coeffs at 0 4
[h264 @ 0x45c05a0] error while decoding MB 0 4
[h264 @ 0x45c05a0] concealing 289 DC, 289 AC, 289 MV errors in P frame
[h264 @ 0x4413420] Invalid level prefix
[h264 @ 0x4413420] error while decoding MB 9 19
[h264 @ 0x4413420] concealing 55 DC, 55 AC, 55 MV errors in P frame

原因

FFmpeg默认接收线程数据队列大小thread_queue_size为8,当合流不够快时,接收数据队列溢出,导致RTP接收数据丢包。

解决办法

使用thread_queue_size选项配置大一点的接收线程数据队列,如

ffmpeg -thread_queue_size 512 -acodec libopus -i ../var/tmp/1024_0.sdp  -thread_queue_size 512 -acodec libopus -i ../var/tmp/1024_1.sdp -filter_complex "[0:v]setpts=PTS-STARTPTS,setsar=1[left];[1:v]setpts=PTS-STARTPTS,setsar=1[right];[left][right]hstack[vout];[0:a][1:a]amix[aout]" -map [vout] -map [aout] -vcodec libx264 -profile:v high -preset veryfast -strict -2 -acodec aac -f flv rtmp://localhost:1935/live/1024
 类似资料: