Don't assume filename of mp4. We store it in the event record for a reason. Fixes #3422

This commit is contained in:
Isaac Connor 2022-02-03 17:24:33 -05:00
parent 3c655807e8
commit ac39be33f5
1 changed files with 7 additions and 2 deletions

View File

@ -464,15 +464,18 @@ sub generateImage {
my $event_path = $Event->Path(); my $event_path = $Event->Path();
my $capture_image_path = sprintf('%s/%0'.$Config{ZM_EVENT_IMAGE_DIGITS}.'d-capture.jpg', $event_path, $frame->{FrameId}); my $capture_image_path = sprintf('%s/%0'.$Config{ZM_EVENT_IMAGE_DIGITS}.'d-capture.jpg', $event_path, $frame->{FrameId});
my $analyse_image_path = sprintf('%s/%0'.$Config{ZM_EVENT_IMAGE_DIGITS}.'d-analyse.jpg', $event_path, $frame->{FrameId}) if $analyse; my $analyse_image_path = sprintf('%s/%0'.$Config{ZM_EVENT_IMAGE_DIGITS}.'d-analyse.jpg', $event_path, $frame->{FrameId}) if $analyse;
my $video_path = sprintf('%s/%d-video.mp4', $event_path, $Event->{Id}); my $video_path = sprintf('%s/%s', $event_path, $Event->{DefaultVideo});
my $image_path = ''; my $image_path = '';
# check if the image file exists. If the file doesn't exist and we use H264 try to extract it from .mp4 video # check if the image file exists. If the file doesn't exist and we use H264 try to extract it from .mp4 video
if ( $analyse && -r $analyse_image_path ) { if ( $analyse && -r $analyse_image_path ) {
Debug("Using analysis and jpeg exists $analyse_image_path");
$image_path = $analyse_image_path; $image_path = $analyse_image_path;
} elsif ( -r $capture_image_path ) { } elsif ( -r $capture_image_path ) {
Debug("Using captures and jpeg exists $capture_image_path");
$image_path = $capture_image_path; $image_path = $capture_image_path;
} elsif ( -r $video_path ) { } elsif ( -r $video_path ) {
Debug("mp4 exists $video_path");
my $command ="ffmpeg -nostdin -ss $$frame{Delta} -i '$video_path' -frames:v 1 '$capture_image_path'"; my $command ="ffmpeg -nostdin -ss $$frame{Delta} -i '$video_path' -frames:v 1 '$capture_image_path'";
#$command = "ffmpeg -y -v 0 -i $video_path -vf 'select=gte(n\\,$$frame{FrameId}),setpts=PTS-STARTPTS' -vframes 1 -f image2 $capture_image_path"; #$command = "ffmpeg -y -v 0 -i $video_path -vf 'select=gte(n\\,$$frame{FrameId}),setpts=PTS-STARTPTS' -vframes 1 -f image2 $capture_image_path";
my $output = qx($command); my $output = qx($command);
@ -486,6 +489,8 @@ sub generateImage {
} else { } else {
$image_path = $capture_image_path; $image_path = $capture_image_path;
} }
} else {
Debug("No files found at $analyse_image_path, $capture_image_path or $video_path");
} }
return $image_path; return $image_path;
} }
@ -723,7 +728,7 @@ sub substituteTags {
if ( -e $path ) { if ( -e $path ) {
push @$attachments_ref, { type=>'image/jpeg', path=>$path }; push @$attachments_ref, { type=>'image/jpeg', path=>$path };
} else { } else {
Warning("Path to first image does not exist at $path"); Warning("Path to first image does not exist at $path for image $first_alarm_frame");
} }
} }