1

I am using CV::VideoCapture to capture frames from an IP camera. It works most of time, however, sometimes it reports the error:

[mjpeg @ 0x233aea0] overread 8

And when this error occurred, my program just stuck there. This might explain why. But how can I solve it in C++ code? Can OpenCV handle this error without terminate the program?

p.s. I found that if I didn't call CV::VideoCapture::read() immediately, but wait for a while, like 60 seconds, after CV::VideoCapture::open(), this error occurred everytime! Is it a bug of OpenCV?

#include <unistd.h>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

int main(int argc, char* argv[]) {
  // argv[1] is a valid url, like "http://xxxx/mjpg/video.mjpg"
  cv::VideoCapture cap(argv[1]);
  if (!cap.isOpened()) {
    std::cout << "Cannot Open Camera!" << std::endl;
    return -1;
  }
  // The error occures if I pause for a while.
  // But it is okay when I capture frames from video files intead of IP camera.
  sleep(60);
  while (static_cast<char>(cv::waitKey(1)) != 'q') {
    cv::Mat frame;
    cap >> frame;
    if (frame.empty()) break;
    cv::imshow("frame", frame);
  }
}
Community
  • 1
  • 1
wking
  • 1,293
  • 1
  • 16
  • 27
  • Check if [this](http://stackoverflow.com/questions/33352098/opencv-ip-camera-application-crashes-h264-0xxxxx-missing-picture-in-access-u) helps you... – tod Dec 12 '15 at 09:57
  • `But it is okay when I capture frames from video files intead of IP camera.` Because, that's a different case and it will be, most probably, also okay if you try if for a webcam :) These problems occur mostly with IP cam. – tod Dec 12 '15 at 10:00
  • Sorry but I am no good at http or rtsp. I tried "http://xxxx/mjpg/video.mjpg/ch1-s1?tcp", but I got another error, saying "GStreamer Plugin: Embedded video playback halted; module source reported: Not Found". – wking Dec 12 '15 at 10:09
  • Is it because my opencv was not built with ffmpeg support? Or I am not using the right address of IP camera? – wking Dec 12 '15 at 10:18

1 Answers1

1

I can't explain why but using the address http://xxxx/axis-cgi/mjpg/video.cgi instead of http://xxxx/mjpg/video.mjpg solved it! Can anyone provide some nice explanation here, or some links? Thanks!

wking
  • 1,293
  • 1
  • 16
  • 27