来自 RTSP 流的 H.264 解码错误日志

Posted

技术标签:

【中文标题】来自 RTSP 流的 H.264 解码错误日志【英文标题】:H.264 decoding error log from RTSP stream 【发布时间】:2015-09-05 13:19:12 【问题描述】:

我收到以下 H264 错误日志。此日志是在 FFMPEG 的帮助下解码 RTSP 视频流时出现的。显示的图像在 5/6 秒后变得模糊。图片会不时恢复它。然而,大部分时间它仍然是模糊的。

编辑:一些 FFMPEG 讨论论坛建议升级 FFMPEG 版本以避免这些日志。我已经更新了 2015 年 6 月 19 日的最新 FFMPEG 版本。日志仍然在那里,图片仍然模糊。

编辑 2:RTSP 流来自 GANZ 摄像机。此相机通过 LAN 连接。

[h264 @ 0abb2aa0] Cannot use next picture in error concealment
[h264 @ 0abb2aa0] concealing 1933 DC, 1933 AC, 1933 MV errors in P frame
[h264 @ 098e5c80] RTP: missed 131 packets
[h264 @ 0abb3300] error while decoding MB 66 25, bytestream (-9)
[h264 @ 0abb3300] Cannot use next picture in error concealment
[h264 @ 0abb3300] concealing 1583 DC, 1583 AC, 1583 MV errors in P frame
[h264 @ 098e5c80] RTP: missed 8 packets
[h264 @ 0b113e40] error while decoding MB 54 30, bytestream (-11)
[h264 @ 0b113e40] Cannot use next picture in error concealment
[h264 @ 0b113e40] concealing 1195 DC, 1195 AC, 1195 MV errors in P frame
[h264 @ 098e5c80] RTP: missed 118 packets
[h264 @ 0ac79960] error while decoding MB 13 20, bytestream (-13)
[h264 @ 0ac79960] Cannot use next picture in error concealment
[h264 @ 0ac79960] concealing 2036 DC, 2036 AC, 2036 MV errors in P frame
[h264 @ 098e5c80] RTP: missed 198 packets
[h264 @ 0ad4f500] error while decoding MB 21 9, bytestream (-5)
[h264 @ 0ad4f500] Cannot use next picture in error concealment
[h264 @ 0ad4f500] concealing 2908 DC, 2908 AC, 2908 MV errors in P frame
[h264 @ 098e5c80] RTP: missed 108 packets
[h264 @ 0abb3300] error while decoding MB 1 14, bytestream (-5)
[h264 @ 0abb3300] Cannot use next picture in error concealment
[h264 @ 0abb3300] concealing 2528 DC, 2528 AC, 2528 MV errors in P frame
[h264 @ 098e5c80] RTP: missed 106 packets
[h264 @ 0b1149c0] error while decoding MB 12 5, bytestream (-7)
[h264 @ 0b1149c0] Cannot use next picture in error concealment
[h264 @ 0b1149c0] concealing 3237 DC, 3237 AC, 3237 MV errors in P frame
[h264 @ 098e5c80] RTP: missed -65402 packets
[h264 @ 0b1155a0] error while decoding MB 50 38, bytestream (-7)
[h264 @ 0b1155a0] Cannot use next picture in error concealment
[h264 @ 0b1155a0] concealing 559 DC, 559 AC, 559 MV errors in P frame
[h264 @ 098e5c80] RTP: missed 150 packets
[h264 @ 0af65740] error while decoding MB 48 31, bytestream (-15)
[h264 @ 0af65740] Cannot use next picture in error concealment
[h264 @ 0af65740] concealing 1121 DC, 1121 AC, 1121 MV errors in P frame
[h264 @ 098e5c80] RTP: missed 4 packets
[h264 @ 0ac79960] error while decoding MB 35 38, bytestream (-41)
[h264 @ 0ac79960] Cannot use next picture in error concealment
[h264 @ 0ac79960] concealing 574 DC, 574 AC, 574 MV errors in P frame

我使用 ffmpeg 将 RTSP 流转储到 avi 文件,并且没有错误。 C:\Users\Matlab>ffmpeg -i rtsp://192.168.1.67/gnz_media/main 123.avi

没有 H.264 解码错误。任何人都可以使用 ffmpeg api 帮助解决上述解码错误。

【问题讨论】:

请不要在多个 Stack Exchange 网站上询问 same question。 @tariq:你能做到以下几点:ffplay << RTSP STREAM >> 并在此处发布输出吗? ffplay 是 ffmpeg 工具包的一部分,但不确定它在 Windows 上的工作原理... 您只是对流进行解码或重新编码吗?它只是看起来像 ffmpeg 太忙编码,所以它只是跳过传入的数据包,这会导致错误。尝试使用较小的分辨率。 我没有对视频流进行编码。我收到一个 RTSP 流,对其进行解码,然后使用 OpenCV 显示。 我使用 ffmpeg 将 RTSP 流转储到 avi 文件,并且没有错误。 C:\Users\Matlab>ffmpeg -i rtsp://192.168.1.67/gnz_media/main 123.avi;谁能帮我理解为什么它会显示这种行为(在 c 程序中给出日志错误,并且在使用 ffmpeg.exe 命令将 RTSP 流转储到 avi 文件时完全没有错误)? 【参考方案1】:

如果您使用的是 UDP,则可能会丢帧 - 这是 UDP 设计的一部分,它注重速度而不是可靠性。丢失数据包是 H264 格式的一个严重问题,因为给定的数据包可能取决于它前面或后面的数据包(使用差异图像而不是发送完整的新图像)。 所以,使用 UDP 会产生很多错误,包括“RTP:miss XXX packet”。

通过将rtsp_transport="tcp" 选项传递给avformat_open_input,切换到更可靠但速度更慢的TCP。示例:

AVDictionary * opts = NULL;
av_dict_set(&opts, "rtsp_transport", "tcp", 0);
int error = avformat_open_input(&rtsp_format_context, "rtsp://your url here", NULL, &opts);
if (error < 0)
    ; // Connection error. Add your error handling here.

这将阻止数据包被丢弃,从而消除视频的损坏。

【讨论】:

我们如何使用 python 模块 python-opencv 设置 rtsp_transport="tcp" 选项。要捕获视频,我们添加行 cv2.VideoCapture("rtsp://%s:%s@%s/Streaming/Channels/1"),我们是否需要在视频捕捉功能。 @NishantKashyap 我没有使用过 OpenCV,但this blog 说只需将“?tcp”添加到 RTSP 网址。所以改为连接到rtsp://stream/?tcp 我宁愿使用 ffmpeg 来获取 mp4 格式的视频,而不会丢失任何数据包并且处理也更少,它也很容易在 html 视频播放器上播放和显示。试试这个ffmpeg -rtsp_transport tcp -i "rtsp://username:password@xxx.xx.xx.xx" -r 30 -vcodec copy -flags +global_header -map 0 -f mp4 -t 10 -y "video.mp4" 感谢您的回答。但是,我没有丢失数据包,而是完全丢失了视频帧。所以没有“拖尾”,而是会丢失整秒钟的视频。有什么建议吗?谢谢! @Phi 经过多天的广泛测试,相机没有问题,但 wifi 和流媒体能力才是罪魁祸首。那个或设备本身无法处理数据吞吐量,但不太可能。使用 TCP 不会导致帧“拖尾”或“撕裂”,但会完全丢弃帧(即不捕获部分帧)。使用 UDP,它会尽可能地保留部分帧,但这会导致这些帧的“拖尾”或“撕裂”。我们最终选择了 UDP,因为它至少显示部分帧而不是丢失整个视频块。【参考方案2】:

此问题由摄像头产生,请通过GANZ技术支持升级摄像头最新固件。摄像头不支持此h.264视频压缩。

【讨论】:

您是否遇到过同样的问题?您是如何更新 GANZ 相机的固件的

以上是关于来自 RTSP 流的 H.264 解码错误日志的主要内容,如果未能解决你的问题,请参考以下文章

为啥在使用 Android MediaPlayer 读取 H.264 编码的 rtsp 流时出现“不支持的格式”错误?

如何在 Java 环境中解码 H.264 视频帧

FFmpeg linux解包解码rtsp流编码h.264/h.265 mp4视频报错问题排查(没解决)

FFmpeg linux解包解码rtsp流编码h.264/h.265 mp4视频报错问题排查(没解决)

如何处理 cv::VideoCapture 解码错误?

H.264/AVC视频编解码技术详解十二解析H.264码流的宏块结构(下):H.264帧内编码宏块的预测结构