Convert Fatal()s to Errors() which is really more appropriate anyways. Maybe Fixes #3426

This commit is contained in:
Isaac Connor 2022-02-08 18:11:33 -05:00
parent 3abacfa488
commit 687818e1ec
1 changed files with 59 additions and 49 deletions

View File

@ -65,7 +65,7 @@ if ( empty($_REQUEST['path']) ) {
if ( empty($_REQUEST['fid']) ) { if ( empty($_REQUEST['fid']) ) {
header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
ZM\Fatal('No Frame ID specified'); ZM\Error('No Frame ID specified');
return; return;
} }
@ -73,47 +73,50 @@ if ( empty($_REQUEST['path']) ) {
$Event = ZM\Event::find_one(array('Id'=>$_REQUEST['eid'])); $Event = ZM\Event::find_one(array('Id'=>$_REQUEST['eid']));
if ( !$Event ) { if ( !$Event ) {
header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
ZM\Fatal('Event '.$_REQUEST['eid'].' Not found'); ZM\Error('Event '.$_REQUEST['eid'].' Not found');
return; return;
} }
if ( $_REQUEST['fid'] == 'objdetect' ) { if ( $_REQUEST['fid'] == 'objdetect' ) {
// if animation file is found, return that, else return image // if animation file is found, return that, else return image
// we are only looking for GIF or jpg here, not mp4 // we are only looking for GIF or jpg here, not mp4
// as most often, browsers asking for this link will be expecting // as most often, browsers asking for this link will be expecting
// media types that can be rendered as <img src=> // media types that can be rendered as <img src=>
$path_anim_gif = $Event->Path().'/objdetect.gif'; $path_anim_gif = $Event->Path().'/objdetect.gif';
$path_image = $Event->Path().'/objdetect.jpg'; $path_image = $Event->Path().'/objdetect.jpg';
if (file_exists($path_anim_gif)) { if (file_exists($path_anim_gif)) {
// we found the animation gif file // we found the animation gif file
$media_type = 'image/gif'; $media_type = 'image/gif';
ZM\Debug("Animation file found at $path"); ZM\Debug("Animation file found at $path");
$path = $path_anim_gif; $path = $path_anim_gif;
} else if (file_exists($path_image)) { } else if (file_exists($path_image)) {
// animation not found, but image found // animation not found, but image found
ZM\Debug("Image file found at $path"); ZM\Debug("Image file found at $path");
$path = $path_image; $path = $path_image;
} else { } else {
// neither animation nor image found // neither animation nor image found
header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
ZM\Fatal("Object detection animation and image not found for this event"); ZM\Error('Object detection animation and image not found for this event');
} return;
$Frame = new ZM\Frame(); }
$Frame->Id('objdetect'); $Frame = new ZM\Frame();
} else if ( $_REQUEST['fid'] == 'objdetect_mp4' ) { $Frame->Id('objdetect');
$path = $Event->Path().'/objdetect.mp4'; } else if ( $_REQUEST['fid'] == 'objdetect_mp4' ) {
if ( !file_exists($path) ) { $path = $Event->Path().'/objdetect.mp4';
header('HTTP/1.0 404 Not Found'); if ( !file_exists($path) ) {
ZM\Fatal("File $path does not exist. You might not have enabled create_animation in objectconfig.ini. If you have, inspect debug logs for errors during creation"); header('HTTP/1.0 404 Not Found');
} ZM\Error("File $path does not exist. You might not have enabled create_animation in objectconfig.ini. If you have, inspect debug logs for errors during creation");
$Frame = new ZM\Frame(); return;
$Frame->Id('objdetect'); }
$media_type = 'video/mp4'; $Frame = new ZM\Frame();
} else if ( $_REQUEST['fid'] == 'objdetect_gif' ) { $Frame->Id('objdetect');
$path = $Event->Path().'/objdetect.gif'; $media_type = 'video/mp4';
if ( !file_exists($path) ) { } else if ( $_REQUEST['fid'] == 'objdetect_gif' ) {
header('HTTP/1.0 404 Not Found'); $path = $Event->Path().'/objdetect.gif';
ZM\Fatal("File $path does not exist. You might not have enabled create_animation in objectconfig.ini. If you have, inspect debug logs for errors during creation"); if ( !file_exists($path) ) {
header('HTTP/1.0 404 Not Found');
ZM\Error("File $path does not exist. You might not have enabled create_animation in objectconfig.ini. If you have, inspect debug logs for errors during creation");
return;
} }
$Frame = new ZM\Frame(); $Frame = new ZM\Frame();
$Frame->Id('objdetect'); $Frame->Id('objdetect');
@ -122,7 +125,8 @@ if ( empty($_REQUEST['path']) ) {
$path = $Event->Path().'/objdetect.jpg'; $path = $Event->Path().'/objdetect.jpg';
if ( !file_exists($path) ) { if ( !file_exists($path) ) {
header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
ZM\Fatal("File $path does not exist. Please make sure store_frame_in_zm is enabled in the object detection config"); ZM\Error("File $path does not exist. Please make sure store_frame_in_zm is enabled in the object detection config");
return;
} }
$Frame = new ZM\Frame(); $Frame = new ZM\Frame();
$Frame->Id('objdetect'); $Frame->Id('objdetect');
@ -149,7 +153,7 @@ if ( empty($_REQUEST['path']) ) {
$path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d', $Frame->FrameId()).'-'.$show.'.jpg'; $path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d', $Frame->FrameId()).'-'.$show.'.jpg';
} else { } else {
header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
ZM\Fatal('No alarm jpg found for event '.$_REQUEST['eid']); ZM\Error('No alarm jpg found for event '.$_REQUEST['eid']);
return; return;
} }
} else { } else {
@ -189,11 +193,12 @@ if ( empty($_REQUEST['path']) ) {
ZM\Debug("Command: $command, retval: $retval, output: " . implode("\n", $output)); ZM\Debug("Command: $command, retval: $retval, output: " . implode("\n", $output));
if ( ! file_exists($path) ) { if ( ! file_exists($path) ) {
header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
ZM\Fatal('Can\'t create frame images from video for this event '.$Event->DefaultVideo().' ZM\Error('Can\'t create frame images from video for this event '.$Event->DefaultVideo().'
Command was: '.$command.' Command was: '.$command.'
Output was: '.implode(PHP_EOL,$output) ); Output was: '.implode(PHP_EOL,$output) );
return;
} }
# Generating an image file will use up more disk space, so update the Event record. # Generating an image file will use up more disk space, so update the Event record.
if ( $Event->EndDateTime() ) { if ( $Event->EndDateTime() ) {
@ -202,7 +207,7 @@ if ( empty($_REQUEST['path']) ) {
} }
} else { } else {
header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
ZM\Fatal('No snapshot jpg found for event '.$_REQUEST['eid']); ZM\Error('No snapshot jpg found for event '.$_REQUEST['eid']);
return; return;
} }
} # end if stored jpgs } # end if stored jpgs
@ -231,7 +236,8 @@ if ( empty($_REQUEST['path']) ) {
$Frame->Delta($previousBulkFrame['Delta'] + floor( 100* ( $nextBulkFrame['Delta'] - $previousBulkFrame['Delta'] ) * $percentage )/100); $Frame->Delta($previousBulkFrame['Delta'] + floor( 100* ( $nextBulkFrame['Delta'] - $previousBulkFrame['Delta'] ) * $percentage )/100);
ZM\Debug('Got virtual frame from Bulk Frames previous delta: ' . $previousBulkFrame['Delta'] . ' + nextdelta:' . $nextBulkFrame['Delta'] . ' - ' . $previousBulkFrame['Delta'] . ' * ' . $percentage ); ZM\Debug('Got virtual frame from Bulk Frames previous delta: ' . $previousBulkFrame['Delta'] . ' + nextdelta:' . $nextBulkFrame['Delta'] . ' - ' . $previousBulkFrame['Delta'] . ' * ' . $percentage );
} else { } else {
ZM\Fatal('No Frame found for event('.$_REQUEST['eid'].') and frame id('.$_REQUEST['fid'].')'); ZM\Error('No Frame found for event('.$_REQUEST['eid'].') and frame id('.$_REQUEST['fid'].')');
return;
} }
} # end if !Frame } # end if !Frame
// Frame can be non-existent. We have Bulk frames. So now we should try to load the bulk frame // Frame can be non-existent. We have Bulk frames. So now we should try to load the bulk frame
@ -244,14 +250,14 @@ if ( empty($_REQUEST['path']) ) {
$Frame = ZM\Frame::find_one(array('Id'=>$_REQUEST['fid'])); $Frame = ZM\Frame::find_one(array('Id'=>$_REQUEST['fid']));
if ( !$Frame ) { if ( !$Frame ) {
header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
ZM\Fatal('Frame ' . $_REQUEST['fid'] . ' Not Found'); ZM\Error('Frame ' . $_REQUEST['fid'] . ' Not Found');
return; return;
} }
$Event = ZM\Event::find_one(array('Id'=>$Frame->EventId())); $Event = ZM\Event::find_one(array('Id'=>$Frame->EventId()));
if ( !$Event ) { if ( !$Event ) {
header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
ZM\Fatal('Event ' . $Frame->EventId() . ' Not Found'); ZM\Error('Event ' . $Frame->EventId() . ' Not Found');
return; return;
} }
$path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-'.$show.'.jpg'; $path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-'.$show.'.jpg';
@ -263,7 +269,8 @@ if ( empty($_REQUEST['path']) ) {
if ( ($show == 'capture') and $Event->DefaultVideo() ) { if ( ($show == 'capture') and $Event->DefaultVideo() ) {
if ( !file_exists($Event->Path().'/'.$Event->DefaultVideo()) ) { if ( !file_exists($Event->Path().'/'.$Event->DefaultVideo()) ) {
header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
ZM\Fatal("Can't create frame images from video because there is no video file for this event at (".$Event->Path().'/'.$Event->DefaultVideo() ); ZM\Error("Can't create frame images from video because there is no video file for this event at (".$Event->Path().'/'.$Event->DefaultVideo() );
return;
} }
$command = ZM_PATH_FFMPEG.' -ss '. $Frame->Delta() .' -i '.$Event->Path().'/'.$Event->DefaultVideo().' -frames:v 1 '.$path . ' 2>&1'; $command = ZM_PATH_FFMPEG.' -ss '. $Frame->Delta() .' -i '.$Event->Path().'/'.$Event->DefaultVideo().' -frames:v 1 '.$path . ' 2>&1';
#$command ='ffmpeg -ss '. $Frame->Delta() .' -i '.$Event->Path().'/'.$Event->DefaultVideo().' -vf "select=gte(n\\,'.$Frame->FrameId().'),setpts=PTS-STARTPTS" '.$path; #$command ='ffmpeg -ss '. $Frame->Delta() .' -i '.$Event->Path().'/'.$Event->DefaultVideo().' -vf "select=gte(n\\,'.$Frame->FrameId().'),setpts=PTS-STARTPTS" '.$path;
@ -275,11 +282,12 @@ if ( empty($_REQUEST['path']) ) {
ZM\Debug("Command: $command, retval: $retval, output: " . implode("\n", $output)); ZM\Debug("Command: $command, retval: $retval, output: " . implode("\n", $output));
if ( ! file_exists($path) ) { if ( ! file_exists($path) ) {
header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
ZM\Fatal('Can\'t create frame images from video for this event '.$Event->DefaultVideo().' ZM\Error('Can\'t create frame images from video for this event '.$Event->DefaultVideo().'
Command was: '.$command.' Command was: '.$command.'
Output was: '.implode(PHP_EOL,$output) ); Output was: '.implode(PHP_EOL,$output) );
return;
} }
# Generating an image file will use up more disk space, so update the Event record. # Generating an image file will use up more disk space, so update the Event record.
if ( $Event->EndDateTime() ) { if ( $Event->EndDateTime() ) {
@ -288,8 +296,9 @@ Output was: '.implode(PHP_EOL,$output) );
} }
} else { } else {
header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
ZM\Fatal("Can't create frame $show images from video because there is no video file for this event at ". ZM\Error("Can't create frame $show images from video because there is no video file for this event at ".
$Event->Path().'/'.$Event->DefaultVideo() ); $Event->Path().'/'.$Event->DefaultVideo() );
return;
} }
} # end if ! file_exists($path) } # end if ! file_exists($path)
@ -317,7 +326,8 @@ Output was: '.implode(PHP_EOL,$output) );
} }
if ( !file_exists($path) ) { if ( !file_exists($path) ) {
header('HTTP/1.0 404 Not Found'); header('HTTP/1.0 404 Not Found');
ZM\Fatal("Image not found at $path"); ZM\Error("Image not found at $path");
return;
} }
} }