Fixes recovering frames from jpegs. Use Time::HiRes stat to get microseconds.

pull/3084/head
Isaac Connor 2020-11-16 11:31:36 -05:00
parent 2c5b13d001
commit 5bf5d58ac1
2 changed files with 20 additions and 14 deletions

View File

@ -41,7 +41,7 @@ require Number::Bytes::Human;
require Date::Parse;
require POSIX;
use Date::Format qw(time2str);
use Time::HiRes qw(gettimeofday tv_interval);
use Time::HiRes qw(gettimeofday tv_interval stat);
#our @ISA = qw(ZoneMinder::Object);
use parent qw(ZoneMinder::Object);
@ -765,44 +765,50 @@ sub recover_timestamps {
return;
}
my @contents = readdir(DIR);
Debug('Have ' . @contents . " files in $path");
Debug('Have ' . @contents . ' files in '.$path);
closedir(DIR);
my @mp4_files = grep( /^\d+\-video\.mp4$/, @contents);
my @mp4_files = grep(/^\d+\-video\.mp4$/, @contents);
if ( @mp4_files ) {
$$Event{DefaultVideo} = $mp4_files[0];
}
my @analyse_jpgs = grep( /^\d+\-analyse\.jpg$/, @contents);
my @analyse_jpgs = grep(/^\d+\-analyse\.jpg$/, @contents);
if ( @analyse_jpgs ) {
$$Event{Save_JPEGs} |= 2;
$$Event{SaveJPEGs} |= 2;
}
my @capture_jpgs = grep( /^\d+\-capture\.jpg$/, @contents);
my @capture_jpgs = grep(/^\d+\-capture\.jpg$/, @contents);
if ( @capture_jpgs ) {
$$Event{Frames} = scalar @capture_jpgs;
$$Event{Save_JPEGs} |= 1;
$$Event{SaveJPEGs} |= 1;
# can get start and end times from stat'ing first and last jpg
@capture_jpgs = sort { $a cmp $b } @capture_jpgs;
my $first_file = "$path/$capture_jpgs[0]";
( $first_file ) = $first_file =~ /^(.*)$/;
my $first_timestamp = (stat($first_file))[9];
my $last_file = "$path/$capture_jpgs[@capture_jpgs-1]";
my $last_file = $path.'/'.$capture_jpgs[@capture_jpgs-1];
( $last_file ) = $last_file =~ /^(.*)$/;
my $last_timestamp = (stat($last_file))[9];
my $duration = $last_timestamp - $first_timestamp;
$Event->Length($duration);
$Event->StartTime( Date::Format::time2str('%Y-%m-%d %H:%M:%S', $first_timestamp) );
if ( $Event->Scheme() eq 'Deep' and $Event->RelativePath(undef) and ($path ne $Event->Path(undef)) ) {
my ( $year, $month, $day, $hour, $minute, $second ) =
($path =~ /(\d{2})\/(\d{2})\/(\d{2})\/(\d{2})\/(\d{2})\/(\d{2})$/);
Error("Updating starttime to $path $year/$month/$day $hour:$minute:$second");
$Event->StartTime(sprintf('%.4d-%.2d-%.2d %.2d:%.2d:%.2d', 2000+$year, $month, $day, $hour, $minute, $second));
}
$Event->EndTime( Date::Format::time2str('%Y-%m-%d %H:%M:%S', $last_timestamp) );
Debug("From capture Jpegs have duration $duration = $last_timestamp - $first_timestamp : $$Event{StartTime} to $$Event{EndTime}");
$ZoneMinder::Database::dbh->begin_work();
foreach my $jpg ( @capture_jpgs ) {
my ( $id ) = $jpg =~ /^(\d+)\-capture\.jpg$/;
if ( ! ZoneMinder::Frame->find_one( EventId=>$$Event{Id}, FrameId=>$id ) ) {
my $file = "$path/$jpg";
if ( ! ZoneMinder::Frame->find_one(EventId=>$$Event{Id}, FrameId=>$id) ) {
my $file = $path.'/'.$jpg;
( $file ) = $file =~ /^(.*)$/;
my $timestamp = (stat($file))[9];
my $Frame = new ZoneMinder::Frame();
@ -813,11 +819,11 @@ sub recover_timestamps {
Type=>'Normal',
Score=>0,
});
}
}
} # end if Frame not found
} # end foreach capture jpg
$ZoneMinder::Database::dbh->commit();
} elsif ( @mp4_files ) {
my $file = "$path/$mp4_files[0]";
my $file = $path.'/'.$mp4_files[0];
( $file ) = $file =~ /^(.*)$/;
my $first_timestamp = (stat($file))[9];

@ -1 +1 @@
Subproject commit 0bd63fb464957080ead342db58ca9e01532cf1ef
Subproject commit 2ab7e23fb4f5b31a2f043ba9b9f607a518007f75