Creating a timelapse from a Foscam IP Camera

After purchasing a cheap Foscam FI8918W off eBay I couldn't resist creating a few simple timelapse videos. I created a simple perl script to help with the process. It allows me to specify

  • how many seconds I want the timelapse to last for
  • how long to wait between each shot

After its finished it uses ffmpeg to combine the jpegs into a timelapse movie.

Overall, I'm pretty happy with the results. The camera performs exceptionally well in low light conditions but seems unable to reliable pictures of outside during daylight - image are always washed out.

Anyhow, without further ado, the code is below:

use strict;
use warnings;
use Getopt::Long;

my $spacing       = 5;
my $captureLength = 30;
my $verbose       = 0;

my $result = GetOptions(
  "length=i"  => \$captureLength,    # numeric
  "spacing=i" => \$spacing,          # string
  "verbose"   => \$verbose

print "Capture every $spacing for a total of $captureLength\n\n";

my $startTime = time;
`mkdir -p $startTime`;
my $endTime = time + $captureLength;

$verbose && print "Started at $startTime and will finish at $endTime\n";

my $index = 0;

while (time < $endTime)
  $verbose && print "Time is " . time . "\n";
  my $output = sprintf("%s/image-%s-%05d.jpg", $startTime, $startTime, $index);
  `curl -u root:password -s -o $output`;
  $verbose && print "Saved $output\n";

# Now encode a video, naming it after the starttime.

`ffmpeg -r 30 -i $startTime/image-$startTime-%05d.jpg -b 4000k $startTime.mpeg`;
Comments (5) Trackbacks (0)
  1. Hi,
    I am also looking for such a solution. My firts idea was to process the cam’s snapshots which are ftp’ed to my NAS and then process them. Did you consider this? Advantage is that you can use the alarm functions of the foscam.
    Your script gives some more control, which I like. I also want to print the date and time in the picture. I think of using ‘convert’ for this (in the while-loop).
    My idea is to create a movie for each day. Compressing it to a mp4 movie safes a lot of space! I’m still experimenting which compression is acceptable (2-pass 800k seems ok)

    • I hadn’t considered an FTP approach, sounds interesting especially if that provides the alarm functions you mention. I’d love to see any updates you make, especially for tagging pictures with a date/time watermark.

  2. I’m a rookie to coding and the only need for Perl would be for the same purpose as you’ve written above. Thinking I could sneak by using your code, I downloaded Strawberry Perl for Windows and tried to run it. It doesn’t seem to work and with my limited understanding, I’m guessing it could be the use of ‘curl’.

    Any thoughts on how I could get this to run in Strawberry Perl or how to setup a similar function to create a timelapse from the Foscam camera in Windows?


  3. To watermark the image, try Image Magick. I ended up going VBScript versus Perl but was able to watermark my images with a timestamp with the following:

    “montage -geometry +0+0 -background white -label ” & chr(34) & strWatermark & chr(34) & ” -pointsize 20 ” & strSourceDir & objFile.FileName & “.jpg ” & strDestinationDir & objFile.FileName & “.jpg”

  4. SebecTec IP software to make time-lapse from an IP cam. Runs on Windows and stores the images to a local hard drive. Images can be sent to a website via FTP if desired. The time-lapse can be made each day and hourly. Running a second instance of the program allows you to make a third time-lapse that can span longer time periods. Has watermark, and on image weather option.


Leave a comment

No trackbacks yet.