#WebCam: Time-laps video

<span class="abstract">
This article illustrates how to make a time-laps video using an Acme Linux Board
</span>

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 
(<a href="http://en.wikipedia.org/wiki/Time-lapse">read more...</a>).

Install an USB webcam as explained on @article='video_streaming'.

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:

<pre class="minicom">
debarm:~/mjpg-streamer# mkdir pics
</pre>

then lauch mjpg_streamer:

<pre class="minicom">
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"
</pre>


Where:

* <b>./input_uvc.so -f 10 -r 640×480</b> 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
* <b>-o ./output_http.so -w ./www</b> enable the web streaming on port 8080 and create the default web page on ./www folder
* <b>-o ./output_file.so -f pics -d 120000</b> 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:

<pre class="prettyprint">
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
</pre>

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 :

<pre class="prettyprint">
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
</pre>
	
Save it as enumerate.py in the mjpg_streamer directory and runs typing:

<pre class="minicom">
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
...
</pre>

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

<pre class="minicom">
debarm:~# apt-get update
debarm:~# apt-get install ffmpeg
</pre>

Now create the time-laps video typing:

<pre class="minicom">
debarm:~# ffmpeg -r 15 -b 200k -i pics/%03d.jpg mymovie.mp4
</pre>

@shop='WB-HD3000'
@shop='WB-HD5000'
