Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Read h264 frame from IP Camera feed: Java version

I have been able to connect to and open an rstp h264 IP camera stream, and grab the first frame. However, when I try to retrieve() or read() the image, I'm given a null pointer exception.

public class MotionDetect {
    public static void main(String[] args) {
        Mat image=null;
        int i=0;

        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        VideoCapture capture = new VideoCapture("rtsp://169.254.71.156/axis-media/media.amp");

        double propid=0;
        if (capture.isOpened()) {
            System.out.println("Video is captured");
            int x=0;
            while (x<18) {
                x=x+1;
                propid=capture.get(x);
                System.out.println("Property Id is " + x + " value ="+ propid);
            }
            // grab 10 frames as a test
            while (i<10) {
            //capture.read(image);
            if (capture.grab()) {
                System.out.println("Frame was grabbed, i=" + i);}
            try {
                //capture.retrieve(image); //same results as .read()
                capture.read(image);    
            } catch (Exception e) {
                System.out.println("Null Pointer Exception during Read");
            }   
            i=i+1;
          }
        }
        capture.release();
        System.out.println("VideoCapture is released"); 
    }
}

The output is;

Video is captured
Property Id is 1 value =0.0
Property Id is 2 value =1.1111111111111112E-5
Property Id is 3 value =704.0
Property Id is 4 value =480.0
Property Id is 5 value =29.97002997002997
Property Id is 6 value =0.0
Property Id is 7 value =-3.0713859596586E15
Property Id is 8 value =0.0
Property Id is 9 value =0.0
Property Id is 10 value =0.0
Property Id is 11 value =0.0
Property Id is 12 value =0.0
Property Id is 13 value =0.0
Property Id is 14 value =0.0
Property Id is 15 value =0.0
Property Id is 16 value =0.0
Property Id is 17 value =0.0
Property Id is 18 value =0.0
Frame was grabbed, i=0
Null Pointer Exception during Read
Frame was grabbed, i=1
Null Pointer Exception during Read
Frame was grabbed, i=2
Null Pointer Exception during Read
Frame was grabbed, i=3
Null Pointer Exception during Read
Frame was grabbed, i=4
Null Pointer Exception during Read
Frame was grabbed, i=5
Null Pointer Exception during Read
Frame was grabbed, i=6
Null Pointer Exception during Read
Frame was grabbed, i=7
Null Pointer Exception during Read
Frame was grabbed, i=8
Null Pointer Exception during Read
Frame was grabbed, i=9
Null Pointer Exception during Read
VideoCapture is released

I've been reviewing the ip camera threads, and by the point capture is successful, the reading seems to be a non-issue.

I ran the properties to identify any odd values, and I note that while I've set my camera to 680x480, it is registering 704x480.

The same code (adjusted for an mjpeg feed) will connect and open when the camera is producing MJPEG, but will not register a successful .grab()

What am I doing wrong on my read (or retrieve)?

Read h264 frame from IP Camera feed: Java version

I have been able to connect to and open an rstp h264 IP camera stream, and grab the first frame. However, when I try to retrieve() or read() the image, I'm given a null pointer exception.

public class MotionDetect {
    public static void main(String[] args) {
        Mat image=null;
        int i=0;

        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        VideoCapture capture = new VideoCapture("rtsp://169.254.71.156/axis-media/media.amp");

        double propid=0;
        if (capture.isOpened()) {
            System.out.println("Video is captured");
            int x=0;
            while (x<18) {
                x=x+1;
                propid=capture.get(x);
                System.out.println("Property Id is " + x + " value ="+ propid);
            }
            // grab 10 frames as a test
            while (i<10) {
            //capture.read(image);
            if (capture.grab()) {
                System.out.println("Frame was grabbed, i=" + i);}
            try {
                //capture.retrieve(image); //same results as .read()
                capture.read(image);    
            } catch (Exception e) {
                System.out.println("Null Pointer Exception during Read");
            }   
            i=i+1;
          }
        }
        capture.release();
        System.out.println("VideoCapture is released"); 
    }
}

The output is;

Video is captured
Property Id is 1 value =0.0
Property Id is 2 value =1.1111111111111112E-5
Property Id is 3 value =704.0
Property Id is 4 value =480.0
Property Id is 5 value =29.97002997002997
Property Id is 6 value =0.0
Property Id is 7 value =-3.0713859596586E15
Property Id is 8 value =0.0
Property Id is 9 value =0.0
Property Id is 10 value =0.0
Property Id is 11 value =0.0
Property Id is 12 value =0.0
Property Id is 13 value =0.0
Property Id is 14 value =0.0
Property Id is 15 value =0.0
Property Id is 16 value =0.0
Property Id is 17 value =0.0
Property Id is 18 value =0.0
Frame was grabbed, i=0
Null Pointer Exception during Read
Frame was grabbed, i=1
Null Pointer Exception during Read
Frame was grabbed, i=2
Null Pointer Exception during Read
Frame was grabbed, i=3
Null Pointer Exception during Read
Frame was grabbed, i=4
Null Pointer Exception during Read
Frame was grabbed, i=5
Null Pointer Exception during Read
Frame was grabbed, i=6
Null Pointer Exception during Read
Frame was grabbed, i=7
Null Pointer Exception during Read
Frame was grabbed, i=8
Null Pointer Exception during Read
Frame was grabbed, i=9
Null Pointer Exception during Read
VideoCapture is released

The "capture" value during the run is VideoCapture(id=18)

I've been reviewing the ip camera threads, and by the point capture is successful, the reading seems to be a non-issue.

I ran the properties to identify any odd values, and I note that while I've set my camera to 680x480, it is registering 704x480.

The same code (adjusted for an mjpeg feed) will connect and open when the camera is producing MJPEG, but will not register a successful .grab()

What am I doing wrong on my read (or retrieve)?

click to hide/show revision 3
Removed extraneous lines

Read h264 frame from IP Camera feed: Java version

I have been able to connect to and open an rstp h264 IP camera stream, and grab the first frame. However, when I try to retrieve() or read() the image, I'm given a null pointer exception.

public class MotionDetect {
    public static void main(String[] args) {
        Mat image=null;
        int i=0;

        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        VideoCapture capture = new VideoCapture("rtsp://169.254.71.156/axis-media/media.amp");

        double propid=0;
        if (capture.isOpened()) {
            System.out.println("Video is captured");
            int x=0;
            while (x<18) {
                x=x+1;
                propid=capture.get(x);
                System.out.println("Property Id is " + x + " value ="+ propid);
            }
            // grab 10 frames as a test
            while (i<10) {
            //capture.read(image);
            if (capture.grab()) {
                System.out.println("Frame was grabbed, i=" + i);}
            try {
                //capture.retrieve(image); //same results as .read()
                capture.read(image);    
            } catch (Exception e) {
                System.out.println("Null Pointer Exception during Read");
            }   
            i=i+1;
          }
        }
        capture.release();
        System.out.println("VideoCapture is released"); 
    }
}

The output is;

Video is captured
Property Id is 1 value =0.0
Property Id is 2 value =1.1111111111111112E-5
Property Id is 3 value =704.0
Property Id is 4 value =480.0
Property Id is 5 value =29.97002997002997
Property Id is 6 value =0.0
Property Id is 7 value =-3.0713859596586E15
Property Id is 8 value =0.0
Property Id is 9 value =0.0
Property Id is 10 value =0.0
Property Id is 11 value =0.0
Property Id is 12 value =0.0
Property Id is 13 value =0.0
Property Id is 14 value =0.0
Property Id is 15 value =0.0
Property Id is 16 value =0.0
Property Id is 17 value =0.0
Property Id is 18 value =0.0
Frame was grabbed, i=0
Null Pointer Exception during Read
Frame was grabbed, i=1
Null Pointer Exception during Read
Frame was grabbed, i=2
Null Pointer Exception during Read
Frame was grabbed, i=3
Null Pointer Exception during Read
Frame was grabbed, i=4
Null Pointer Exception during Read
Frame was grabbed, i=5
Null Pointer Exception during Read
Frame was grabbed, i=6
Null Pointer Exception during Read
Frame was grabbed, i=7
Null Pointer Exception during Read
Frame was grabbed, i=8
Null Pointer Exception during Read
Frame was grabbed, i=9
Null Pointer Exception during Read
VideoCapture is released

The "capture" value during the run is VideoCapture(id=18)

I've been reviewing the ip camera threads, and by the point capture is successful, the reading seems to be a non-issue.

I ran the properties to identify any odd values, and I note that while I've set my camera to 680x480, it is registering 704x480.

The same code (adjusted for an mjpeg feed) will connect and open when the camera is producing MJPEG, but will not register a successful .grab()

What am I doing wrong on my read (or retrieve)?

click to hide/show revision 4
retagged

updated 2013-11-21 02:45:02 -0600

berak gravatar image

Read h264 frame from IP Camera feed: Java version

I have been able to connect to and open an rstp h264 IP camera stream, and grab the first frame. However, when I try to retrieve() or read() the image, I'm given a null pointer exception.

public class MotionDetect {
    public static void main(String[] args) {
        Mat image=null;
        int i=0;

        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        VideoCapture capture = new VideoCapture("rtsp://169.254.71.156/axis-media/media.amp");

        double propid=0;
        if (capture.isOpened()) {
            System.out.println("Video is captured");
            int x=0;
            while (x<18) {
                x=x+1;
                propid=capture.get(x);
                System.out.println("Property Id is " + x + " value ="+ propid);
            }
            // grab 10 frames as a test
            while (i<10) {
            if (capture.grab()) {
                System.out.println("Frame was grabbed, i=" + i);}
            try {
                //capture.retrieve(image); //same results as .read()
                capture.read(image);    
            } catch (Exception e) {
                System.out.println("Null Pointer Exception during Read");
            }   
            i=i+1;
          }
        }
        capture.release();
        System.out.println("VideoCapture is released"); 
    }
}

