sarxos / webcam-capture

The goal of this project is to allow integrated or USB-connected webcams to be accessed directly from Java. Using provided libraries users are able to read camera images and detect motion. Main project consist of several sub projects - the root one, which contains required classes, build-in webcam driver compatible with Windows, Linux and Mac OS, which can stream images as fast as your camera can serve them (up to 50 FPS). Main project can be used standalone, but user is able to replace build-in driver with different one - such as OpenIMAJ, GStreamer, V4L4j, JMF, LTI-CIVIL, FMJ, etc.
http://webcam-capture.sarxos.pl
MIT License
2.27k stars 1.11k forks source link

EOF detected, recreating MJPEG stream #287

Closed sarxos closed 9 years ago

sarxos commented 9 years ago

Issue from Omid Haghighatgoo:


hi I want to use your amazing sarxos project for getting images from an ip camera I used your sample code like this :

import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamPanel;
import com.github.sarxos.webcam.ds.ipcam.IpCamDeviceRegistry;
import com.github.sarxos.webcam.ds.ipcam.IpCamDriver;
import com.github.sarxos.webcam.ds.ipcam.IpCamMode;

import javax.swing.*;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by omid on 12/23/2014.
 */
public class second {

    static {
        Webcam.setDriver(new IpCamDriver());
    }

