This is a guide on how to make a time-lapse video from an online webcam. I have used my Raspberry Pi for its low cost, small footprint, and energy efficiency. This will work on any Linux, Unix or Unix-like operating system.
My source for my webcam is the building of the University of Birmingham’s new library.
The process to making the time-lapse is fairly simple. We need to: download the image at a desired interval, use FFmpeg to make the final movie. There are a few other caveats that we need to do get it to fully work, these will be explained in this walk-through.
Prerequisites. We need FFmpeg and wget. These are available by almost all default package management repositories in utilities such as apt-get, yum, Mac Ports, or pacman. I’ll just cover Raspbian operating system in this guide.
Type these in to terminal. Ignoring the $, this denotes a command at user level used in many guides and manuals.
$ sudo apt-get update
$ sudo apt-get install ffmpeg wget
1. Download the file using wget and cron
First we need to find the direct link to the file generated by the webcam. This was done by dragging the image to the address bar. The file is located at:
Time to use wget. There is one limitation that every file will over-write itself because each file is named “library.jpg”. To solve this problem we can use wget to rename and append something to the file name. I have decided to add year, month, day, hour, minute. We then need to make this in to a script. The default working directory is /home/pi/ if you log in as pi user on Rasbian,
Make a new directory
$ mkdir uoblibrary
Move in to the new directory we made. If you ever get lost type in the command ‘pwd’ and terminal will print the current working directory.
$ cd uoblibrary
Make the new script file
$ touch uoblibrary.script
Make the file executable so we can run the script
$ chmod +x uoblibrary.script
Using a text editor, we are using nano here.
$ nano uoblibrary.script
Insert the command below, press ctrl+o to save and ctrl+x to exit.
wget --output-document=/Users/simon/Pictures/uoblibrary/uoblibrary_$(date +\%Y\%m\%d\%H\%M).jpg http://www.download.bham.ac.uk/estates/library.jpg
We then need to make the script run at a desired time interval. I have chosen ten minutes. This will make a video at 24fps last for 4 seconds. For this we can use cron.
Mac OS X users cron is disabled , everyone else go to the step after, to enable type:
$ sudo mkdir /etc/crontab
Now let’s make the crontab.
$ env EDITOR=nano crontab -e
nano will open, insert text below, save and exit.
0/10 * * * * /home/pi/uoblibrary/uoblibrary.script
Confirmation that the crontab has been made, terminal will say ‘crontab: installing new crontab‘.
We can now let the script run indefinitely. Do not switch off your device or disconnect form the internet.
2. Using FFmpeg to make a video.
FFmpeg is a fantastic utility for transcoding or encoding video and audio, and even making animated GIFs. This can be done on the RaspberryPi, but if you have a more powerful machine such as a laptop or desktop I highly recommend using that, it can take a lit of time to encode.
First, I do not want to use the current directory the images are being saved to, this will make sense in a moment as we need to edit the filenames.
To go up one directory
$ cd ./
Copy the directory
$ cp -r uoblibrary/* uoblibraryvideo
Move to the new directory
$ cd uoblibraryvideo
FFmpeg can make a sequence of JPEGs in a directory in to a movie,
To make the video just use this simple one line command
ffmpeg -framerate 24 -pattern_type glob -i "*.jpg" output.mp4
I do not recommend doing this on a RPi, but this will sharpen the images and make the encoding as high quality as possible.
ffmpeg -framerate 24 -pattern_type glob -i "*.jpg" -b 10M -filter:v unsharp=5:5:1.0:5:5:0.0 -c:v libx264 -tune film output.mp4
If you plan on exporting to Youtube use this. Youtube use FFmpeg their side too, these setting will mean it wont get re-encoded again therefore keeping the video quality.
ffmpeg -framerate 24 -pattern_type glob -i "*.jpg" -filter:v unsharp=5:5:1.0:5:5:0.0 -c:v libx264 -preset slow -crf 18 -pix_fmt yuv420p output.mkv
Good luck. As long as the webcam link and your computer is working all should be fine.