Monday, July 30, 2012

Making a Time Lapse movie and dragging the shutter in post production

Since the release of Android Ice Cream Sandwich and the camera's timelapse feature, I've been having fun. Examples:

The only problem is that you cannot drag the shutter because there's no shutter speed control.

So I decided to see if I can do this from a regular movie. Tools needed: avidemux, imagicmagick, QuickTime,

1.  Take the movie and turn into individual images. This will create a LOT of files! AT 25 frames per second, an hour of video will be 90,000 frames!

For this I use avidemux. Open the video file, and move the slider to where you want to start, then click Edit > Set Marker A.

Then move to the end of where you want, and click Edit > Select Marker B.

and now you see how much of the movie you've selected

You can estimate how many frames that'll be.

Then go to File > Save > Save Selection as JPEG Images

Its best to create a new folder for the images, then you have to have a start character. This will give a naming scheme like f0001.jpg f0002.jpg etc

Here's the folder

2.  We need to remove the 'f', and then the extra zeroes.

To remove the 'f' we can use the command

    for f in *; do mv "$f" "${f#?}"; done
each ? in the {} is one character, so the above command removes one leading character.

Then we need to remove the leading zeroes. We can use the command

    for FILE in *; do mv $FILE `echo $FILE | sed -e 's:^0*::'`; done

and that gets us

3.  Simulate dragging the shutter.

Going to use ImageMagick. On OSX you can get a pre-compiled version here, or compile it yourself.

So what you need to do is create a script that averages a number of images, to simulate dragging the shutter. With help from folks on the ImageMagick forum:

        #! /bin/bash
        while [ $i -le $num ]; do
        /usr/local/ImageMagick/bin/convert $i1.jpg $i2.jpg $i3.jpg $i4.jpg $i5.jpg $i6.jpg $i7.jpg $i8.jpg $i9.jpg $i10.jpg -evaluate-sequence mean /path/to/output/result$i.jpg

You can extend this as much as you want.

What does this mean?

  1. totnum is the total number of frames to be processed, which I got from running avidemux above
  2. segnum is the number of images to be averaged into one image ie the duration of the "drag"
  3. In the example above I have 500 frames, and I average 1 to 10, then 2 to 11, 3 to 12 and so on.
  4. The "i=$((i+1))" at the end is critically important: it sets the advance for each averaging cycle, and is in essence the time lapse period you'd set on the camera.

The result is that you can have a drag duration greater than the time lapse interval, which is not possible on a camera.

4.  Join the frames back into a movie. I use Quicktime Pro, version 7. Click File > Open Image Sequence

navigate to the folder with the processed images

Click one and select "Open"

Then your framerate for the movie, 25 would be PAL standard, and after a few seconds, depending on the number of frames the movie appears. Here it uploaded to YouTube.

dragging 100 frames, timelapse 25

Some interesting aspects to this.

Basically you can drag / blend over one period / duration, and time lapse over a different one.

ImageMagick can hold up to 999 images in RAM, so the maximum drag would be 40 seconds at PAL fps. Bear in mind that "dragging" ie averaging lots of images can takes a long time, and if you have 1hr of original movie, thats 90,000 frames to process. You may need to run the script overnight.

Here's another example where I've blended over 500 frames ie 20 seconds, and timelapsed at one frame per second.

drag = 500, timelapse = 25

drag = 500, timelapse = 500

Just to mention that I'm a novice at this, so my terminology may be incorrect and my techniques rudimentary. Certainly I think someone could  make a plugin for Final Cut, or Adobe Premier, or even iMovie.

1 comment:

previouslysilent said...

alternatively, get a Panasonic Lumix G and do it all in camera!