Error while decoding camera stream video frame using FFMpeg iOS
I have an app, In which I am decoding video frames coming from ip camera, but the method avcodec_decode_video2(m_pCodecCtx, m_pFrame, &consumed_bytes, &avpkt);
present in avcodec.h
generating bad_access, I can't figure out what is wrong.
This app was working fine with old libraries FFMpeg, but by apple policy, in order to publish app it support arm64, so I updated my libraries to support arm64 and after that this issue occurred.
Here is the screenshot
While bad_access app is generating the following log:
[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
Complete error log : https://drive.google.com/file/d/0B-Nh7ci6wLX0OVlxaXV4aGpJems/view?usp=sharing
Crash Log : http://crashes.to/s/6765d63b540
Note: If you need any thing else, please comment.
I resolved my issue, The problem was with depreciated method avcodec_alloc_frame()
.
I was using the following code in constructor
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];
Then I eventually updated my header files, afterward I got warnings about depreciation of method avcodec_alloc_frame()
so, I updated it to av_frame_alloc()
and it worked flawlessly!