generate event video with alarm frames

Anything you want added or changed in future versions of ZoneMinder? Post here and there's a chance it will get in! Search to make sure it hasn't already been requested.
Post Reply
altimeter
Posts: 1
Joined: Tue Oct 10, 2023 7:45 am

generate event video with alarm frames

Post by altimeter »

First and foremost, I want to express my gratitude to the ZoneMinder developers for creating this exceptional application that I've been using for quite some time.

Now, I have a question regarding the generation of event videos that include alarm frames with audio. Currently, all events automatically generate videos, which is fantastic. However, I'd like to enhance this process by replacing the captured frames with alarm frames whenever alarm frames are available during video generation. (So this can clearly show me what triggered the alarms.)

My understanding is that the event videos are created using the 'event.pm' script, and I believe I need to make specific modifications to achieve this. However, I'm not proficient in programming, so I would greatly appreciate some assistance in making the necessary adjustments to the script, particularly in the sections highlighted in red below.


sub GenerateVideo {
my ( $self, $rate, $fps, $scale, $size, $overwrite, $format ) = @_;

my $event_path = $self->Path();
chdir($event_path);
( my $video_name = $self->{Name} ) =~ s/\s/_/g;

my @file_parts;
if ( $rate ) {
my $file_rate = $rate;
$file_rate =~ s/\./_/;
$file_rate =~ s/_00//;
$file_rate =~ s/(_\d+)0+$/$1/;
$file_rate = 'r'.$file_rate;
push( @file_parts, $file_rate );
} elsif ( $fps ) {
my $file_fps = $fps;
$file_fps =~ s/\./_/;
$file_fps =~ s/_00//;
$file_fps =~ s/(_\d+)0+$/$1/;
$file_fps = 'R'.$file_fps;
push( @file_parts, $file_fps );
}

if ( $scale ) {
my $file_scale = $scale;
$file_scale =~ s/\./_/;
$file_scale =~ s/_00//;
$file_scale =~ s/(_\d+)0+$/$1/;
$file_scale = 's'.$file_scale;
push @file_parts, $file_scale;
} elsif ( $size ) {
my $file_size = 'S'.$size;
push @file_parts, $file_size;
}
my $video_file = join('-', $video_name, $file_parts[0], $file_parts[1] ).'.'.$format;
if ( $overwrite || !-s $video_file ) {
Info("Creating video file $video_file for event $self->{Id}");

my $frame_rate = sprintf('%.2f', $self->{Frames}/$self->{FullLength});
if ( $rate ) {
if ( $rate != 1.0 ) {
$frame_rate *= $rate;
}
} elsif ( $fps ) {
$frame_rate = $fps;
}

my $width = $self->{Width};
my $height = $self->{Height};
my $video_size = " ${width}x${height}";

if ( $scale ) {
if ( $scale != 1.0 ) {
$width = int($width*$scale);
$height = int($height*$scale);
$video_size = " ${width}x${height}";
}
} elsif ( $size ) {
$video_size = $size;
}
my $command = $Config{ZM_PATH_FFMPEG}
." -y -r $frame_rate "
.$Config{ZM_FFMPEG_INPUT_OPTIONS}
.' -i ' . ( $$self{DefaultVideo} ? $$self{DefaultVideo} : '%0'.$Config{ZM_EVENT_IMAGE_DIGITS} .'d-capture.jpg' )
#. " -f concat -i /tmp/event_files.txt"
." -s $video_size "
.$Config{ZM_FFMPEG_OUTPUT_OPTIONS}
." '$video_file' > ffmpeg.log 2>&1"
;

Debug($command);
my $output = qx($command);

my $status = $? >> 8;
if ( $status ) {
Error("Unable to generate video, check $event_path/ffmpeg.log for details");
return;
}

Info("Finished $video_file");
return $event_path.'/'.$video_file;
} else {
Info("Video file $video_file already exists for event $self->{Id}");
return $event_path.'/'.$video_file;
}
return;
} # end sub GenerateVideo
Post Reply