Showing posts with label mencoder. Show all posts
Showing posts with label mencoder. Show all posts
Wednesday, 8 January 2014

Timelapse with Rapberry Pi camera module

As I have mentioned before I always wanted the camera module for the Raspberry Pi. Until now I had only tried out timelapse using my laptop web camera, and that gave me really crappy images. Now I have the camera module to play with and the images are way better. This is timelapse from 12:00 31. Des 2013 to 12:00 1. Jan 2014 shows 24 Hours in 5 minutes and 26 sec. including some fireworks.



This script will take image every 5 seconds 1440 times leaving you with just enough to create 60 sec timelaps video using 24 fsp

#!/bin/bash
# Timelapse controller for USB webcam
DIR=/home/user/timelapse
x=1
while [ $x -le 1440 ]; do                                                       
filename=$(date -u +"%Y%m%d-%H%M-%S").jpg                                       
raspistill -o $DIR/$filename -w 1280 -h 960 -n -t 1000
x=$(( $x + 1 ))
sleep 5;
done

Now you have 1440 images or the number you entered and next step is to create the video. Copy the images to your computer using scp or rsync, you can add that to your script if the Raspberry pi is connected to network. When you have all your images on your computer you can render video with mencoder. Install mencoder if needed.

sudo apt-get install mencoder

#!/bin/bash
DIR=/home/user/timelapse/
ls $DIR/*.jpg > list.txt
mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=640:480 -o $DIR/$(date -u +"%Y%d%m-%H%M-%S").avi -mf type=jpeg:fps=24 mf://@list.txt
rm list.txt

All ideas about improving this code are welcome.
-cheers
Monday, 18 November 2013

Capture images on webcam

I own a raspberry pi and have been thinking about getting the camera module, but still I haven't. One of the things I like to do is time lapse.
You can also do this with your web cam on your computer.

First check if your web cam is detected
$ ls -l /dev/video*
crw-rw----+ 1 root video 81, 0 nov 16 17:08 /dev/video0
Then install following programs
sudo apt-get install fswebcam
sudo apt-get install mencoder
Create your time lapse folder and use editor to create your tilme lapse file, the script.
mkdir timelapse
vim runtimelapse
Paste in the following:
#!/bin/bash
# Timelapse controller for USB webcam
frames=1440 # The numer of images to be taken
pause=10 # Dealy in seconds between images
DIR=~/timelapse
x=1
while [ $x -le $frames ]; do
filename=$(date -u +"%Y%m%d_%H%M-%S").jpg
fswebcam -d /dev/video0 -r 640x480 $DIR/$filename
x=$(( $x + 1 ))
sleep $pause;
done;
To make the script executable, use:
chmod 755 runtimelapse
Then run it using:
./runtimelapse
Now you have some number of images, time to create video
cd timelapse
ls *.jpg > list.txt
mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=16/9:vbitrate=8000000 -vf scale=640:480 -o timelapse.avi -mf type=jpeg:fps=24 mf://@list.txt
And now you have time lapse video.

Instructions on making timelapse using raspberry pi