Jump to content

Primary: Sky Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Secondary: Sky Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Pattern: Blank Waves Squares Notes Sharp Wood Rockface Leather Honey Vertical Triangles

Tutorial info Visit support topic

  • Added on: Apr 25 2013 07:57 AM
  • Views: 6784
 


* * * * *
0 Ratings

Time lapse Webcam With The Raspberry Pi, fswebcam and mencoder

Posted by drewibbo on Apr 25 2013 07:57 AM

A nice easy tutorial now. This one will have you making your own time lapse movies in minutes using a button to start the camera.
I will also show you how to encode them into a short movie. View my sample video here.

Here is a list of things that you will need:

  • Rapsberry Pi
  • Debian “Wheezy” Operating System
  • USB webcam (I have used the Trust HD 1080)
  • wiringPi gpio library

Download and install the following packages:

 

sudo apt-get install fswebcam
sudo apt-get install mencoder

 

To install wiringPi type the following into the terminal:

 

git clone git://git.drogon.net/wiringPi

 

Once downloaded then type:

 

cd wiringPi
./build

 

This will install wiringPi on your system.

 

That is the software taken care of. Now lets take some photos as a time-lapse.
We have a button attached to wiringPi pin 16 on the GPIO header.
 

Type the following into the terminal:

 

sudo nano timeplapse.sh

 

Copy the following into the file:

 

#!/bin/sh
# Time-lapse capture script
# Andy Ibbitson 17-03-2013
###############################

button=16
setup ()
{
echo Setup
gpio mode 0 out
}
# waitButton:
# Wait for the button to be pressed. Because we have the GPIO
# pin pulled high, we wait for it to go low to indicate a push.
#####################################################
waitButton ()
{
echo "Press the button to begin the sequence ... "
while [ `gpio read $button` = 1 ]; do
sleep 0.5
done
}
beginCapture ()
{
i=0
echo "CAPTURING... [CTRL+C] to cancel..."
while [ $i -lt 750 ]
do
  fswebcam -r 1280x720 -S 15 --jpeg 99 -p MJPEG --shadow --title "IbboCam" --subtitle "BN11 1BY Looking North..." --info "Author: Andy Ibbitson" --save photos/home$i.jpg -q
  gpio write 0 1
  sleep 0.01
  gpio write 0 0
  sleep 0.5
  i=$(($i+1))
done
}
setup
while true;
do
  waitButton
  beginCapture
done

Save as timelapse.sh and create a directory called “photos”.

The script will take up to 750 photos and save them to “photos”.

You can terminate the script early with CTRL+C.

 

Once you have taken all of your photos you can then use encode.sh to make your mini movie:

 

sudo nano encode.sh

 

Copy the following into the file:

 

echo "This script will encode a time lapse movie..."
echo "\n"
echo "ENCODE THE VIDEO NOW? [y/n]..."
read inputmake
filedate=$(date +"%d-%m-%Y-%H-%M")
if [ $inputmake == "y" ]; then
  cd photos
  ls -1tr | grep -v files > $filedate.txt
  echo "Enter the desired frame rate of the finished movie (15-20 is normal)..."
  read frames
  mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4 -o $filedate.avi -mf type=jpeg:fps=$frames:sc_threshold=-1000000000 mf://@$filedate.txt
  cd ..
  echo "\n"
  echo "Your time lapse movie has been created. It has been saved to the photos directory."
  rm *.jpg rm *.txt else
  echo "OK THIS SCRIPT WILL NOW EXIT... Nothing has been done."
  exit
fi

 

And there we have it! Take a look at your time lapse movie.

 

One tip: Clouds make great subject matter as do people. :D


Powered by Tutorials 1.5.1 © 2017, by Michael McCune