Timelapse with variable shutter speed

  • 151 Replies

Offline fbonomi

  • ****
  • 469
  • A570IS SD1100/Ixus80
    • Francesco Bonomi
Re: Timelapse with variable shutter speed
« Reply #70 on: 17 / May / 2008, 16:01:05 »

Re: Timelapse with variable shutter speed
« Reply #71 on: 18 / May / 2008, 07:01:48 »
Yesterday i did a sunset time lapse but after a while as it gets dark my shots become just black pictures... Is this due to the fact that i take a shot every 10 seconds and since the exposure requires to be more than 10 seconds i don't get enough light before the next shot and so and and on...?

Sunset TimeLapse on Flickr - Photo Sharing!
« Last Edit: 18 / May / 2008, 07:17:32 by fpalangie »
450D & 18-55mm, 100-400mm


Offline fbonomi

  • ****
  • 469
  • A570IS SD1100/Ixus80
    • Francesco Bonomi
Re: Timelapse with variable shutter speed
« Reply #72 on: 18 / May / 2008, 07:06:07 »
no, it shouldn't happen. if you ask for a delay of 5 seconds, that's the delay between shots. if shots are 15 second, you get 15 seconds of exposure PLUS 5 seconds of delay.

There might be a bug somewhere...

Look in the chdk/scripts folder. you should have a file called PR_SCREEN.TXT from the last time you ran the script.

Can you send it to me?


Re: Timelapse with variable shutter speed
« Reply #73 on: 18 / May / 2008, 07:21:13 »
In fact it was every 10 sec... here is the document you asked for...
450D & 18-55mm, 100-400mm


Offline fbonomi

  • ****
  • 469
  • A570IS SD1100/Ixus80
    • Francesco Bonomi
Re: Timelapse with variable shutter speed
« Reply #74 on: 18 / May / 2008, 09:21:23 »
From this log, the script appears to work correctly. I am enclosing a graph of the settings the script has used (i.e. the settings that the script was thinking to be shooting with).

Blue line is Tv (Exposure), and pink line is Sv (ISO), expressed in apex units multiplied by 96. (Don't mind if you don't know these things, the importnt thing is that when the blue line goes down the exposure gets longer, and when the pink line goes up the ISO get higher)

There are three phases:

1) Up to frame 979 (first circle) the script is changing exposure following the measured light conditions (standard mode).

2) From that point on it it's too dark to measure light reliably and so the script just "guesses", assumin it's getting darker and darke, and lengthening the exposure (guess mode).

3) This goes up to frame 1021, when exposure has reached the limit of -414 (20 seconds) and instead of lengthening exposure starts keeping exposure the same and increasing sensitivity (the blue line goes horiziontal and the pink line rises) (guess mode with high ISO)

In what phase are the black pictures you were getting? (what frame number do they have?)

If you read the EXIF values, what do they say about exposure and ISO settings?

Can you send me one of these shots?


Offline fbonomi

  • ****
  • 469
  • A570IS SD1100/Ixus80
    • Francesco Bonomi
Re: Timelapse with variable shutter speed
« Reply #75 on: 18 / May / 2008, 09:28:39 »
My guess:

they got only in phase 3 (frame numbers above 1021)

the good frames have EXIF values showing an increasing exposure time up to 15 secs (even if exposure is longer, EXIF records only up to 15 secs)

The bad frames have an exposure like 1/1000, or anyway the default exposure the camera was set to.

If my guess is correct, you have met a bug (of uBasic?? of the camera itself??) that I thought I had worked around (with sleep instruction in the script etc.)

The effect of the bug is that sometimes setting exposure has no effect if you also set sensitivity.

One thing that you might try is to format the card IN THE CAMERA ITSELF (using the standard canon menu) and re-installing CHDK. Don't ask why, but that helped me a lot. Then, you can try if things have got better.

To ease testing, instead of waiting a whole day you can just start the script and then put the camera in an almost completely closed drawer .

You will be able to simulate the darkness, and you should be able to check if the problem has gone or not: do you see the camera adapting itself to the darkness (frames getting lighter and lighter), or do you still get black frames?

If the black shots are different from what I thought, you should give me the info I requested before.

Let me know!

« Last Edit: 18 / May / 2008, 09:31:48 by fbonomi »

Re: Timelapse with variable shutter speed
« Reply #76 on: 18 / May / 2008, 11:33:14 »

Well here is the info you requested:

From 1 o 1007 all is good
From 1008  to 1010 black shot
1011 is a good shot
From 1012 onwards black shot (attached to the reply is one of the back shots)

hope this helps
450D & 18-55mm, 100-400mm