    public static void main(String[] args) throws MalformedURLException {
        URL url = new URL("http://192.168.1.6");
        IpCamDeviceRegistry.register("WGE-100-CB-5BB9", url, IpCamMode.PUSH);
        WebcamPanel panel = new WebcamPanel(Webcam.getWebcams().get(0));
        //    panel.setFPSLimit(1);
        JFrame f = new JFrame("test");
        f.add(panel);
        f.pack();
        f.setVisible(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

and my camera is this :

http://www.brickcom.com/products/DetailView.php?modelname=CB-100Ae

but the result is below message :

DEBUG c.g.s.webcam.ds.ipcam.IpCamDevice - EOF detected, recreating MJPEG stream

what is the problem ? I will really appreciate any help

thank you

sarxos commented 9 years ago

Please take a look at:

https://github.com/sarxos/webcam-capture/blob/master/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/IpCamDevice.java

This message is printed when EOFException is caught. This means most probably that end of stream has been reached unexpectedly when reading input. Is it possible to test this camera online? Does it work directly from web browser, or you get similar problems?

omidhaghighatgoo commented 9 years ago

it works fine with browser I also check my code with these urls : http://96.10.1.168 http://wmccpinetop.axiscam.net but I got same error does it related to memory or something like this ?

omidhaghighatgoo commented 9 years ago

I also checked this your sample :

    static {
        Webcam.setDriver(new IpCamDriver());
    }
    public static void main(String[] args) throws MalformedURLException {
        String name = "Test #255";
        URL url = new URL("http://ce3014.myfoscam.org:20054/videostream.cgi");
        IpCamMode mode = IpCamMode.PUSH;
        IpCamAuth auth = new IpCamAuth("user", "user");
        IpCamDeviceRegistry.register(name, url, mode, auth);
        Webcam w = Webcam.getWebcams().get(0);
        w.open();
        WebcamPanel panel = new WebcamPanel(w);
        JFrame f = new JFrame("Test #255 PUSH");
        f.add(panel);
        f.pack();
        f.setVisible(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

but the line w.open() never finished !! I mean when I debug this code , w.open() takes a lot of time and never finished correctly or by exception

omidhaghighatgoo commented 9 years ago

today I tried below code with your last release of libraries and I got video . public class Test {

    static {
        Webcam.setDriver(new IpCamDriver());
    }
    public static void main(String[] args) throws MalformedURLException {
        String name = "Test #255";
        String url = "http://ce3014.myfoscam.org:20054/videostream.cgi";
        IpCamMode mode = IpCamMode.PUSH;
        IpCamAuth auth = new IpCamAuth("user", "user");
        IpCamDeviceRegistry.register(name, url, mode, auth);
        Webcam w = Webcam.getWebcams().get(0);
        w.open();
        WebcamPanel panel = new WebcamPanel(w);
           panel.setFPSLimit(1);
        JFrame f = new JFrame("Test #255 PUSH");
        f.add(panel);
        f.pack();
        f.setVisible(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

but when I changed url to this : "http://192.168.1.6" some wrong thing happend Instead of library i download all open source code and test with them again I trace and trace until this line :

if (open.compareAndSet(false, true)) {
}

this line is open() method from Webcam class when the program goes into this line never get out of it !!! what does compareAndSet() do ? how can I solve this problem ?

sarxos commented 9 years ago

Hi @omidhaghighatgoo,

Sorry for late response. I was busy with preparations to Christmas Eve.

In regards to your issue:

I tested http://wmccpinetop.axiscam.net which points to MJPEG image available at http://wmccpinetop.axiscam.net/mjpg/video.mjpg and it's working well, though it's opening pretty slow (this is due to the low camera speed, connection, or network route speed).

287

The source code I used for this test:

import java.net.MalformedURLException;

import javax.swing.JFrame;

import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamPanel;
import com.github.sarxos.webcam.ds.ipcam.IpCamDeviceRegistry;
import com.github.sarxos.webcam.ds.ipcam.IpCamDriver;
import com.github.sarxos.webcam.ds.ipcam.IpCamMode;

public class Test {

    static {
        Webcam.setDriver(new IpCamDriver());
    }

    public static void main(String[] args) throws MalformedURLException {

        String name = "Test Issue #287";
        String url = "http://wmccpinetop.axiscam.net/mjpg/video.mjpg";
        IpCamMode mode = IpCamMode.PUSH;
        IpCamDeviceRegistry.register(name, url, mode);

        JFrame f = new JFrame(name);
        f.add(new WebcamPanel(Webcam.getDefault()));
        f.pack();
        f.setVisible(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

For the http://192.168.1.6 I'm getting Network Connection Error so it's obvious that API will not work with that.

And for the http://96.10.1.168 which points to the image at http://96.10.1.168/jpg/1/image.jpg, which is JPEG (not MJPEG) the PULL mode (the client pull out the JPG image every time) must be used instead of PUSH (server push new frame in MJPEG stream), the camera is working just perfectly. I'm getting more smooth image than in the previous one (but this is again due to the connection speed because PUSH is much faster than PULL).

287a

The source code I used for this test:

import java.net.MalformedURLException;

import javax.swing.JFrame;

import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamPanel;
import com.github.sarxos.webcam.ds.ipcam.IpCamDeviceRegistry;
import com.github.sarxos.webcam.ds.ipcam.IpCamDriver;
import com.github.sarxos.webcam.ds.ipcam.IpCamMode;

public class Test {

    static {
        Webcam.setDriver(new IpCamDriver());
    }

    public static void main(String[] args) throws MalformedURLException {

        String name = "Test Issue #287";
        String url = "http://96.10.1.168/jpg/1/image.jpg";
        IpCamMode mode = IpCamMode.PULL;
        IpCamDeviceRegistry.register(name, url, mode);

        JFrame f = new JFrame(name);
        f.add(new WebcamPanel(Webcam.getDefault()));
        f.pack();
        f.setVisible(true);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

You are asking what does the compareAndSet(boolean, boolean) do? The detailed answer can be found in Javadoc (this is AtomicBoolean available in all the Java versions starting from Java 5). This method compare if current atomic reference value equals the one in first argument and set its value to second argument if comparison is true. This operation is atomic and non-blocking so it can be safely used (and should be used) in multithreaded applications. For more details please take a look at Java Concurrency API. It's impossible for this method to block (because it has been designed to not block at all) and it's usually used to make sure that some operation will be executed once and only once, always. If your debugger points out that this method is blocking then I can assume that you have wrong source code (incorrect version) or the debugger is somehow configured incorrectly.

If you are using IP camera and open() method is blocking it's pretty commonly caused by the fact that API is waiting for the remote end to serve some content. It will block until timeout (like in regular web application) or to the moment when remote end send the response or close the socket connection.

omidhaghighatgoo commented 9 years ago

Thank you very very veeeeeeeeeeeeeeery much and *** HAPPY NEW YEAR *** I finally find the problem ! the problem was with URL . each camera has it's own URL that is specific and depends on brand and model i test these urls for my camera : url = ip address url = ip address:port and ... but none of them was correct unfortunately there wasn't any thing on manual or data sheet finally i found correct camera url on this site :

http://www.ispyconnect.com/man.aspx?n=Brickcom

sarxos commented 9 years ago

Great to hear good news :) I also wish you a Happy New Year! Take care, I'm closing this ticket.

betrand commented 9 years ago

Webcam webcam = Webcam.getDefault(); webcam.open(); BufferedImage bufferedImage = webcam.getImage(); LOG.info("BufferedImage", bufferedImage);

I get null printed what can I be doing wrong?

sarxos commented 9 years ago

@betrand what is your IP camera URL, are you using JPEG or MJPEG?

betrand commented 9 years ago

Thank you.Am on a windows machine with built in Camera. I have tried accessing the camera as belowLOG.info("Webcam name: webcam.getName()");I get Webcam name: Chicony USB 2.0 Camera 0Kind regardsSent from Yahoo Mail for iPadAt 11 Feb 2015 16:13:24, Bartosz Firyn wrote:@betrand what is your IP camera URL, are you using JPEG or MJPEG?

—Reply to this email directly or view it on GitHub.

sarxos commented 9 years ago

@betrand, thank you for clarification. This thread is about EOFs in MJPEG stream, so lets move this discussion to #308 you've created.

betrand commented 7 years ago

Hi Bartosz. It's been a long time I tried your API. Does it support Fingerprint capture and verification now?

Thank you and Kind regards Betrand Senior Java Architect/DeveloperEMB ERP ConsultantUptitek Ltd

sarxos commented 7 years ago

Hi @betrand,

Unfortunately I haven't found any way to reliably support finger print images. There is libfprint-java project, but it seems that not all finger print readers are supported. For example I was unable to use libfprint with a finger print reader embedded in my HP EliteBook ([138a:003c] Validity VFS471 Fingerprint Reader).

However, you may try it out yourself to check if maybe your finger print reader is supported.

betrand commented 7 years ago

I picked up SecuGen fingerprint reader though they have java SDK I thought I should try out your Lib to see if it will detect it as a camera device. If it does then I can go that direction