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

GStreamer caps不兼容:如何让rtph264pay接收H264流?

问题解决:GStreamer rtph264pay兼容MPEG-TS解析出的H264流

问题背景

开发服务时,通过GStreamer接收MPEG-TS流(固定为H264视频+OPUS音频),并以WebRTC形式推送给浏览器。初始管道配置:

udpsrc port=8888 ! tsdemux name=demux
demux. ! tee name=video-tee ! queue ! fakesink sync=true
demux. ! tee name=audio-tee ! queue ! fakesink sync=true

当浏览器客户端连接时,动态添加以下bin:

queue name=video-queue ! rtph264pay aggregate-mode=zero-latency ! webrtcbin.
queue name=audio-queue ! rtpopuspay ! webrtcbin.
webrtcbin name=webrtcbin

通过Ghost Pad将video-queue和audio-queue分别连接到video-tee与audio-tee后,浏览器显示黑屏;WebRTC Internals显示视频尺寸、帧率正常,但GStreamer日志提示Caps不兼容:

GST_CAPS gstpad.c:3235:gst_pad_query_accept_caps_default:<rtph264pay0:sink> caps: video/x-h264, stream-format=(string)byte-stream were not compatible with: video/x-h264, stream-format=(string)byte-stream, profile=(string)constrained-baseline, alignment=(string){ nal, au }; video/x-h264, stream-format=(string)byte-stream, alignment=(string){ nal, au }

原因分析

tsdemux输出的H264流仅携带stream-format=byte-stream的Caps元数据,而rtph264pay要求的Caps必须包含profile和alignment属性,两者元数据不匹配导致流无法正常接收。videoconvert仅负责视频颜色空间、分辨率等格式转换,无法补充H264编码相关的元数据,因此无法解决该问题。

解决方案

在video-queue与rtph264pay之间插入h264parse元素,它会解析H264流的SPS/PPS信息,自动补充profile、alignment等必要的Caps属性,让rtph264pay能匹配接收流,且无需重编码。

修改后的动态bin配置:

queue name=video-queue ! h264parse ! rtph264pay aggregate-mode=zero-latency ! webrtcbin.
queue name=audio-queue ! rtpopuspay ! webrtcbin.
webrtcbin name=webrtcbin

若已知输入流的具体编码参数,也可手动指定h264parse的输出Caps以进一步约束:

queue name=video-queue ! h264parse ! capsfilter caps="video/x-h264, stream-format=byte-stream, profile=constrained-baseline, alignment=nal" ! rtph264pay aggregate-mode=zero-latency ! webrtcbin.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 06:13:27