Read h264 stream from IP camera

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

To this end, I tried two different solutions:

SOLUTION 1: Reading a stream from an rtsp address

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

In this case, I use opencv to read directly from the stream encoded in H264 (profile1), however this gives the same problem that was 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 resolved h264 decoding errors, but posed another problem. There is always a long delay when accessing a stream with opencv supported by gstreame. With this solution, I achieve 15 FPS, but I have a delay of 5 seconds, which is unacceptable, given that I need a real-time application.

SOLUTION 2: reading frames from an http address while (true) {= System.currentTimeMillis starting span ();

  URL url = new URL("http://[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 captures the frame from the URL that the camera provides. The code is in Java, but the results in C ++ are the same as the curl library. This solution avoids the delay of the first solution, however, no more than 100 ms is required for each frame, which means that I can only achieve an average of 10 FPS.

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

+5
source share
3 answers

I struggled with similar problems and thought I solved some of your problems using libVLC with OpenCV. FFMPEG seems to have had problems with H264 decoding incorrectly, plus newer versions (2.4.11) seem to have the TCP fix that already exists for FFMPEG. Anyway, I use MS Visual Studio on Windows 7 and 8.1.

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

+4
source

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

You can use the ffmpeg binary to verify that it works 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 you definitely need to integrate ffmpeg libs into your project.

Good luck

0
source

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

0
source

Source: https://habr.com/ru/post/1204005/


All Articles