使用 FFMpeg 解码相机流视频帧时出错 iOS

Error while decoding camera stream video frame using FFMpeg iOS

我有一个应用程序,我在其中解码来自网络摄像机的视频帧,但是 avcodec.h 中存在的方法 avcodec_decode_video2(m_pCodecCtx, m_pFrame, &consumed_bytes, &avpkt); 生成 bad_access,我无法弄清楚怎么了。

这个应用程序在旧库 FFMpeg 上运行良好,但根据 Apple 政策,为了发布它支持 arm64 的应用程序,所以我更新了我的库以支持 arm64,之后出现了这个问题。

截图如下

当 bad_access 应用生成以下日志时:

[h264 @ 0x1071400] sps_id 12 out of range
[h264 @ 0x1071400] pps_id 417 out of range
[h264 @ 0x1071400] sps_id 3 out of range
[h264 @ 0x1071400] sps_id 32 out of range
[h264 @ 0x1071400] sps_id 6 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 32 out of range
[h264 @ 0x1071400] sps_id 1 out of range
[h264 @ 0x1071400] sps_id 3 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 32 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 1 out of range
[h264 @ 0x1071400] sps_id 1 out of range
[h264 @ 0x1071400] sps_id 1 out of range
[h264 @ 0x1071400] sps_id 1 out of range
[h264 @ 0x1071400] sps_id 1 out of range
[h264 @ 0x1071400] sps_id 1 out of range
[h264 @ 0x1071400] sps_id 1 out of range
[h264 @ 0x1071400] sps_id 2 out of range
[h264 @ 0x1071400] sps_id 2 out of range
[h264 @ 0x1071400] sps_id 2 out of range
[h264 @ 0x1071400] sps_id 2 out of range
[h264 @ 0x1071400] sps_id 2 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 32 out of range
[h264 @ 0x1071400] sps_id 3 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 1 out of range
[h264 @ 0x1071400] sps_id 1 out of range
[h264 @ 0x1071400] sps_id 1 out of range
[h264 @ 0x1071400] sps_id 1 out of range
[h264 @ 0x1071400] sps_id 1 out of range
[h264 @ 0x1071400] sps_id 1 out of range
[h264 @ 0x1071400] sps_id 1 out of range
[h264 @ 0x1071400] sps_id 2 out of range
[h264 @ 0x1071400] sps_id 2 out of range
[h264 @ 0x1071400] sps_id 2 out of range
[h264 @ 0x1071400] sps_id 2 out of range
[h264 @ 0x1071400] sps_id 2 out of range
[h264 @ 0x1071400] pps_id 418 out of range
[h264 @ 0x1071400] Partitioned H.264 support is incomplete
[h264 @ 0x1071400] sps_id 6 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 1 out of range
[h264 @ 0x1071400] non-existing PPS 3 referenced
[h264 @ 0x1071400] decode_slice_header error
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] slice type 10 too large at 0 0
[h264 @ 0x1071400] decode_slice_header error
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] non-existing PPS 2 referenced
[h264 @ 0x1071400] decode_slice_header error
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] slice type 29 too large at 0 0
[h264 @ 0x1071400] decode_slice_header error
[h264 @ 0x1071400] sps_id 2 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] sps_id 0 out of range
[h264 @ 0x1071400] slice type 32 too large at 0 0
[h264 @ 0x1071400] decode_slice_header error
[h264 @ 0x1071400] slice type 32 too large at 0 0
[h264 @ 0x1071400] decode_slice_header error
[h264 @ 0x1071400] slice type 32 too large at 0 0
[h264 @ 0x1071400] decode_slice_header error
[h264 @ 0x1071400] slice type 32 too large at 0 0

完整的错误日志: https://drive.google.com/file/d/0B-Nh7ci6wLX0OVlxaXV4aGpJems/view?usp=sharing

崩溃日志: http://crashes.to/s/6765d63b540

注:如有其他需要,请留言。

我解决了我的问题,问题出在折旧方法 avcodec_alloc_frame()

我在构造函数中使用了以下代码

    m_pCodecCtx = avcodec_alloc_context3(m_pCodec);
    if(m_pCodecCtx == NULL)
    {
        NSLog(@"if(pCodecCtx == NULL)\n");
        return ;
    }  
   [g_Lock lock];
    //¥Úø™codec°£»Áπ˚¥Úø™≥…𶵃ª∞£¨∑÷≈‰AVFrame£     
    if(avcodec_open2(m_pCodecCtx, m_pCodec, NULL) >= 0)     
    {     
        m_pFrame = avcodec_alloc_frame();   /* Allocate video frame   */

    }
    [g_Lock unlock];

然后我最终更新了我的头文件,之后我收到了关于方法贬值的警告 avcodec_alloc_frame() 所以,我将它更新为 av_frame_alloc() 并且它完美地工作了!