Read h264 stream from an IP camera

18,114

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

Share:
18,114
Admin
Author by

Admin

Updated on June 07, 2022

Comments

  • Admin
    Admin almost 2 years

    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:[email protected]/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++ ?