« Reply #77 on: 20 / May / 2008, 00:55:11 »
Hey all, loving this thread. Some of my older timelapses (preCHDK) used an auto aperture security camera shooting at 1.3mp (largest snowfall in NYC's history)

I was always somewhat annoyed I couldn't override it though. heheeh. Fun to see the opposite discussion taking place.

I did some moving timelapse using a different interv. script. Yuri's night in SF last month (april 08). http://www.seej.net/shows/yuri_sf_08/
the motor on the tripod moved really slowly. I was a bit worried someone would mess up the camera, but. People behaved really well around it. Snailpod could even part 8 beer lines without a misstep...something about an inanimate object moving slowly towards people causes them to step aside. Sorry for the high res on this one...Flash can't really handle the 1024x768  30fps.. I shot this in 1600x1200.

I run into situations all the time where hdr timelapse is the key; but, as was pointed out in the HDR timelapse thread, it generally doesn't work so great as multi shot (vs single-ccd hdr) as things move in time too quickly for most hdr timelapse..or, you need fast shutter and really smart post processing.

thanks again all, good discussion
(oh, and if you come up with a timelapse that other's should see, I organize www.t-minus.org, the timelapse film festival; going into its 5th year!)


Offline fbonomi

  • ****
  • 469
  • A570IS SD1100/Ixus80
    • Francesco Bonomi
Re: Timelapse with variable shutter speed
« Reply #78 on: 20 / May / 2008, 17:25:03 »
Ok, second example of dawn timelapse...

Dawn time-Lapse 17

1172 fames, from midnight to about 7:20 AM.

It was a bad night to shoot (a cloudy, rainy night with moonlight) but on the other hand it was a good night to test the script, with a rather unpredictable luminance of the scene.

There is a strong flash at 00:12 (caused by script misbehaviour because of very fast changes in scene luminance)


Offline fbonomi

  • ****
  • 469
  • A570IS SD1100/Ixus80
    • Francesco Bonomi
Re: Timelapse with variable shutter speed
« Reply #79 on: 20 / May / 2008, 17:31:43 »
For the ones interested in the gory details, that's how it works:

It's based on the previous script, but after shooting each frame it builds a (rough) histogram of the RAW data.

The histogram is made of 1024 short ints, each ranging from 0 to 1023.

The uBasic script checks this data and tries to determine if the shot is over-exposed.

A satisfactory way to do this (in frames mainly composed of sky) is to check that at most 10% of the pixels are in the luminance range 100-800.

The logic of this is that if there are artificial lights, with these long exposures they will result in over-exposed pixels (above 800). We will ignore them, as it's normal for them to be over-exposed.

for the rest of the scene, we want a rather dark sky, so at most 10% of the pixels will be allowed to be over luminance 100.

If there are more, the script determines that the frame was over-exposed and decreases the exposure for next shot.

The results are smoothed with a sort of FIFO buffer (with a rudimendary weighting system)

This allows for a certain number of over-exposed pixels (in case arti



If interested in testing this script, please give me your camera model and I will compile the build for you.

Otherwise, see below for a summary of changes made to the core.

Code: [Select]
@title Sunset10
rem Sunset and dawn time-lapses
rem v. 10, Fbonomi may 20th 2008
rem Released under GPL
rem incorporates feedback from previous shot: if more than 10% of pixels
rem are in the 100-800 range, decrease exposure

@param a Delay (sec)
@default a 5

@param b Limit Tv
@default b -414
rem (-414=20 sec; -384=15 sec; -320=10 sec; -224=5 sec.)

@param c Default Sv
@default c 480
rem (480=160)

@param d Limit Sv
@default d 776
rem (776=1250 ISO; 960=5000)

@param e Guess mode limit
@default e -200

@param f Slope in guess mode
@default f 5

print_screen 1

print "Sunset Time Lapse"

rem initialize guess mode value

rem get start Tv
get_tv96 N

rem picture counter

rem exposure factor of previous shot



rem measure luminance and aperture
press "shoot_half"
sleep 500
release "shoot_half"
get_bv96 B
get_av96 A
rem release "shoot_half"

print "Measured: ",B ,A

rem resulting Tv would be:

print "Calculated T: ", N

rem check Tv Values

if N>e then
 rem normal mode, shoot with calculated Tv and default Sc
 print "Mode: Standard"
 rem Guess mode, every shot will be 5/96th steps longer

 rem but if last exposure was over-exposed, don't decrease,
 rem and instead increase
 if h>10 then
  print "Compensating ", h

 rem x has now the desired exposure, we will now attempt
 rem to smooth its value (mobile average over 10 shots)
 rem the last 10 values of x are stored in a FIFO buffer
 rem made by variables Q to Z

 rem The first time we are here, the FIFO buffer will be empty
 rem let's initialize it
 if Z=-1 then

 rem feed the buffer

 rem calculate the average of values stored in FIFO buffer
 P=   Q+Q+Q+Q+Q
 P=P +R+R+R+R
 P=P +S+S+S
 P=P +T+T
 P=P +U


 print "Smoothed ",x, " ", P

 rem P now contains a smoothed value of what was in x

 rem avoid overcompensating (guess mode climbing over guess mode limit)
 if P>e then

 if P>b then
  print "Mode: Guess ", P ,b
  rem we are in dark, but exposure is not too long
  rem normal mode, shoot with guessed Tv and default Sc
  print "Mode: Guess with High ISO", P ,b

  rem we are in very dark area, we want to avoid too long exposures
  rem shoot with maximum allowed time (b) and
  rem adjust Sv accordingly

  rem BUT check we don't go in too high ISO!
  if L>d then

rem we can now shoot
sleep 100
set_sv96 L
sleep 100
set_tv96_direct M
sleep 100
sleep 100
rem let's read histogram of the shot that was just taken
exp_get_info 100 800 h
rem h contains the percentage of pixels that are between 100/1024 and 800/1024
print "SHOOT ",p,M,L,h

sleep a*1000

goto "loop"

Summary of changes made to the C code:

New file:
Code: [Select]
#include "platform.h"
#include "conf.h"
#include "shot_histogram.h"
#include "camera.h"
#include "raw.h"
#include "stdlib.h"

#define RAW_TARGET_FILENAME     "%s_%04d.%s"

unsigned short shot_histogram[1024];
unsigned short shot_margin_left=0, shot_margin_top=0, shot_margin_right=0, shot_margin_bottom=0;

void build_shot_histogram()
 // read samples fromRAW memory and build an histogram of its luminosity
 // actually, it' just reading pixels, ignoring difference between R, G and B,
 // we just need an estimate of luminance
 // SHOT_HISTOGRAM_MARGIN defines a margin around the sensor that will be ignored
 // (dead area)
 int x, y, x0, x1, y0, y1;
 int marginstep;
 short p;
 for (x = 0; x < 1024; x ++ )

 // In future, support definition of a sort of "spot metering"
 x0 = SHOT_HISTOGRAM_MARGIN + shot_margin_left * marginstep;
 x1 = CAM_RAW_ROWPIX - SHOT_HISTOGRAM_MARGIN - shot_margin_right * marginstep;
 y0 = SHOT_HISTOGRAM_MARGIN + shot_margin_top * marginstep;
 y1 = CAM_RAW_ROWS - SHOT_HISTOGRAM_MARGIN - shot_margin_bottom * marginstep;


 // just read one pixel out of SHOT_HISTOGRAM_STEP, one line out of SHOT_HISTOGRAM_STEP
 for (y = y0 ; y < y1; y +=SHOT_HISTOGRAM_STEP )
 for (x = x0 ; x < x1; x +=SHOT_HISTOGRAM_STEP ) 
 // dump to file (just for debugging / logging purposes)
 // for each shoot, creates a HSTnnnnn.DAT file containing 2*1024 bytes
 char fn[64];
 char dir[32];
 sprintf(dir, RAW_TARGET_DIRECTORY, (conf.raw_in_dir)?get_target_dir_num():100);
 sprintf(fn, "%s/", dir);
 sprintf(fn+strlen(fn), RAW_TARGET_FILENAME, "HST", get_target_file_num(), "DAT");
 char buf[64];
 int fd = open(fn, O_WRONLY|O_CREAT, 0777);
 if (fd>=0)
  write(fd, shot_histogram, 2048);

int shot_histogram_get_range(int histo_from, int histo_to)
// Examines the histogram, and returns the percentage of pixels that
// have luminance between histo_from and histo_to
 int x, tot, rng;
 for (x = 0 ; x < 1024; x ++ ) 
tot += shot_histogram[x];
if (x>=histo_from  && x <= histo_to) 
  rng += shot_histogram[x];
 return (rng*100)/tot;

Line 4:
Code: [Select]
#include "shot_histogram.h"

Code: [Select]
Line 28:
   // just after shooting, build shot histogram

Line 48:
Code: [Select]
#include "shot_histogram.h"

Code: [Select]
Line 1552:

// Interface function for uBasic
static void exp_get_info()
    int var;
    int histo_from;
    int histo_to;

    var = tokenizer_variable_num();
    ubasic_set_variable(var, (unsigned short)shot_histogram_get_range(histo_from, histo_to));

Code: [Select]

Line 175
Code: [Select]
  {"exp_get_info",            TOKENIZER_EXP_GET_INFO}, 


Related Topics