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`;