Timelapse - an alternative howto.

A place for discussion of topics that are not specific to ZoneMinder. This could include Linux, Video4Linux, CCTV cameras or any other topic.
Post Reply
Flasheart
Posts: 342
Joined: Thu Jul 06, 2006 2:27 pm

Timelapse - an alternative howto.

Post by Flasheart »

We're having a new building built and I wanted to make a timelapse movie of the process as something cute to show my bosses and to give the builders as a promotion tool.

First I looked at Zoneminder, setting up the camera (an axis 211) as normal and using a fps of 0.02 but I had problems getting it working well, and I wanted the whole of the external stage (4-6 weeks) in one movie.

So I came up with this method;

Create a directory on your server somewhere.

mkdir /timelapse

Setup a crontab entry to run a simple perl script every X minutes (I'm using five mins which condenses a day into about 3-5 seconds)

crontab -e
*/5 * * * * /timelapse/get_timelapse.pl


Create that perl script;

jed /timelapse/get_timelapse.pl

Code: Select all

#!/usr/bin/perl
# Fetches a remote image and numbers it sequentially to be stitched together later by ffmpeg or similar ot make a movie.

open(IN,"</timelapse/counter.txt");
my $cnt = <IN>;
$cnt++;
close (IN);
open(OUT,">/timelapse/counter.txt");
print OUT $cnt;
close (OUT);

system("wget -q -O /timelapse/$cnt.jpg http://10.0.0.119/axis-cgi/jpg/image.cgi?resolution=640x480");

What this does is fetch a single jpg from that camera using wget and save it locally as N.jpg - incrementing N.jpg every time it's run, so you end up with a sequence of jpgs from 1.jpg, 2.jpg, 3.jpg etc

Change the permissions on the script so it'll run;

chmod +x /timelapse/get_timelapse.pl


Go and have a cup of tea. When you come back, you should have 1.jpg and maybe 2.jpg or more.

(I also linked this directory from my http web root so I can check it remotely by web browser.)

When you think you've got enough pictures to try making a movie, copy them to a working directory (Don't work on them in the main directory in case something goes wrong and you lose the lot)

mkdir /tmp/film
cd /tmp/film
cp /timelapse/*.jpg .


Install ffmpeg if you haven't already

(In Debian:)
apt-get install ffmpeg


And simply run;

ffmpeg -i %d.jpg output.mpeg

The %d in the -i input clause tells ffmpeg to read the jpgs in order and create output.mpeg, your amazing timelapse movie!

You can play around with ffmpeg's settings to slow down or speed up the process, and if you want to remove chunks of data (such as long periods of night) - just delete the relevant jpgs before you create the movie.


Output for about a day and a half; http://www.youtube.com/watch?v=rP9PkpYlESI
User avatar
Lee Sharp
Posts: 1069
Joined: Sat Mar 31, 2007 9:18 pm
Location: Houston, TX

Post by Lee Sharp »

Cool! You should be able to do some creative cron work, or script magic to have it not capture during specified hours, or capture much slower to make the nights flash by.
Flasheart
Posts: 342
Joined: Thu Jul 06, 2006 2:27 pm

Post by Flasheart »

Yeah, that would be good if you were doing a lot of them.

With this project, I'll remove most of the night-time jpgs manually before making the movie for the same effect :)
river100
Posts: 145
Joined: Sun Oct 07, 2007 5:52 pm
Location: Louisiana

Post by river100 »

perfect timing !
my son asked me today if i knew a way to do just this. he wants to timelapse his new beehives. i told him to do just what you first tried.
got on the net tonight to research this and saw your post. he still has some work to do since he doesn't have an IP cam. some searches in the zm forums should get him jpegs from the low powered zm server i set up for him. some incentive for him to use it.

clay
coke
Posts: 518
Joined: Wed Jan 30, 2008 5:53 pm
Location: St. Louis, MO, USA

Post by coke »

If you're feeling really creative, you could likely get the sunrise/sunset times from one of the variety of web services providing that data, and set the record times daily to avoid levels of darkness. Though it probably only matters when people are actually working, which I'd assume happens in the day.

Axis 211 doesn't do badly at night for that matter, either. I've got one in a cave that can see better there than I can.
Post Reply