WebCam: Time-laps video

This article illustrates how to make a time-laps video using an Acme Linux Board

Time-lapse photography is a cinematography technique whereby each film frame is captured at a rate much slower than it will be played back. When replayed at normal speed, time appears to be moving faster and thus lapsing. Time-lapse photography can be considered to be the opposite of high speed photography (read more...).

Install an USB webcam as explained on WebCam: Using mjpeg streamer to stream video over HTTP.

Point your webcam to the subject to be photographed then use the web streaming to check the setup (shot, focus, light, etc). Type ctrl-c to stop mjpg-streamer and create a directory where to store the pictures taken:

debarm:~/mjpg-streamer# mkdir pics

then lauch mjpg_streamer:

debarm:~/mjpg-streamer# ./mjpg_streamer -i "./input_uvc.so -f 10 -r 640x480" -o "./output_http.so -w ./www" -o "./output_file.so -f pics -d 120000"

Where:

  • ./input_uvc.so -f 10 -r 640×480 call input_uvc.so plug-in to get mjpg stream from /dev/video0 device at 10 frame per second with a resolution of 640×480 pixels
  • -o ./output_http.so -w ./www enable the web streaming on port 8080 and create the default web page on ./www folder
  • -o ./output_file.so -f pics -d 120000 is the part related to the time-laps and use output_file.so plug-in to save JPG shot on pics forlder each 120 seconds

With this command it is possible to check in web streaming the photo quality and store a shot each x seconds. After a while type:

debarm:~/mjpg-streamer# ls -al pics
-rw-r--r-- 1 root root 23550 Mar  7 18:34 2010_03_07_18_34_11_picture_000000000.jpg
-rw-r--r-- 1 root root 25808 Mar  7 18:36 2010_03_07_18_36_15_picture_000000001.jpg
-rw-r--r-- 1 root root 25633 Mar  7 18:38 2010_03_07_18_38_15_picture_000000002.jpg
-rw-r--r-- 1 root root 25885 Mar  7 18:40 2010_03_07_18_40_15_picture_000000003.jpg
-rw-r--r-- 1 root root 25739 Mar  7 18:42 2010_03_07_18_42_15_picture_000000004.jpg
-rw-r--r-- 1 root root 25648 Mar  7 18:44 2010_03_07_18_44_15_picture_000000005.jpg

When you have collected an enough number of photos kill mjpg_streamer and use ffmpeg utility to create a single movie file.

Ffmpeg requires that all the files are named sequentially, so it hangs if you delete some photos. To avoid that use this simple utility in Python to rename all the files before using ffmpeg :

import os
 
path="pics"  
dirList=os.listdir(path)
orderedDirList=sorted(dirList)
i=0
for fname in orderedDirList:
    previous_name = path + "/" + fname
    new_name = path + "/%03d.jpg" % i
 
    os.rename(previous_name,new_name) 
    i+=1

Save it as enumerate.py in the mjpg_streamer directory and runs typing:

debarm:~/mjpg-streamer# python enumerate.py
debarm:~/mjpg-streamer# ls -al pics
total 14287
drwxr-xr-x 2 root root 10392 Mar  8 08:45 .
drwxr-xr-x 8 root root   864 Mar  8 08:45 ..
-rw-r--r-- 1 root root 20412 Mar  7 18:26 000.jpg
-rw-r--r-- 1 root root 20008 Mar  7 18:28 001.jpg
-rw-r--r-- 1 root root 21245 Mar  7 18:32 002.jpg
...

Probably you don't have ffmpeg installed on your FOX so install it typing:

debarm:~# apt-get update
debarm:~# apt-get install ffmpeg

Now create the time-laps video typing:

debarm:~# ffmpeg -r 15 -b 200k -i pics/%03d.jpg mymovie.mp4