The output is;

Video is captured
Property Id is 1 value =0.0
Property Id is 2 value =1.1111111111111112E-5
Property Id is 3 value =704.0
Property Id is 4 value =480.0
Property Id is 5 value =29.97002997002997
Property Id is 6 value =0.0
Property Id is 7 value =-3.0713859596586E15
Property Id is 8 value =0.0
Property Id is 9 value =0.0
Property Id is 10 value =0.0
Property Id is 11 value =0.0
Property Id is 12 value =0.0
Property Id is 13 value =0.0
Property Id is 14 value =0.0
Property Id is 15 value =0.0
Property Id is 16 value =0.0
Property Id is 17 value =0.0
Property Id is 18 value =0.0
Frame was grabbed, i=0
Null Pointer Exception during Read
Frame was grabbed, i=1
Null Pointer Exception during Read
Frame was grabbed, i=2
Null Pointer Exception during Read
Frame was grabbed, i=3
Null Pointer Exception during Read
Frame was grabbed, i=4
Null Pointer Exception during Read
Frame was grabbed, i=5
Null Pointer Exception during Read
Frame was grabbed, i=6
Null Pointer Exception during Read
Frame was grabbed, i=7
Null Pointer Exception during Read
Frame was grabbed, i=8
Null Pointer Exception during Read
Frame was grabbed, i=9
Null Pointer Exception during Read
VideoCapture is released

The "capture" value during the run is VideoCapture(id=18)

I've been reviewing the ip camera threads, and by the point capture is successful, the reading seems to be a non-issue.

I ran the properties to identify any odd values, and I note that while I've set my camera to 680x480, it is registering 704x480.

The same code (adjusted for an mjpeg feed) will connect and open when the camera is producing MJPEG, but will not register a successful .grab()

What am I doing wrong on my read (or retrieve)?

click to hide/show revision 5
retagged

updated 2013-11-21 02:45:04 -0600

berak gravatar image

Read h264 frame from IP Camera feed: Java version

I have been able to connect to and open an rstp h264 IP camera stream, and grab the first frame. However, when I try to retrieve() or read() the image, I'm given a null pointer exception.

public class MotionDetect {
    public static void main(String[] args) {
        Mat image=null;
        int i=0;

        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        VideoCapture capture = new VideoCapture("rtsp://169.254.71.156/axis-media/media.amp");

        double propid=0;
        if (capture.isOpened()) {
            System.out.println("Video is captured");
            int x=0;
            while (x<18) {
                x=x+1;
                propid=capture.get(x);
                System.out.println("Property Id is " + x + " value ="+ propid);
            }
            // grab 10 frames as a test
            while (i<10) {
            if (capture.grab()) {
                System.out.println("Frame was grabbed, i=" + i);}
            try {
                //capture.retrieve(image); //same results as .read()
                capture.read(image);    
            } catch (Exception e) {
                System.out.println("Null Pointer Exception during Read");
            }   
            i=i+1;
          }
        }
        capture.release();
        System.out.println("VideoCapture is released"); 
    }
}

The output is;

Video is captured
Property Id is 1 value =0.0
Property Id is 2 value =1.1111111111111112E-5
Property Id is 3 value =704.0
Property Id is 4 value =480.0
Property Id is 5 value =29.97002997002997
Property Id is 6 value =0.0
Property Id is 7 value =-3.0713859596586E15
Property Id is 8 value =0.0
Property Id is 9 value =0.0
Property Id is 10 value =0.0
Property Id is 11 value =0.0
Property Id is 12 value =0.0
Property Id is 13 value =0.0
Property Id is 14 value =0.0
Property Id is 15 value =0.0
Property Id is 16 value =0.0
Property Id is 17 value =0.0
Property Id is 18 value =0.0
Frame was grabbed, i=0
Null Pointer Exception during Read
Frame was grabbed, i=1
Null Pointer Exception during Read
Frame was grabbed, i=2
Null Pointer Exception during Read
Frame was grabbed, i=3
Null Pointer Exception during Read
Frame was grabbed, i=4
Null Pointer Exception during Read
Frame was grabbed, i=5
Null Pointer Exception during Read
Frame was grabbed, i=6
Null Pointer Exception during Read
Frame was grabbed, i=7
Null Pointer Exception during Read
Frame was grabbed, i=8
Null Pointer Exception during Read
Frame was grabbed, i=9
Null Pointer Exception during Read
VideoCapture is released

The "capture" value during the run is VideoCapture(id=18)

I've been reviewing the ip camera threads, and by the point capture is successful, the reading seems to be a non-issue.

I ran the properties to identify any odd values, and I note that while I've set my camera to 680x480, it is registering 704x480.

The same code (adjusted for an mjpeg feed) will connect and open when the camera is producing MJPEG, but will not register a successful .grab()

What am I doing wrong on my read (or retrieve)?