Time Lapse Movies

There are plenty of generally accessible webcams. Instead of just tuning in and watching, I wrote some perl scripts  to grab pictures at regular intervals and then put them together into time-lapse movies. I’m fond of Madison, Wisconsin, because I grew up there.

This Perl script generates a one-day movie from the King Hall, Lake Mendota cam:

#!/usr/bin/perl -w

# get_webcam_pics Bill Feiereisen, February 22, 2017
# Put this script in a file ending in .pl For example --> get_webcam_pics.pl
# Place it in a new directory. Execute it with ./get_webcam_pics.pl
# Patience! It runs for a long time depending on how many pictures and the wait interval

# Gets webcam pictures at regular intervals from public webcams and stores
# them for later processing into a time-lapse movie.
# Downloads from the chosen camera URL with curl.
# Creates a sequential filename for each picture and stores in the current directory.
# After the main loop calls ffmpeg to generate the movie from stored frames.
# You gotta have curl and ffmpeg installed on your system.
# You could do the downloading with wget if you don't have curl.

# identify script to the terminal.
  print "get_webcam_pics Bill Feiereisen February 22, 2017\n";

# Here's where this particular cam stores its files.
  $CAM_URL="http://agwx.soils.wisc.edu/soils-agwx-assets/uwex_agwx/images/webcam/fullsize.jpg";
  $CAM_NAME="Lake_Mendota";

# picture counter limit
# This is one day at five minute intervals.
  $ipic_max = 288; #How many pictures? Change to suit.
# sleep time
  $sleep_tics = 300; #This is 300 seconds, five minute interval. Change to suit.

# main picture gathering loop
  for ($ipic = 0; $ipic < $ipic_max; $ipic+=1) { # main loop
      $picture_name = "$CAM_NAME$ipic.jpg"; # create filename with sequential numbered files
      print "$picture_name\n"; # print something to the terminal so you know what's happening.
      system("curl -o $picture_name $CAM_URL;"); # get the picture and store it
      sleep $sleep_tics; #sleep for a while until the next picture is available.
  } #end picture gathering loop

# make movie with ffmpeg
# for this call use 15fps, start with file number 0, code at 1280x800
  system("ffmpeg -r 15 -start_number 0 -i $CAM_NAME%d.jpg -s 1280x800 -vcodec libx264 $CAM_NAME.mp4;");

# end of main program
  exit;