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

使用Gstreamer合流多路H265 RTSP推KVS报编解码错误求助

错误根因

你遇到的MissingCodecPrivateDataException错误,核心原因是x265编码器输出的H.265码流没有附带VPS/SPS/PPS编解码私有数据,Kinesis Video Streams(KVS)的kvssink插件需要在码流开头(以及每个关键帧前)拿到这些数据才能正确识别编码格式,生成可检索的视频片段。
你之前单路RTSP推流可以正常工作,是因为直接透传了原RTSP流里已经携带的SPS/PPS数据,不需要编码端额外生成。合流场景下你做了解码再重新编码,新生成的H.265码流默认不会重复插入私有数据,就触发了KVS的报错。
另外你之前写的两路合流命令还存在videomixer坐标配置错误的问题:第一个命令中sink_0的xpos设为1080、sink_1的ypos设为1080,会导致两个子画面都超出输出画布的可见范围,无法正常合成。

解决方案

关键修改点

  • 给x265enc添加repeat-headers=TRUE参数,强制编码器在每个关键帧前都插入VPS/SPS/PPS私有数据
  • 给x265enc添加key-int-max=30参数,控制关键帧间隔,适配KVS的片段生成规则
  • 明确指定videomixer的输出画布尺寸和每个子画面的位置,避免画面溢出
  • 每个子流解码后先缩放到固定的子画面尺寸,保证合流布局稳定
  • 编码后增加h265parse并明确指定码流格式为byte-stream、对齐方式为au,匹配kvssink的输入要求

4路2×2合流完整命令示例

假设每个子画面分辨率为1920×1080,输出总分辨率为3840×2160,命令如下:

gst-launch-1.0 -e \
# 第一路流 左上位置
rtspsrc user-id="admin" user-pw="password" location="rtsp://admin:password@192.168.0.1:554/cam/realmonitor?channel=1&subtype=0" short-header=TRUE ! rtph265depay ! h265parse ! video/x-h265, alignment=au ! libde265dec ! videoconvert ! videoscale ! video/x-raw,width=1920,height=1080 ! queue ! m.sink_0 \
# 第二路流 右上位置
rtspsrc user-id="admin" user-pw="password" location="rtsp://admin:password@192.168.0.2:554/cam/realmonitor?channel=1&subtype=0" short-header=TRUE ! rtph265depay ! h265parse ! video/x-h265, alignment=au ! libde265dec ! videoconvert ! videoscale ! video/x-raw,width=1920,height=1080 ! queue ! m.sink_1 \
# 第三路流 左下位置
rtspsrc user-id="admin" user-pw="password" location="rtsp://admin:password@192.168.0.3:554/cam/realmonitor?channel=1&subtype=0" short-header=TRUE ! rtph265depay ! h265parse ! video/x-h265, alignment=au ! libde265dec ! videoconvert ! videoscale ! video/x-raw,width=1920,height=1080 ! queue ! m.sink_2 \
# 第四路流 右下位置
rtspsrc user-id="admin" user-pw="password" location="rtsp://admin:password@192.168.0.4:554/cam/realmonitor?channel=1&subtype=0" short-header=TRUE ! rtph265depay ! h265parse ! video/x-h265, alignment=au ! libde265dec ! videoconvert ! videoscale ! video/x-raw,width=1920,height=1080 ! queue ! m.sink_3 \
# 合流+编码+推KVS
videomixer name=m background=black sink_0::xpos=0 sink_0::ypos=0 sink_1::xpos=1920 sink_1::ypos=0 sink_2::xpos=0 sink_2::ypos=1080 sink_3::xpos=1920 sink_3::ypos=1080 ! videoconvert ! x265enc key-int-max=30 repeat-headers=TRUE tune=zerolatency ! h265parse ! video/x-h265, alignment=au, stream-format=byte-stream ! kvssink stream-name="test-stream" storage-size=512 access-key="access-key" secret-key="secret-key" aws-region="us-east-1"

两路合流适配

如果只需要两路流并排或者上下布局,只需要删除对应rtspsrc分支,调整videomixer的子画面位置参数即可,核心编码推流部分的配置保持不变。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 15:39:01