See the download page to obtain this program
IPCamera allows images and video from a remote (Internet-connected) camera to be retrieved, stored, archived and displayed on a web page. Besides a Java program to retrieve and manipulate images, Perl programs are provided to organise images and videos. Sample HTML pages with a Perl script are also provided to display these.
To see what the code does, look at images and videos from the Loch Ard Sailing Club Web Camera.
The code has been tested with the Tenvis JPT3815W and Tenvis TH661 IP cameras (webcams), but may work with similar models by the same and other manufacturers. (Several essential identical cameras are marketed under different brand names.)
The core program for images is the GetCamera Java class that is used to retrieve one image from an IP camera. This can be used on its own, but offers more capabilities when used with the get_camera Perl script.
Some constants may optionally be changed in GetCamera, e.g. for adjustments in image colour balance, image size or labelling. The following constants must be adjusted before compiling and running the code:
Camera snapshots typically have the following size (width x height pixels): 640 x 480 (JPT3815W) or 1280 x 720 (TH661). After retrieving an image, its hue and saturation may be adjusted (various constants, default without change). The current day and time are placed in the bottom left corner of the image (font controlled by various constants). A thumbnail image (scale defined by a constant) is then produced. GetCamera might be called as follows:
java GetCamera http://mycamera.dyndns.org:81 image159.jpeg
This will create the following in the current directory: 'image159.jpeg' (full image) and 'image159s.jpeg' (thumbnail image, 's' for small).
The Perl program get_camera collects and organises images. The program aims to store only a limited number of images, numbered 001, 002, etc. Image 001 is always the latest, with earlier images being 'shuffled down' until they exceed the maximum image count. The number of images preserved is a program constant (16 by default). In addition, get_camera will store one image at noon for archival purposes in the archive directory.
The result of image retrieval is sent to standard output. If an image cannot be retrieved, an attempt is made to diagnose the problem. Assuming the webcam is behind a router, an attempt is made to contact the router web server using telnet. If this works, an attempt is made to contact the webcam web server using telnet. Since the telnet command may not produce a useful exit code, a timeout is used to determine whether the remote system is responding.
A warning email is sent to primary and secondary recipients. It is assumed that the email server uses TLS. The Perl modules Authen::SASL, IO::Socket::SSL and Net::SMTP can be installed from CPAN if necessary. To prevent a flurry of failure messages, email is sent intermittently (default every 3 hours).
Some constants may optionally be changed in subroutine customise, e.g. for adjustments in error reporting. Certain constants must be adjusted in get_camera before running it:
get_camera can be run from the command-line without parameters. (Option -u can be used to set the camera URL.) More typically it would be run on a scheduled basis (e.g. every half hour during daylight). On Windows this might be done using Task Scheduler, or on Unix with cron.
The Perl program get_video collects and organises videos. The program expects to store only two videos, one in the morning (video_am.mp4) and one in the afternoon (video_pm.mp4). It makes use of VLC (Video LAN Controller) to capture streaming videos in a file.
The result of video retrieval is sent to standard output. If a video cannot be retrieved, no attempt is made to diagnose or report the problem. (It is assumed that get_camera is also being used and that it will report any failures.)
Some constants may optionally be changed in subroutine customise, e.g. for adjustments in video capture. Certain constants must be adjusted in get_video before running it:
get_video can be run from the command-line without parameters. (Option -u can be used to set the camera URL.) More typically it would be run on a scheduled basis (e.g. mid-morning and mid-afternoon). On Windows this might be done using Task Scheduler, or on Unix with cron.
The web page images1.html is provided as a template that could be adapted to statically display the 16 most recent images.
The web page images2.html is provided as a template that could be adapted to generate the most recent images dynamically. This requires server-side execution of CGI scripts (e.g. as in the Apache web server). It calls the get_images CGI script with the path to where images can be found. The result is a dynamically generated HTML table (with 4 columns and 16 images by default). The script path and image path need to be set in the template web page provided.
The web page video.html is provided as a template that could be adapted to show the captured morning and afternoon videos.
This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation - either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful but without any warranty, without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details.
You may re-distribute this software provided you preserve its existing files. Bug reports should be sent to Ken Turner, who would also appreciate receiving any corrections and comments.
Version 1.0: First public release, Ken Turner, 18th February 2013
Version 2.0: Second public release, Ken Turner, 4th January 2019:
Version 2.0: Second public release, Ken Turner, 7th January 2019:
Up one level to Graphical Utilities