Ask Your Question
6

ip camera h264 error while decoding

asked 2014-05-24 06:46:00 -0500

SunPuzzle gravatar image

updated 2014-05-24 06:54:42 -0500

Capture video from network camera.

VideoCapture cam0("rtsp://admin:12345@192.168.1.65/MPEG-4/ch1/main/av_stream ");

if (!cam0.isOpened()){
    std::cout << "camera open faild";
    return -1;
}

Mat cam_frame;
do{
    cam0 >> cam_frame;
    imshow("output_1", cam_frame);
    if (cvWaitKey(1) == 27) break;
} while (!cam_frame.empty());
return 0;

It's work, but some frames have bug.

Console:

[h264 @ 00000000030afaa0] error while decoding MB 59 10, bytestream (-9)

[h264 @ 00000000055e7420] left block unavailable for requested intra4x4 mode -1 at 0 14 image description

edit retag flag offensive close merge delete

Comments

take a look at my answer

sturkmen gravatar imagesturkmen ( 2016-03-20 03:02:11 -0500 )edit

3 answers

Sort by » oldest newest most voted
1

answered 2015-04-23 21:25:53 -0500

klauski gravatar image

I know three ways to reduce such problem.

First, create new thread to grab frame and save the frame into your queue from the thread to process your algorithm such as image enhancement, feature calculation or displaying. Moreover, you could adjust thread priorities if necessary. Then you can get much better frames.

Second, if there is network problem, you can rebuild opencv library after fix some codes in cap_ffmpeg_impl.hpp which is one of the sources for opencv_highgui module. There are two ways of RTSP protocol, over TCP and over UDP. Other people have said opencv adapted only RTSP over UDP, which doesn't keep reliability. The stream using UDP can be always lost. In the function CvCapture_FFMPEG::open in cap_ffmpeg_impl.hpp, you can add several lines (see http://www.qapit.com/qap/opencv-rtsp-...). And rebuild opencv.

OR, if your situation doesn't require a scenario of getting full good stream , you can drop such screwed frames by comparing between frames. I use this way and it seems to work well. I attach some codes as follows,

qm->clear(); // qm is a queue storing frames as I said in first way. 
while (1) {
    frmPrv = qm->safe_pop(); // get one frame.
    // Check whether grabbed frames are bad or not.
    frmNxt = qm->safe_pop();
    cv::absdiff(frmPrv, frmNxt, frmTmp);
    double sum_m = cv::sum(frmTmp)[0];
    double dm = sum_m / (frmTmp.cols * frmTmp.rows);
    if (dm < 32 /* you can choose threshold */) break;
}
edit flag offensive delete link more
1

answered 2014-06-11 09:55:43 -0500

dro gravatar image

Try rebuilding OpenCV without FFMPEG support, but with GStreamer enabled. Then, ensure you have all of the GStreamer plugins installed (good, bad, ugly) and gstreamer-ffmpeg (if you're in Linux, not sure how to get these plugins/libraries in other OSes).

I had the same problem with OpenCV 2.4.9 on Ubuntu 14.04, built with FFMPEG enabled. I tried the FFMPEG library versions in the Ubuntu repository (libavcodec 54.35.0, libavdevice 53.2.0, libavfilter 3.3.0, libavformat 54.20.4, libavutil 52.3.0, libavresample 1.0.1). I also tried with the latest FFMPEG libraries manually compiled with libx264 support, but was still seeing these same h264 decoding failures in my RTSP H264 stream (from an AXIS video encoder). However, I just rebuilt OpenCV without FFMPEG support and the H264 decoding errors have disappeared.

edit flag offensive delete link more

Comments

Hi,

Do you have OpenCV2.4.9 library which was built without FFMPEG support? I need the jar to try on Windows 7 64 bit. Would you please send the jar to this thread as an attachment or would you may email to me?

erohan gravatar imageerohan ( 2014-10-26 17:15:12 -0500 )edit

I also compiled OpenCV2.4.9 under Ubuntu 14.04 without FFMEG support but while trying to render Video data through RTSP stream CPU usage raises more that 100% and computer gave no response.

After a research, i found that GStream codecs is no more supported from Ubuntu 14.04. I also ignored this situation and although i installed gstream bad-uglu-good codecs, CPU again went to over 100% and a dedlock occurred. So, i install GStream full compatible Ubuntu 12.04 LTS and compiled OpenCV2.4.9 without FFMPEG support also on it. I was carefull about not to install gstream1, i installed gstream0 codecs. After that i gained the 1920x1080 high reolution video stream from my ip camera. It is brillant and has only 1/2 second delay.

erohan gravatar imageerohan ( 2014-11-10 07:00:17 -0500 )edit

Thanks Man this worked on the machine in which i was working and it was a really simple solution. :)

juangilopez gravatar imagejuangilopez ( 2015-08-27 17:41:28 -0500 )edit
0

answered 2015-07-13 09:59:35 -0500

joecmama gravatar image

I struggled with similar issues and think I have solved some of your problems using libVLC with OpenCV. FFMPEG seemed to have issues of not decoding H264 properly, plus the newer versions (2.4.11) seemed to have the TCP fix in there already for FFMPEG. Anyways, I use MS Visual Studio on Windows 7 and 8.1.

Details are given here: http://answers.opencv.org/question/65932

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-05-24 06:46:00 -0500

Seen: 25,533 times

Last updated: Jul 13 '15