h264解码异常处理(iOS)

来源:互联网 发布:windows snmp cpu oid 编辑:程序博客网 时间:2024/06/05 04:26

<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);">h264解码使用的是ffmpeg。</span>

先在网上找了个Demo,是播放本地文件的。那这个Demo修改,解码摄像头传过来的帧,log中却一直报错:

[h264 @ 0xd3e3a00] non-existing PPS 0 referenced[h264 @ 0xd3e3a00] decode_slice_header error[h264 @ 0xd3e3a00] no frame!

    还以为是这个Demo有问题,于是自己编译了最新的ffmpeg,参考其他文档,自己写了个解码的Demo,仍然是报这个错。后来参考官方的sample,每次解码器都进行了初始化操作,修改一下就正常播放了。

- (void)initDecoder {    avcodec_register_all();    frame = av_frame_alloc();    AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_H264);    codecCtx = avcodec_alloc_context3(codec);    int ret = avcodec_open2(codecCtx, codec, nil);    if (ret != 0){        NSLog(@"open codec failed :%d",ret);    }        frame = av_frame_alloc();    frame_count = 0;}


0 0
原创粉丝点击