Time Lapse Recording

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
tommy
Posts: 45
Joined: Sun Aug 17, 2003 2:58 am

Time Lapse Recording

Post by tommy »

Debian/Mepis
Linux 2.4.22 Kernel
Pentium IV 2.6
786M ram
ZM 1.19.3
4 Cameras on a single bttv chip card
ffmpeg version 0.4.8

Although I am way back on 1.19.3 I think this is also applicable to the current version of zm.

I recently defined a new monitor on my system using the same input as a camera doing motion detection. That is /dev/video0(0) shows twice in my list of zm monitors. This new monitor is set up to do time lapse photography. I set the max fps for all my cameras to 3. On this camera I set the frame skip to 720. At 3fps it should only save an image every 720/3 seconds or approx. every 4 min. I had it set longer but zmaudit closes any event open longer than 5 minutes.
The problem was that when I played back the event, which in this case was 6 hours long, it played fine at 100x or 50x. However when I tried to make a video it failed with this error in the video log:

Creating video file Event-98180.mpg for event 98180
/usr/local/bin/ffmpeg -y -hq -intra -qmax 2 -r 0.00 -s 320x240 -i
%03d-capture.jpg Event-98180.mpg > mpeg.logIncorrect frame rate

Notice the frame rate of 0.00. I traced this back to zmvideo.pl at approx line 237:
elsif ( ZM_OPT_MPEG eq "ffmpeg" )
{
my $frame_rate = sprintf( "%.2f", $event->{Frames}/$event->{FullLength} );
if ( $rate != 1.0 )
{
$frame_rate *= $rate;

My event duration was 20020 sec with 87 frames. This made $frame_rate=.0043 which formatted to 0.00 and ultimately caused the ffmpeg failure.

My fix was to change the formatting to 4 decimal places:
my $frame_rate = sprintf( "%.4f", $event->{Frames}/$event->{FullLength} );

This meant that my frame rate at maximum speed of 100x was still only .43fps, each frame lingering on the screen for almost 1/2 second.

I added these rates to zm_html.php above the 100x
$rates = array(
"90000" => "900x",
"60000" => "600x",
"30000" => "300x",
"10000" => "100x",

and changed the range test in zmvideo.pl to correspond
if ( $rate < 0.25 || $rate > 900 )
{
print( STDERR "Rate is out of range, 0.25 >= rate <= 900\n" );
Usage();
}

I can now take time lapse pictures at anything less than 1 frame every 5 minutes and generate videos to play back at approx 3-4fps.

Hope someone else can use it.

tommy
User avatar
cordel
Posts: 5210
Joined: Fri Mar 05, 2004 4:47 pm
Location: /USA/Washington/Seattle

Post by cordel »

Hi Tommy,
Thanks for that.

Regards,
Corey
Post Reply