• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ip camera view

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.!
 
Pauline Chevalier
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 344
Oracle Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 344
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 344
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic