GStreamer RTP输出帧率异常过快及多播播放启动顺序问题求助
GStreamer推流与播放问题解决方案
问题1:帧率异常,输出速率远超设定值
推流命令:
gst-launch-1.0.exe videotestsrc ! timeoverlay ! video/x-raw,format=NV12,width=1920,height=1080,framerate=50/1 ! queue ! nvh265enc !queue ! h265parse ! tee name=video_tee ! queue ! rtph265pay ! udpsink host=224.1.1.1 port=5600 auto-multicast=true sync=false qos-dscp=60 max-bitrate=12000000
现象:无论设置何种帧率,RTP输出帧率始终维持在250-300帧/秒,播放时快进严重,画面卡顿跳帧,FFmpeg使用硬件编码时也有类似问题。
解决步骤:
- 强制视频源按设定帧率输出:
videotestsrc默认会全速生成帧,添加is-live=true参数让它严格遵循设定的帧率:gst-launch-1.0.exe videotestsrc is-live=true ! timeoverlay ! video/x-raw,format=NV12,width=1920,height=1080,framerate=50/1 ! queue ! nvh265enc ! queue ! h265parse ! tee name=video_tee ! queue ! rtph265pay ! udpsink host=224.1.1.1 port=5600 auto-multicast=true sync=false qos-dscp=60 max-bitrate=12000000 - 明确配置硬件编码器参数:给
nvh265enc添加framerate=50/1参数,同时设置rc-mode=cbr确保比特率稳定,避免编码器失控:gst-launch-1.0.exe videotestsrc is-live=true ! timeoverlay ! video/x-raw,format=NV12,width=1920,height=1080,framerate=50/1 ! queue ! nvh265enc framerate=50/1 rc-mode=cbr ! queue ! h265parse ! tee name=video_tee ! queue ! rtph265pay ! udpsink host=224.1.1.1 port=5600 auto-multicast=true sync=false qos-dscp=60 max-bitrate=12000000 - 更新显卡驱动:旧版本NVIDIA驱动可能存在硬件编码器同步bug,前往NVIDIA官网下载并安装最新驱动。
问题2:必须先启动播放端再启动推流,否则无画面
播放命令:
gst-launch-1.0.exe udpsrc multicast-group=224.1.1.1 auto-multicast=true port=5600 caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H265" ! rtph265depay ! decodebin ! glimagesink
现象:推流先启动时,播放端后续启动无法获取画面。
解决步骤:
- 定期发送关键帧配置信息:在
rtph265pay后添加config-interval=1,强制每隔1秒发送一次SPS/PPS关键帧配置,确保播放端后启动时能快速获取解码所需的信息:gst-launch-1.0.exe videotestsrc is-live=true ! timeoverlay ! video/x-raw,format=NV12,width=1920,height=1080,framerate=50/1 ! queue ! nvh265enc framerate=50/1 rc-mode=cbr ! queue ! h265parse ! tee name=video_tee ! queue ! rtph265pay config-interval=1 ! udpsink host=224.1.1.1 port=5600 auto-multicast=true sync=false qos-dscp=60 max-bitrate=12000000 - 修改播放端等待参数:给
udpsrc添加timeout=0,让播放端持续等待数据包,避免超时退出:gst-launch-1.0.exe udpsrc multicast-group=224.1.1.1 auto-multicast=true port=5600 timeout=0 caps="application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H265" ! rtph265depay ! decodebin ! glimagesink - 检查网络配置:确保局域网内的交换机/路由器开启了IGMP snooping,避免组播数据包在无接收端时被丢弃。
内容的提问来源于stack exchange,提问作者Matyas Szekely
相关产品推荐
相关产品推荐

