wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes Ip camera view Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Ip camera view " Watch "Ip camera view " New topic
Author

Ip camera view

Pauline Chevalier
Greenhorn

Joined: Mar 06, 2012
Posts: 7

hello,
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.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1511
Don't try to do something that you yourself don't understand, especially too many things. Go step by step.

Pauline Chevalier wrote:...a null pointer exception




This is how you get a null pointer exception. Missing is myObject that needs to be available.

Welcome to ranch.!


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Pauline Chevalier
Greenhorn

Joined: Mar 06, 2012
Posts: 7
I am trying to understand step by step. I think the exception is thrown in the connect() function at InputStream is = huc.getInputStream(). when I call
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.
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

I have written a program long time ago, to connect to an IP camera and to save the stream of jpg images into an AVI file. I'll look around and see if I can find anything to give you some hints.
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

Ok, I found it again. Basically it was a program using SWT which I compiled with GCJ into an executable .exe file. I'm not going to give you the entire thing but will drop some hints that may or may not be useful.

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
Greenhorn

Joined: Mar 06, 2012
Posts: 7
Thank you. I think what I want to do is different, I need a solution which doesn't use sockets. I want to get the DataInputStream by opening a connection on my HttpURLConnection like this

Pauline Chevalier
Greenhorn

Joined: Mar 06, 2012
Posts: 7
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://194.17.150.25/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 */
Pauline Chevalier
Greenhorn

Joined: Mar 06, 2012
Posts: 7
what really matter is thet the url I use corresponds to a web peg but my progrm needs a mjpg stream
Koen Aerts
Ranch Hand

Joined: Feb 07, 2012
Posts: 344

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
Greenhorn

Joined: Mar 06, 2012
Posts: 7
It works now. By adding axis-cgi/mjpg/video.cg at the end of the url, the camera sends me mjpeg stream and the display now is OK
Arjit Kapoor
Greenhorn

Joined: May 10, 2012
Posts: 1
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://194.17.150.25/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.
red sem
Greenhorn

Joined: Sep 06, 2012
Posts: 1
hello, the correct url to get the img:
http://194.17.150.25/axis-cgi/mjpg/video.cgi?camera=1&resolution=640x480
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.
in french:
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ip camera view
 
Similar Threads
works on WinXP jdk 1.6 but not Linux jdk 1.5
problem while dispalying from file
Problem with using getSubimage(x,y,w,h)
way to rotate without using Graphics2D.rotate()
Image smoothing