You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于GStreamer的UDP音视频收发问题求助(附代码及运行日志)

问题排查与解决方案

1. 修复接收端GStreamer命令的语法错误

你的接收端命令中multicast-group参数缺少地址值,这是语法错误,会导致udpsrc无法正确初始化接收逻辑。

修正后的单播接收命令:

gst-launch-1.0 -v udpsrc port=5000 ! application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H265,payload=(int)96 ! rtph265depay ! avdec_h265 ! videoconvert ! autovideosink sync=false

如果使用多播场景(适配udpsquared多播转发),需要同步修改收发端命令:

# 发送端:指定多播地址,开启多播模式
gst-launch-1.0 -v rtspsrc location=rtsp://192.168.144.25:8554/main.264 short-header=TRUE latency=400 connection-speed=3000 timeout=50000000 ! rtph265depay ! h265parse ! rtph265pay ! udpsink host=224.0.0.1 port=5000 auto-multicast=true ttl=1

# 接收端:绑定对应多播地址
gst-launch-1.0 -v udpsrc multicast-group=224.0.0.1 port=5000 auto-multicast=true ! application/x-rtp,media=(string)video,clock-rate=(int)90000,encoding-name=(string)H265,payload=(int)96 ! rtph265depay ! avdec_h265 ! videoconvert ! autovideosink sync=false

注:添加payload=(int)96是因为rtph265pay默认使用payload 96,明确指定caps可避免流格式匹配失败。

2. 验证发送端源流有效性

先跳过UDP传输环节,直接在发送端本地播放RTSP流,确认摄像头源本身无问题:

gst-launch-1.0 -v rtspsrc location=rtsp://192.168.144.25:8554/main.264 short-header=TRUE latency=400 ! rtph265depay ! avdec_h265 ! videoconvert ! autovideosink sync=false

如果本地无法播放,优先排查RTSP摄像头的网络连接、端口配置及流输出格式。

3. udpsquared v2配置要点

udpsquared作为UDP转发工具,需确保:

  • 监听端口与发送端udpsink port完全一致(如5000)
  • 转发目标设置为VLC所在机器的IP和指定端口(如5001)
  • 关闭冗余过滤规则,保证UDP数据包能无阻碍转发

4. VLC播放配置

方式1:直接指定RTP地址

打开VLC → 媒体 → 打开网络串流 → 输入:

rtp://@:5001  # 5001为udpsquared转发的目标端口

若无画面,调整缓存参数:

  • 工具 → 偏好设置 → 输入/编解码器 → 勾选「启用网络缓存(ms)」,设置为500-1000
  • 打开网络串流时点击「显示更多选项」,在「编辑选项」中添加:
    :rtp-caching=500 :codec=h265
    

方式2:使用SDP文件

创建h265.sdp文件,内容如下:

v=0
o=- 0 0 IN IP4 127.0.0.1
s=H265 Stream
c=IN IP4 0.0.0.0
t=0 0
m=video 5001 RTP/AVP 96
a=rtpmap:96 H265/90000

用VLC打开该文件即可播放转发后的流。

5. 网络连通性排查

  • 用tcpdump或Wireshark抓包,确认UDP包从发送端发出、经udpsquared转发后能到达VLC所在机器
  • 检查防火墙规则,确保5000、5001等端口允许UDP流量通行

内容的提问来源于stack exchange,提问作者hendeseci

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 20:26:15