Search code examples
opencvffmpegh.264decodingip-camera

How to deal with cv::VideoCapture decode errors?


I'm streaming H264 content from an IP camera using the VideoCapture from OpenCV (compiled with ffmpeg support).

So far things work ok, but every once in a while I get decoding errors (from ffmpeg I presume):

[h264 @ 0x103006400] mb_type 137 in I slice too large at 26 10
[h264 @ 0x103006400] error while decoding MB 26 10
[h264 @ 0x103006400] negative number of zero coeffs at 25 5
[h264 @ 0x103006400] error while decoding MB 25 5
[h264 @ 0x103006400] cbp too large (421) at 35 13
[h264 @ 0x103006400] error while decoding MB 35 13
[h264 @ 0x103006400] mb_type 121 in P slice too large at 20 3
[h264 @ 0x103006400] error decoding MB 20 3

These messages show up in the console. Is there any clean way to listen to these ? I'd like to skip processing the glitchy frames.

Any hints/tips ?


Solution

  • recently i have solved the same problem and try to explain the steps i followed.

    i updated most recent opencv_ffmpeg.dll ( i renamed opencv_ffmpeg.dll to opencv_ffmpeg310.dll to use with OpenCV 3.1, also renamed same dll opencv_ffmpeg2412.dll to use with OpenCV 2.4.12

    by doing that, a basic capturing frames and display became successful without problem.but still the same problem if i do some image-processing or detection causes delay between capturing frames.

    to solve the second problem i used a thread to grab frames continiously and update a global Mat for processing.

    here you can find my test code ( it need some improvements like using mutex and lock memory when update the Mat)

    i hope the information will be useful ( sorry for my poor english )