Quick Tip: Easy Time Lapse Videos with FFmpeg
In this tip I want to share with you a quick and easy way of creating your own time lapse videos using your webcam and a tool called FFmpeg. I just recently discovered this command line tool myself and can think of various cool uses for it e.g. connecting a webcam to a Raspberry Pi and leaving it somewhere to take snapshots on certain events, or stream video of some place you want to monitor.
Getting the tool
First thing is first – download FFmpeg. On the download page you’ll find various different ways of getting this tool. You can clone a git repository, download source code snapshots or get the pre-built binaries for your platform. I’m using a 64-bit version of Windows 7 so I go to the FFmpeg Windows builds page and get the 64-bit build with all the libraries statically linked. If you’re not sure what to download just get this file and it should work on most Windows machines. Also note that you’ll need a program called 7-Zip to extract the downloaded archive.
Now that you downloaded and extracted FFmpeg open up a command promt and go to the binary directory of the tool e.g.
ffmpeg-win64-static\\bin. Let’s check what devices are supported by executing the following command:
ffmpeg -list_devices true -f dshow -i dummy
You should get a response of something like this
... [dshow @ 00000000020977e0] DirectShow video devices [dshow @ 00000000020977e0] "Microsoft LifeCam Cinema" [dshow @ 00000000020977e0] DirectShow audio devices [dshow @ 00000000020977e0] "Jack Mic (IDT High Definition A" [dshow @ 00000000020977e0] "Desktop Microphone (2- Cinema -" [dshow @ 00000000020977e0] "Dock Mic (IDT High Definition A" [dshow @ 00000000020977e0] "Headset Microphone (GN 2000 USB" [dshow @ 00000000020977e0] "Rec. Playback (IDT High Definit"
We’re interested in the video devices, so take note of the one that comes up for you, in my case it’s “Microsoft LifeCam Cinema”. Now let’s see what resolutions are supported on this camera:
ffmpeg -f dshow -list_options true -i video="Microsoft LifeCam Cinema"
Remember to replace the video parameter value with your own video device name. You should get a list of supported resolutions and framerates for your camera. Choose a resolution that you want and let’s test how it will look:
ffplay -f dshow -video_size 1280x720 -i video="Microsoft LifeCam Cinema"
Notice that this time I used ffplay instead of ffmpeg because I wanted it to open a window with a live video feed of the camera to make sure everything looks good and to be able to set up the camera where you want. Creating time lapse videos involves leaving the camera in the same place for long periods of time so you need to be sure that you’re getting the view you expect.
Creating the time lapse video
Now that everything is in place you can start capturing images. You can play around with the setting, but my suggestion is to first try recording 1 frame per second and leave camera untouched for an hour or so. Point it at something that has movement, but don’t put the camera to close to the subject or the images might be blurry from time to time due to the auto focusing. Start capturing:
ffmpeg -t 100000 -f vfwcap -s 1280x720 -i -r 1 -f image2 camera%06d.jpg
-t 100000 part means that it will try to capture that many images before the program exits, but if at any time you change your mind simply click q while the ffmpeg window is in focus. The frame rate is set with the parameter
-r 1. Also you may or may not get some errors about buffer being full, but this does not impact your capturing session. Though if that bothers you just add parameter
-v quiet right after
ffmpeg. The images will be captured with file names of
After your done capturing the frames you need to convert those images to a movie like this:
ffmpeg -f image2 -i camera%06d.jpg time-lapse.mp4
Voila, you have created a time lapse video!
Here’s a sample of my first attempt: