Arduino time lapse video

In this post I’ll explain how to create a time lapse video with an arduino.

time lapse, 5-8s interval

In Lesson 5: (Trigger your camera with an Arduino) of my highspeed 101 I described how one can use an arduino to trigger the cam. The very same method can be applied to create a time lapse video, instead of one picture we take several pictures. The amount of pictures you take depends on several factors, such as expected duration of the video, battery of your camera, event you want to time lapse.

Lets first calculate the number of pictures; 1 second of video uses about 20-25 frames per second (the higher the better, but I wouldn’t go below 20 frames).

video duration (in seconds) x 25 frames per second = number of images you need

You’ll end up somewhere around 1500 frames for one minute of video.

Next you need to calculate the interval in which you want to take your pictures. The shorter the interval, the faster the motion in the video. In the video above I used about 5 seconds (8 seconds during sunset) which results in a more or less smooth motion. In my first time lapse video (below) I used 30 seconds, which results in a much faster motion.

time lapse, 30s interval

time to cover (in seconds)
--------------------------- = interval (in seconds)
number of images

F.ex. If you would like to cover one day (1440 minutes) in one minute video (1500 frames) you’d use an interval of 1 minute.

When we know the interval settings, we can program our arduino. The code looks very similar to the one used in Lesson 5.

int SCRPin =  8;    // SCR connected to digital pin 8
void setup() {
  // initialize the digital pin as an output:
  pinMode(SCRPin, OUTPUT);

void loop() {
  digitalWrite(SCRPin, HIGH);   // set the SCR on
  delay(100);                   // wait for 100 milliseconds
  digitalWrite(SCRPin, LOW);    // set the SCR off
  delay(9900);                  // wait for 10 seconds

With the code above, the arduino would trigger the cam every 10 seconds. 100 Milliseconds worked for me, if this is to short (camera not triggering) or to long (multiple images), adjust this value.

Depending on the time you want to cover, the battery may be a limitation. I bought a external power adapter for my Sony cam (AC-PW10AM), so I don’t have to care about battery.

Camera settings
The camera settings depend on the event you want to cover. If the light conditions will stay constant, you can use manual settings (manual focus, manual aperture and manual exposure). If the light conditions are going to change, as with my sunset video, I used aperture priority mode (with manual focus). In my video at the top, you can see, that there is a little ‘flickering’, this is because of the changing light conditions and aperture priority mode. In that video I was also using the in-cam HDR feature.

Taking the pictures
Taking the pictures is easy.. Setup the cam, connect the arduino and let the camera take the pictures.

Post processing
I exported all the image with 720px width in jpg format. You have to decide yourself, whether you’re using all images or not. I removed some at the beginning, as they were not very spectacular.
To create the fading image at the start, I used imagemagick.

for i in `seq 5 5 95`; do composite -dissolve $i "firstimage.jpg" "secondimage.jpg" "fade$i.jpg" ; done

Finally combine all the images you want to use in a video. For this task I used mencoder, which is part of mplayer. These are the settings I used:

mencoder -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=24000000:aspect=1.5 -mf w=1082:h=720:fps=24:type=jpg 'mf://*.jpg' -ofps 24 -noskip -xy 1082 -aspect 1.50 -o /media/tmp/timelapse2/sunset.avi

That’s it!

This entry was posted in Howto. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *