Here are instructions for capturing and compiling a time-lapse video using a Raspberry Pi and the PiCamera module.
Upload and edit the time-lapse video script
1. Connect to your pi via the terminal :
ssh pi@10.0.1.17
change the IP address to match your Pi
2. Create a 'scripts' directory in your home folder of your pi:
mkdir scripts
3. Open a new terminal window to work locally on your laptop. Put the time-lapse Python script on your desktop.
4. On your laptop terminal type the following to upload the time lapse python script to your pi:
scp /Users/dwingus/Desktop/TL.py pi@10.0.1.17:/home/pi/scripts
Change "dwingus" to your laptops username and change the IP address to match your Pi
5. You can edit the TL.py to change the filenames or the speed at which images are captured.
sudo nano TL.py
Make your changes and then save the file.
Stream the video feed from your Pi to your laptop to setup the camera
You will need to install two applications on your laptop to make this step work. You will install HomeBrew and MPlayer
HomeBrew is a package installer for Os X. Installing HomeBrew will allow you to easily install MPlayer. It will also allow you to use additional unix commands that are not included in a standard Os X install.
1. Go here: http://brew.sh
2. Scroll to the very bottom of the page and follow the "Install Homebrew" instructions.
3. The first thing to do after installing HomeBrew is to type into command line:
brew doctor
4. Type the following to install MPlayer
brew install mplayer
You will need to have two terminal windows open on your laptop. One will be for the Pi and the other will be a local terminal. Start MPlayer on the local terminal. It will listen for the video stream from the Pi. MPlayer should always be started first. The video stream on the RPI will be started using raspivid which pipes the video output to NC.
You will need to know your laptops IP address in order to send a video stream to it. To do so go to System Preferences / Network and make note of the IP address. You will need it in the following steps.
on the mac terminal type the following command:
nc -l 5001 | mplayer -fps 31 -cache 1024 -
This starts MPlayer and has it wait for an incoming video stream.
on the Pi terminal type the following command:
raspivid -t 0 -o - | nc [ ip address ] [port number]
My command looked like this:
raspivid -t 0 -o - | nc 172.20.121.152 5001
This starts the Raspivid and pipes its output to your laptop. You should now see the video stream from the Pi Camera in MPlayer on your laptop. This will allow you to adjust the PiCamera remotely in order to setup a nice shot for capturing a time-lapse video.
Running the Python time-lapse script
Once you have setup a nice shot do the following to start capturing images:
Start the time-lapse python script with the following command:
sudo python /home/pi/scripts/TL.py
This will start the image capturing sequence. The script will automatically create a new time-lapse folder with a time stamp in the folder name. It will then start saving JPG files into the folder. There will be many JPG files! You may need a bigger SD card!
To have the script start immediately on boot:
sudo nano /home/pi/.bash_profile
Put the following in the bottom of the .bash_profile file:
python /home/pi/scripts/TL.py
Save the file and reboot
Compiling the JPG files into a time-lapse MP4 movie
Navigate to the time-lapse folder and list the file names into a text file.
sudo ls *.jpg > stills.txt
Run apt-update on the Pi to update all of the library packages
sudo apt-get update
Install a program called mencoder
sudo apt-get install mencoder
Navigate to the time-lapse folder containing your JPG files and run the following command to create a movie file
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
This will take a while depending on how many images there are to process. Once the process is complete you should see a file called timelapse.avi in the folder.
To play the movie:
omxplayer -o hdmi timelapse.avi