Willkommen bei bytebang » The blog about all and nothing » Rendering timelapse videos from daylight webcam images

Rendering timelapse videos from daylight webcam images

Sep 07 2014

In my last article i described how to setup a webcam with a raspberry pi. This time i am showing you how to create timelapse videos from those images: MEncoder is a free command line video decoding, encoding and filtering tool released under the GNU General Public License. I am using it to generate a flv file from a sequence of images. So if you have a list of images stored in a file then you can easily create a video from it. The images are shown one after anothe - exactly as they appear in the file /tmp/webcam_imagelist.txt

$ mencoder mf:///tmp/webcam_imagelist.txt -mf type=jpg -of lavf -ovc lavc -lavcopts vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 -o /tmp/timelapse.flv

So far so good. The previous snipped produces a *.flv video (/tmp/timelapse.flv) from a list of *.jpg images. But imagine that you have a huge amount of images and you want to generate videos that are not showing the black images taken in the middle of the night ?

Imagine that you have the following set of images:


All images of a day are stored in a separate directory. The filename indicates the time when the image was taken (hh.mm.ss). The the naive approach is to take only these images that are taken in a certain hour:

#! /bin/bash
find /var/webcam/ -regextype posix-egrep -regex ".*\/($hours)\.([0-9]{2}\.){2}jpg" -ctime -10 | sort > /tmp/webcam_imagelist.txt

It searches only for files not older than 1o days in the /tmp/webcam/images/ directory whose hours are in between 08 and 19. This means that the image 23.45.01.jpg will not be taken because it is not in the desired timespan (actually because it doesnt start with a number defined in the hours variable).

While this works pretty well in the summer you may stumble into a problem in the wintertime when the days are getting shorter. Here in austria the sunrise in the winter is about 07:30 and sunset around 16:00 - so you will end up with a few black images in your 10 day timelapse video every morning and every evening.

How to overcome this ? ... The solution is simple:

  • Find all images not older than x days
  • Filter out all images that are below a certain brightness - threshold.
  • Leave the rest and write it to the imaglist file.
$ find /var/webcam/-type f -ctime -10 | sort -n | xargs identify -verbose -format "%d/%f -> %[mean]\n" | awk '$3 > 25000 {print}' | awk '{print $1}' > /tmp/webcam_imagelist.txt

This command does exactly that. It searches for all files in the /tmp/images directory which are not older than 10 days. Then it sorts them and for each file the identify command is invoked. This command is part of the imagmagick toolchain and (beside a lot of other things) able to generate a number that represents the darkness of an image. The output after this stage looks like this:

/var/webcam/05.15.01.jpg -> 656.156
/var/webcam/05.20.01.jpg -> 607.619
/var/webcam/05.25.01.jpg -> 645.206
/var/webcam/05.30.01.jpg -> 631.563
/var/webcam/05.35.01.jpg -> 833.807
/var/webcam/05.40.01.jpg -> 863.513
/var/webcam/05.45.01.jpg -> 1148.49
/var/webcam/05.50.01.jpg -> 1624.04
/var/webcam/05.55.01.jpg -> 3549.87
/var/webcam/06.00.01.jpg -> 5629.03
/var/webcam/06.05.01.jpg -> 11898.2
/var/webcam/06.10.01.jpg -> 17631.1
/var/webcam/06.15.01.jpg -> 23135.4
/var/webcam/06.20.01.jpg -> 26110.6
/var/webcam/06.25.01.jpg -> 28694.1
/var/webcam/06.30.01.jpg -> 28726.1
/var/webcam/06.35.01.jpg -> 28849.7
/var/webcam/06.40.01.jpg -> 28638
/var/webcam/06.45.01.jpg -> 29678.3
/var/webcam/06.50.02.jpg -> 29901
/var/webcam/06.55.01.jpg -> 30466
/var/webcam/07.00.01.jpg -> 31730.8
/var/webcam/07.05.01.jpg -> 31333.4

You can see that the value starts to increase at 05:40 - which was sunset on this day. Afterwards the script removes all lines whose brightness is below 25000 and removes the brightness value again. The outcome is a list of chronologically ordered files with a guaranteed brightness - This avoids the black images in the beginning and in the end of the filelist with the other approach.

The result can be seen on the bottom of this site (Timelapse): http://web.segelflug.at/flugplatz/wetter

Get Social

(c) 2017, by bytebang e.U. - Impressum - Datenschutz / Nutzungsbedingungen