Wednesday, June 17, 2015

Using Your Raspberry Pi to Take Time Lapse Videos

For this project, we will be setting up a webcam on the Raspberry Pi using fswebcam. We will then create a shell script to take a pictures at scheduled intervals. This is a great skill building project so we will do some variations on it in the future. The video below was taken this way.


Time: 20 minutes
Difficulty: Easy

You Will Need:

  • A Raspberry Pi.
  • Some way to access it's terminal. You can use SSH, Remote Desktop, or keyboard and mouse.
  • A USB webcam.
Steps:
  1. Plug in your USB webcam before powering on your Pi.
  2. Power on your Pi and open the terminal.
  3. Type sudo apt-get install fswebcam. This is a simple way to use a webcam with your pi. You can test it by typing fswebcam /home/pi/Desktop/this_is_my_test_picture.jpg. You will see your picture
  4. Type mkdir /home/pi/Desktop/Timelapse
  5. We will now write a bash script to take the pictures.
  6. Type sudo nano /home/pi/Desktop/timelapse.sh
  7. In the nano editor, type DATE=$ (date +"%Y-%m-%d_%H%M")
  8. On the next line type fswebcam /home/pi/Desktop/Timelapse.
  9. Press CTRL+X, then y, and then Enter to exit nano.
  10. Right now all our script does is take a picture. We want it to take lots of pictures at specified intervals. To do this, we will use cron, a way of scheduling tasks to run on the Pi at certain intervals.
  11. To edit your crontab (the place where cron looks to find out which command to run) type crontab -e in the command line. You will see this window.
  12. In the bottom, in a new line, type * * * * * /home/pi/Desktop/timelapse.sh. Save with CTRL+X, Y, and Enter. You should then the message "crontab: installing new crontab"
  13. If everything is set up correctly, you should start to see pictures in your Timelapse folder.
  14. You can use any video editor to turn your stills into a video. According to the Raspberry Pi website, you can use the following commands to convert the pictures on the Pi.
  15. sudo apt-get install mencoder
  16. cd /home/pi/Desktop/Timelapse
  17. ls *.jpg > stills.txt
  18. mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=1920:1080 -o timelapse.avi mf type=jpeg:fps=24 mf://@stills.txt




No comments:

Post a Comment