axis ip camera live streaming using java

4.5k Views Asked by At

i have axis m1114 ip camera

i want to display live streaming as well as record streaming using java. i tried following code but frame rate is very low

please suggest some api gives me more frame rate and recording functionality.

import java.io.File;
import java.net.URL;
import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.*;
import com.googlecode.javacv.cpp.*;
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_calib3d.*;
import static com.googlecode.javacv.cpp.opencv_objdetect.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import  demo.authenticator.MyAuthenticator;
import java.net.Authenticator;
import java.net.MalformedURLException;
import org.jcodec.api.SequenceEncoder;
public class Demo {
    public static void main(String[] args) throws IOException {

        CanvasFrame CamWindow = new CanvasFrame("Camera");
        int i=0,j=0;

        URL url = null ;
        SequenceEncoder encoder=new SequenceEncoder(new File("video.mp4"));
        try {
            // Create a new URL object from the URL-string of our camera.
            url = new URL("http://192.168.168.92/axis-cgi/jpg/image.cgi");
        } catch (MalformedURLException m) {
            m.getMessage();
        }

        // Check if this camera requires authentication.
        // If so, then create and set the authenticator object.

            MyAuthenticator authenticator = new MyAuthenticator("root",
                        "pass");
    Authenticator.setDefault(authenticator);

    Long stime=System.currentTimeMillis();
        while(true){
            i++;
        //InputStream is = url.openStream();
        BufferedImage image = ImageIO.read(url);

        CamWindow.showImage(image);
     //   is.close();

       /* if(i<100)
        {
           encoder.encodeImage(image);
        }
        else 
        {
            if(j==0)
            {
                encoder.finish();
                j++;
                System.out.println("video saved");
                System.out.println((System.currentTimeMillis()-stime)/1000+"seconds");
            }

        }*/
        System.out.println((System.currentTimeMillis()-stime));
        }
    }
}
2

There are 2 best solutions below

0
On

The Axis camera API is here: http://www.axis.com/files/manuals/vapix_video_streaming_52937_en_1307.pdf

You need to use this: http:///axis-cgi/mjpg/video.cgi

instead of the image URL you have now. Getting a still image from the Axis camera will be very choppy. You need to use the Motion JPEG feed it spits out.

0
On

I have also gone through for these solutions and one of the good API i found is WEBCAM-Capture. I rate it good for some reasons

  • It is updated
  • It is open source
  • Many Examples
  • And most IMPORTANT its support from its developers is fast and accurate rather than other Camera supporting APIs. Hope this would help you.