【发布时间】:2018-09-19 06:18:18
【问题描述】:
我需要对来自实时 DVR 摄像机的 H264 流进行解码。 为了方便示例,我将来自 DVR 摄像机的 RAW 流存储在以下文件 (test.h264) 中:http://f.zins.com.br/test.h264
为了解码直播流,我遵循以下 ffmpeg 示例:https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/decode_video.c
如果我用 VLC 打开 .h264 测试,图像看起来很完美。 如果您使用 avformat_open_input 和 avformat_find_stream_info 使用 ffmpeg 解码 .h264 测试,图像看起来也很完美。
但如果我使用https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/decode_video.c 示例进行解码,图像都会失真。我认为这是因为 H264 流可以与音频一起出现。
开启ffmpeg的调试,显示很多如下错误:
[h264 @ 092a9b00] Invalid NAL unit 0, skipping.
[h264 @ 092a9b00] Invalid NAL unit 0, skipping.
[h264 @ 092a9b00] Invalid NAL unit 0, skipping.
[h264 @ 092a9b00] error while decoding MB 16 1, bytestream -28
[h264 @ 092a9b00] Invalid NAL unit 8, skipping.
[h264 @ 092a9b00] Invalid NAL unit 8, skipping.
[h264 @ 092a9b00] Invalid NAL unit 8, skipping.
有没有办法让我只过滤直播中的视频并忽略音频? 否则,是否有任何解决方案可以使用 decode_video.c 示例解码 test.h264 而不会扭曲帧?
【问题讨论】:
-
.h264 应该是原始流并且不包含音频。这是什么,是具有单个流的 MPEG-PS。 Remux 到原始流:
ffmpeg -i test.h264 -c copy raw.h264并使用它。 -
我已经这样做了,而且效果很好。问题是我不能对直播做同样的事情。在直播中,我得到的字节与它们存储在 test.h264 中的字节完全相同,但我有这些问题需要解码。
-
因此,您需要使用 mpegps 解复用和读取数据包
-
或者,您可以将直播流包装在自定义 AVIOContext 中,类似于 this example。
-
@Alex Cohn,效果很好。非常感谢。
标签: ffmpeg libavcodec libav