2012-07-09

Creating Timelapse Videos with a Webcam

Last week I had some fun creating timelapse videos using just an inexpensive webcam and a laptop. Timelapse videos are a nice way to visualize processes which are otherwise to slow to observe directly (eg. the movement of clouds or the growth of plants). Technically the the solution to all the world's problems seem to be little Python scripts, which can be downloaded here. ;)
For simplicity a lot of things are hardcoded in these scripts, so you most certainly have to make changes. The scripts should be easy to understand, as they are quite short and simple. However if anything is unclear, just drop me a comment.

timelapse.py, timelapse_copy.py

timelapse.py uses ffmpeg for capturing images from the webcam (support for v4l assumed). You do not need this script, if you have any other means of acquiring the individual frames. The filenames of the acquired images contain a consecutive nr. and the time and date when the image was taken. Unfortunately it turned out later that times and dates in the filename confuse ffmpeg and have to stripped away to join the individual frames to a single video file. Besides the nr. needs to have leading zeros. The timelapse_copy.py script was made to compensate for that.


timelapse_filter.py

As mentioned before, an inexpensive webcam was used for simplicity. Therefore a Gimp plugin is used to sharpen and denoise the pictures a little. The script uses Gimp and the package gimp-plugin-registry (for the wavelet denoise). You can skip this step if you have a good camera or are not willing to wait, because the filtering can take quite some time, depending on which filtering operations you want to run on the individual frames. Do not forget to copy this script to ~/.gimp-2.6/plug-ins and to make it executable.

timelapse_ffmpeg.py

A third script creates a video from the filtered images again using ffmpeg.

2 comments:

  1. i am getting a error as follows :
    >>>
    Traceback (most recent call last):
    File "C:\Users\Acer\Desktop\timelapse\timelapse.py", line 24, in
    subprocess.call(["ffmpeg", "-f", "video4linux2", "-s", "1280x720", "-r", "1", "-i", "/dev/video0", "-vframes", "1", "-f", "image2", "./jpgs/image_"+str(i)+".jpg"])
    File "C:\Python26\lib\subprocess.py", line 444, in call
    return Popen(*popenargs, **kwargs).wait()
    File "C:\Python26\lib\subprocess.py", line 595, in __init__
    errread, errwrite)
    File "C:\Python26\lib\subprocess.py", line 821, in _execute_child
    startupinfo)
    WindowsError: [Error 2] The system cannot find the file specified
    >>>

    ReplyDelete
    Replies
    1. Do you have ffmpeg installed? Is it in your path variable?

      I assume you are using Windows. Unfortunately I have no experience how easy or hard it is using ffmpeg on Windows. Maybe it is a good idea to download and install ffmpeg or any other program that can be used to acquire images from a webcam.
      After that you can play a bit with this program to figure out how acquiring individual images works and then change the line in the script accordingly.

      Sorry that I cannot be more precise.

      Volker

      Delete