h264解碼異常處理(iOS)
阿新 • • 發佈:2019-02-03
<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; }