RTP 的 H264 关键帧问题

H264 keyframe issue with RTP

我正在为 H264 视频构建一个 RTP 编码器。视频数据提供商不会定期在数据中传输关键帧,而是为我提供关键帧的二进制文件表示形式。这包括 SPS-PPS-SEI,然后是 i 帧的 8 个切片。

由于我正在对 RTP 进行编码,因此我需要以 2 秒的间隔重播此关键帧。我在我的代码中这样做,连同它进来的其余数据。我正在使用 ffmpeg 通过 UDP 套接字连接到 RTP 数据以进行显示测试。

我注意到视频似乎每隔 2 秒就会变黑并重新同步、像素化等。显然,这在视频产品中是非常不受欢迎的。我已经尝试调试它很长一段时间了,我唯一可以确定的是它与关键帧有关。如果我只发送一次关键帧,然后发送其余数据,ffmpeg 可以很好地显示视频。但是在网络环境下,我需要定期发送关键帧。

有没有人知道为什么会发生这种视频重新同步,最重要的是,如何阻止它发生?

谢谢!

设置解码器需要 SPS、PPS 和 SEI,它们属于 non-VCL 数据。这些通常在 IDR 帧之前的流中找到,但它们也可以在带外通信,例如通过 SDP。如果您没有用于通信 SPS 和 PPS 的带外机制,那么当然,您需要定期在带内重新发送它们,以便新客户端可以初始化 H.264 解码器。

I am noticing that every 2 seconds, the video seems to blank and resync itself, pixelate, etc. Obviously, this is highly undesirable in the video product. I've been trying to debug this for quite some time and the only thing I can determine is that it has to do with the keyframe. If I just send the keyframe once, and then the rest of the data, ffmpeg displays the video fine. But in a network environment, I need to send the keyframe at periodic intervals.

我不确定我是否理解正确,但你不能每两秒重新发送一次“静态”i 帧(可能是 IDR)数据:你正在发送“旧的”先前解码的 VCL 数据到具有重新同步流效果的编码器。

Does anyone have an idea as to why this resyncing of the video happens and most importantly, how to stop it from happening?

尝试定期仅发送非 VCL NAL 单元。您可以定期执行此操作,也可以仅将它们添加到流中的 IDR 帧之前,因为无论如何您只能在此时开始播放视频(没有伪影)。 .