7

Currently, I am trying to use opencv to read a video from my Canon VB-H710F camera.

For this purpose I tried two different solutions:

SOLUTION 1: Read the stream from rtsp address

 VideoCapture cam ("rtsp://root:camera@10.0.4.127/stream/profile1=u");

 while(true)
  cam >> frame;

In this case I am using opencv to directly read from a stream encoded with in H264 (profile1), however this yields the same problem reported here http://answers.opencv.org/question/34012/ip-camera-h264-error-while-decoding/ As suggested in the previous question, I tried to disable FFMPEG support in opencv installation, which solved the h264 decoding errors but raised other problem. When accessing the stream with opencv, supported by gstreame, there is always a large delay associated. With this solution I achieve 15 FPS but I have a delay of 5 seconds, which is not acceptable considering that I need a real time application.

SOLUTION 2: Read the frames from http address while(true) { startTime=System.currentTimeMillis();

        URL url = new URL("h t t p://[IP]/-wvhttp-01-/image.cgi");
        URLConnection con = url.openConnection();
        BufferedImage image = ImageIO.read(con.getInputStream());   
        showImage(image);
        estimatedTime=System.currentTimeMillis()-startTime;
        System.out.println(estimatedTime);
        Thread.sleep(5);
}

This strategy simply grabs the frame from the url that the camera provides. The code is in Java but the results are the same in C++ with the curl library. This solution avoids the delay of the first solution however it takes little more than 100 ms to grab each frame, which means that I can only achieve on average 10 FPS.

I would like to know how can I read the video using c++ or another library developed in c++ ?

João Neves
  • 71
  • 1
  • 1
  • 3

3 Answers3

5

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

JoeC
  • 71
  • 2
  • 6
0

Personally, I suggest you to use ffmpeg to read rtsp streams from IP cameras, and then use openCV to read from decoded buffer from ffmpeg. ffmpeg has very good optimizations towards H.264 decoding, performance should not be a critical issue.

You can use ffmpeg binary to verify whether this can work correctly:

ffmpeg -i "rtsp://root:camera@10.0.4.127/stream/profile1=u" -vcodec copy -acodec none test.mp4

If test.mp4 can be played successfully, then it's definitely OK for you to integrate ffmpeg libs into your project.

Good luck!

JasonYang
  • 686
  • 7
  • 14
  • Thank for your answer. Despite being able to successfully record the video at 15 fps, this solution does not fit my purposes, since in your example the ffmpeg just copies the video to a file without decoding and in my case I need to decode in real-time. – João Neves Oct 17 '14 at 16:07
  • Yes, I understand you need to extract the frames and do processing on each frame. The ffmpeg example is a test of whether the input signal is correct for processing as well as can be correctly processed using ffmpeg. As you verified, you can now, you can start compiling ffmpeg libraries, and use ffmpeg lib for decoding the frames manually using codes, and the frames data will be available to you in the decoding pipeline. Various ffmpeg developing manual are available on the internet. – JasonYang Oct 18 '14 at 02:25
  • I have already tried that, but the problem remains since I can only access frames of 2 seconds in the past (I think that is related to the buffer size of ffmpeg). Do you know some way to decrease the size of this buffer while maintaining real-time decoding? I have already searched the web but I was not able to find any solution. Thank you again – João Neves Oct 18 '14 at 13:34
0

You can process each frame using ffmpeg as well. you need to create your own filter as per your requirement. https://trac.ffmpeg.org/wiki/FilteringGuide