does anyone know how to develop a simple application for IP camera (Axis, D-link and heden) using Java language. I don't know how to view the IP camera in my GUI.
does anyone has the solution? This is the code i found but I can't make it work there is a null pointer exception when I try to get the stream of the camera.
getInputStream, nothing seems to work. Stepping through the code, the
inputSteam is null.How can I have
works. There is no problem with the value of huc it contains the right url.
First, you need to connect to the camera (socket) and send it a String to instruct it to start streaming back a continuous stream of images; usually in JPG format. You can then either display those images real-time or save them to a file such as AVI.
I don't know what the request string for your IP camera is, or whether it even works the same or similar, but below is a snippet of how I initiated the streaming process. Keep in mind this is some old code and now that I look back at it; it is not written very well but it should still be useful to illustrate the general process;
Then in a separate Thread, I keep reading the jpg images from the DataInputStream; each image is separated by a so called "boundary marker"; which is basically a specific string that indicates the start/end of an image, for instance "--video boundary--". Also in this thread I use flags (booleans) to manage the datastream (i.e. save jpg files, or stop the stream when user clicks a button or closes the app).
To close the datastream, simply call the close() methods on the DataInputStream and DataOutputStream instances.
I have removed a lot of code from the above snippets; what's left should be enough to give you a general idea of how it can be done. However, you IP camera might work differently. I wrote this code for the DLink DCS 900 and DCS 950 IP cameras and initially used packet sniffers to find out what kind of information was send and received from those cameras, such as camera settings; how to change those settings; how to restart the cameras, etc. Basically it was a bit of a reverse engineering project. At the time there was hardly any useful information online to do this kind of stuff.
Pauline Chevalier wrote:what really matter is thet the url I use corresponds to a web peg but my progrm needs a mjpg stream
If you have client software that came with the camera, or if the camera has a built-in web app to show live video, use that to start streaming video content. Use a packet sniffer (for instance www.wireshark.org) to figure out what is communicated between the client software (or your browser if camera has built-in web app) and the IP camera. It likely is some form of http based content. About your ImageFormatException; not sure what it could be but I can think of some reasons: 1) you somehow didn't capture or loose parts of the image binary content, 2) maybe it's a different image format you're getting back (not a jpg), 3) maybe you captured a wrong set of bytes from the input stream (i.e. entire wrong or just off by 1 byte or so).
Pauline Chevalier wrote:I tried a different url and it helped me to know that the problem came from my url. Then I tried a public cam url (http://126.96.36.199/view/index.shtml), the connection is OK but I have a new error message: com.sun.image.codec.jpeg.ImageFormatException: Not a JPEG file: starts with 0x3c 0x68. the exception is thrown by this line image = decoder.decodeAsBufferedImage(); . How can I treat this error? /*sorry for my bad english I am french */
hello pauline I am not able to connect my ip camera through your code can you help me please.
whene you recev the data you must separate the http header from the raw data, the data start after the string "contenent lenght: 25889" where 25889 is the size of the compressed jpeg img.
une foit ke tu te connect, tu doit va recevoir quelque text de la part de la camera qui correspandant au protocol http, aprés la chaine "contenent lenght: 60588" il y'au les donnée qui coresspont au image jpeg.