fix thumbnail generation from video file

This commit is contained in:
Isaac Connor 2016-04-01 13:02:31 -04:00
parent cbebdfe670
commit ca96481036
1 changed files with 1868 additions and 1878 deletions

View File

@ -19,24 +19,20 @@
//
// Compatibility functions
if ( version_compare( phpversion(), "4.3.0", "<") )
{
function ob_get_clean()
{
if ( version_compare( phpversion(), "4.3.0", "<") ) {
function ob_get_clean() {
$buffer = ob_get_contents();
ob_end_clean();
return( $buffer );
}
}
function userLogin( $username, $password="", $passwordHashed=false )
{
function userLogin( $username, $password="", $passwordHashed=false ) {
global $user, $cookies;
$sql = "select * from Users where Enabled = 1";
$sql_values = NULL;
if ( ZM_AUTH_TYPE == "builtin" )
{
if ( ZM_AUTH_TYPE == "builtin" ) {
if ( $passwordHashed ) {
$sql .= " AND Username=? AND Password=?";
} else {
@ -48,23 +44,18 @@ function userLogin( $username, $password="", $passwordHashed=false )
$sql_values = array( $username );
}
$_SESSION['username'] = $username;
if ( ZM_AUTH_RELAY == "plain" )
{
if ( ZM_AUTH_RELAY == "plain" ) {
// Need to save this in session
$_SESSION['password'] = $password;
}
$_SESSION['remoteAddr'] = $_SERVER['REMOTE_ADDR']; // To help prevent session hijacking
if ( $dbUser = dbFetchOne( $sql, NULL, $sql_values ) )
{
if ( $dbUser = dbFetchOne( $sql, NULL, $sql_values ) ) {
Info( "Login successful for user \"$username\"" );
$_SESSION['user'] = $user = $dbUser;
if ( ZM_AUTH_TYPE == "builtin" )
{
if ( ZM_AUTH_TYPE == "builtin" ) {
$_SESSION['passwordHash'] = $user['Password'];
}
}
else
{
} else {
Warning( "Login denied for user \"$username\"" );
unset( $user );
}
@ -72,8 +63,7 @@ function userLogin( $username, $password="", $passwordHashed=false )
session_write_close();
}
function userLogout()
{
function userLogout() {
global $user;
$username = $user['Username'];
@ -85,8 +75,7 @@ function userLogout()
session_destroy();
}
function noCacheHeaders()
{
function noCacheHeaders() {
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: ".gmdate( "D, d M Y H:i:s" )." GMT"); // always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
@ -97,11 +86,11 @@ function noCacheHeaders()
function CORSHeaders() {
if ( isset( $_SERVER['HTTP_ORIGIN'] ) ) {
# The following is left for future reference/use.
# The following is left for future reference/use.
$valid = false;
$servers = dbFetchAll( 'SELECT * FROM Servers' );
if ( sizeof($servers) <= 1 ) {
# Only need CORSHeaders in the event that there are multiple servers in use.
# Only need CORSHeaders in the event that there are multiple servers in use.
return;
}
foreach( dbFetchAll( 'SELECT * FROM Servers' ) as $row ) {
@ -118,8 +107,7 @@ function CORSHeaders() {
}
}
function getAuthUser( $auth )
{
function getAuthUser( $auth ) {
if ( ZM_OPT_USE_AUTH && ZM_AUTH_RELAY == "hashed" && !empty($auth) )
{
$remoteAddr = "";
@ -275,75 +263,75 @@ function outputVideoStream( $id, $src, $width, $height, $format, $title="" )
{
if ( isWindows() )
{
?>
<object id="<?php echo $id ?>" width="<?php echo validNum($width) ?>" height="<?php echo validNum($height) ?>"
classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902"
standby="Loading Microsoft Windows Media Player components..."
type="<?php echo $mimeType ?>">
<param name="FileName" value="<?php echo $src ?>"/>
<param name="autoStart" value="1"/>
<param name="showControls" value="0"/>
<embed type="<?php echo $mimeType ?>"
pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"
src="<?php echo $src ?>"
name="<?php echo validHtmlStr($title) ?>"
width="<?php echo validNum($width) ?>"
height="<?php echo validInt($height) ?>"
autostart="1"
showcontrols="0">
</embed>
</object>
<?php
?>
<object id="<?php echo $id ?>" width="<?php echo validNum($width) ?>" height="<?php echo validNum($height) ?>"
classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902"
standby="Loading Microsoft Windows Media Player components..."
type="<?php echo $mimeType ?>">
<param name="FileName" value="<?php echo $src ?>"/>
<param name="autoStart" value="1"/>
<param name="showControls" value="0"/>
<embed type="<?php echo $mimeType ?>"
pluginspage="http://www.microsoft.com/Windows/MediaPlayer/"
src="<?php echo $src ?>"
name="<?php echo validHtmlStr($title) ?>"
width="<?php echo validNum($width) ?>"
height="<?php echo validInt($height) ?>"
autostart="1"
showcontrols="0">
</embed>
</object>
<?php
$objectTag = true;
}
break;
}
case "video/quicktime" :
{
?>
<object id="<?php echo $id ?>" width="<?php echo $width ?>" height="<?php echo $height ?>"
classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
codebase="http://www.apple.com/qtactivex/qtplugin.cab"
type="<?php echo $mimeType ?>">
<param name="src" value="<?php echo $src ?>"/>
<param name="autoplay" VALUE="true"/>
<param name="controller" VALUE="false"/>
<embed type="<?php echo $mimeType ?>"
src="<?php echo $src ?>"
pluginspage="http://www.apple.com/quicktime/download/"
name="<?php echo validHtmlStr($title) ?>"
width="<?php echo validInt($width) ?>"
height="<?php echo validInt($height) ?>"
autoplay="true"
controller="true">
</embed>
</object>
<?php
?>
<object id="<?php echo $id ?>" width="<?php echo $width ?>" height="<?php echo $height ?>"
classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
codebase="http://www.apple.com/qtactivex/qtplugin.cab"
type="<?php echo $mimeType ?>">
<param name="src" value="<?php echo $src ?>"/>
<param name="autoplay" VALUE="true"/>
<param name="controller" VALUE="false"/>
<embed type="<?php echo $mimeType ?>"
src="<?php echo $src ?>"
pluginspage="http://www.apple.com/quicktime/download/"
name="<?php echo validHtmlStr($title) ?>"
width="<?php echo validInt($width) ?>"
height="<?php echo validInt($height) ?>"
autoplay="true"
controller="true">
</embed>
</object>
<?php
$objectTag = true;
break;
}
case "application/x-shockwave-flash" :
{
?>
<object id="<?php echo $id ?>" width="<?php echo $width ?>" height="<?php echo $height ?>"
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
type="<?php echo $mimeType ?>">
<param name="movie" value="<?php echo $src ?>"/>
<param name="quality" value="high"/>
<param name="bgcolor" value="#ffffff"/>
<embed type="<?php echo $mimeType ?>"
pluginspage="http://www.macromedia.com/go/getflashplayer"
src="<?php echo $src ?>"
name="<?php echo validHtmlStr($title) ?>"
width="<?php echo validInt($width) ?>"
height="<?php echo validInt($height) ?>"
quality="high"
bgcolor="#ffffff">
</embed>
</object>
<?php
?>
<object id="<?php echo $id ?>" width="<?php echo $width ?>" height="<?php echo $height ?>"
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
type="<?php echo $mimeType ?>">
<param name="movie" value="<?php echo $src ?>"/>
<param name="quality" value="high"/>
<param name="bgcolor" value="#ffffff"/>
<embed type="<?php echo $mimeType ?>"
pluginspage="http://www.macromedia.com/go/getflashplayer"
src="<?php echo $src ?>"
name="<?php echo validHtmlStr($title) ?>"
width="<?php echo validInt($width) ?>"
height="<?php echo validInt($height) ?>"
quality="high"
bgcolor="#ffffff">
</embed>
</object>
<?php
$objectTag = true;
break;
}
@ -351,120 +339,120 @@ bgcolor="#ffffff">
}
if ( !$objectTag )
{
?>
<embed<?php echo isset($mimeType)?(' type="'.$mimeType.'"'):"" ?>
src="<?php echo $src ?>"
name="<?php echo validHtmlStr($title) ?>"
width="<?php echo validInt($width) ?>"
height="<?php echo validInt($height) ?>"
autostart="1"
autoplay="1"
showcontrols="0"
controller="0">
</embed>
<?php
?>
<embed<?php echo isset($mimeType)?(' type="'.$mimeType.'"'):"" ?>
src="<?php echo $src ?>"
name="<?php echo validHtmlStr($title) ?>"
width="<?php echo validInt($width) ?>"
height="<?php echo validInt($height) ?>"
autostart="1"
autoplay="1"
showcontrols="0"
controller="0">
</embed>
<?php
}
}
function outputImageStream( $id, $src, $width, $height, $title="" )
{
if ( canStreamIframe() ) {
?>
<iframe id="<?php echo $id ?>" src="<?php echo $src ?>" alt="<?php echo validHtmlStr($title) ?>" width="<?php echo $width ?>" height="<?php echo $height ?>"/>
<?php
?>
<iframe id="<?php echo $id ?>" src="<?php echo $src ?>" alt="<?php echo validHtmlStr($title) ?>" width="<?php echo $width ?>" height="<?php echo $height ?>"/>
<?php
} else {
?>
<img id="<?php echo $id ?>" src="<?php echo $src ?>" alt="<?php echo validHtmlStr($title) ?>" width="<?php echo $width ?>" height="<?php echo $height ?>"/>
<?php
?>
<img id="<?php echo $id ?>" src="<?php echo $src ?>" alt="<?php echo validHtmlStr($title) ?>" width="<?php echo $width ?>" height="<?php echo $height ?>"/>
<?php
}
}
function outputControlStream( $src, $width, $height, $monitor, $scale, $target )
{
?>
<form name="ctrlForm" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" target="<?php echo $target ?>">
<input type="hidden" name="view" value="blank">
<input type="hidden" name="mid" value="<?php echo $monitor['Id'] ?>">
<input type="hidden" name="action" value="control">
<?php
?>
<form name="ctrlForm" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" target="<?php echo $target ?>">
<input type="hidden" name="view" value="blank">
<input type="hidden" name="mid" value="<?php echo $monitor['Id'] ?>">
<input type="hidden" name="action" value="control">
<?php
if ( $monitor['CanMoveMap'] )
{
?>
<input type="hidden" name="control" value="moveMap">
<?php
?>
<input type="hidden" name="control" value="moveMap">
<?php
}
elseif ( $monitor['CanMoveRel'] )
{
?>
<input type="hidden" name="control" value="movePseudoMap">
<?php
?>
<input type="hidden" name="control" value="movePseudoMap">
<?php
}
elseif ( $monitor['CanMoveCon'] )
{
?>
<input type="hidden" name="control" value="moveConMap">
<?php
?>
<input type="hidden" name="control" value="moveConMap">
<?php
}
?>
<input type="hidden" name="scale" value="<?php echo $scale ?>">
<input type="image" src="<?php echo $src ?>" width="<?php echo $width ?>" height="<?php echo $height ?>">
</form>
<?php
?>
<input type="hidden" name="scale" value="<?php echo $scale ?>">
<input type="image" src="<?php echo $src ?>" width="<?php echo $width ?>" height="<?php echo $height ?>">
</form>
<?php
}
function outputHelperStream( $id, $src, $width, $height, $title="" )
{
?>
<applet id="<?php echo $id ?>" code="com.charliemouse.cambozola.Viewer"
archive="<?php echo ZM_PATH_CAMBOZOLA ?>"
align="middle"
width="<?php echo $width ?>"
height="<?php echo $height ?>"
title="<?php echo $title ?>">
<param name="accessories" value="none"/>
<param name="url" value="<?php echo $src ?>"/>
</applet>
<?php
?>
<applet id="<?php echo $id ?>" code="com.charliemouse.cambozola.Viewer"
archive="<?php echo ZM_PATH_CAMBOZOLA ?>"
align="middle"
width="<?php echo $width ?>"
height="<?php echo $height ?>"
title="<?php echo $title ?>">
<param name="accessories" value="none"/>
<param name="url" value="<?php echo $src ?>"/>
</applet>
<?php
}
function outputImageStill( $id, $src, $width, $height, $title="" )
{
?>
<img id="<?php echo $id ?>" src="<?php echo $src ?>" alt="<?php echo $title ?>" width="<?php echo $width ?>" height="<?php echo $height ?>"/>
<?php
?>
<img id="<?php echo $id ?>" src="<?php echo $src ?>" alt="<?php echo $title ?>" width="<?php echo $width ?>" height="<?php echo $height ?>"/>
<?php
}
function outputControlStill( $src, $width, $height, $monitor, $scale, $target )
{
?>
<form name="ctrlForm" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" target="<?php echo $target ?>">
<input type="hidden" name="view" value="blank">
<input type="hidden" name="mid" value="<?php echo $monitor['Id'] ?>">
<input type="hidden" name="action" value="control">
<?php
?>
<form name="ctrlForm" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" target="<?php echo $target ?>">
<input type="hidden" name="view" value="blank">
<input type="hidden" name="mid" value="<?php echo $monitor['Id'] ?>">
<input type="hidden" name="action" value="control">
<?php
if ( $monitor['CanMoveMap'] )
{
?>
<input type="hidden" name="control" value="moveMap">
<?php
?>
<input type="hidden" name="control" value="moveMap">
<?php
}
elseif ( $monitor['CanMoveRel'] )
{
?>
<input type="hidden" name="control" value="movePseudoMap">
<?php
?>
<input type="hidden" name="control" value="movePseudoMap">
<?php
}
elseif ( $monitor['CanMoveCon'] )
{
?>
<input type="hidden" name="control" value="moveConMap">
<?php
?>
<input type="hidden" name="control" value="moveConMap">
<?php
}
?>
<input type="hidden" name="scale" value="<?php echo $scale ?>">
<input type="image" src="<?php echo $src ?>" width="<?php echo $width ?>" height="<?php echo $height ?>">
</form>
<?php
?>
<input type="hidden" name="scale" value="<?php echo $scale ?>">
<input type="image" src="<?php echo $src ?>" width="<?php echo $width ?>" height="<?php echo $height ?>">
</form>
<?php
}
// Incoming args are shell-escaped. This function must escape any further arguments it cannot guarantee.
@ -527,7 +515,7 @@ function getEventPath( $event )
function getEventDefaultVideoPath( $event ) {
$Event = new Event( $event );
return $Event->getStreamSrc( array( "mode=mpeg" ) );
//$Event->Path().'/'.$event['DefaultVideo'];
//$Event->Path().'/'.$event['DefaultVideo'];
}
function deletePath( $path )
@ -550,7 +538,7 @@ function deleteEvent( $event ) {
}
if ( gettype($event) != 'array' ) {
# $event could be an eid, so turn it into an event hash
# $event could be an eid, so turn it into an event hash
$event = new Event( $event );
}
@ -675,18 +663,18 @@ function buildSelect( $name, $contents, $behaviours=false )
$behaviourText = ' onchange="'.$behaviours.'"';
}
}
?>
<select name="<?php echo $name ?>" id="<?php echo $name ?>"<?php echo $behaviourText ?>>
<?php
?>
<select name="<?php echo $name ?>" id="<?php echo $name ?>"<?php echo $behaviourText ?>>
<?php
foreach ( $contents as $contentValue => $contentText )
{
?>
<option value="<?php echo $contentValue ?>"<?php if ( $value == $contentValue ) { ?> selected="selected"<?php } ?>><?php echo validHtmlStr($contentText) ?></option>
<?php
?>
<option value="<?php echo $contentValue ?>"<?php if ( $value == $contentValue ) { ?> selected="selected"<?php } ?>><?php echo validHtmlStr($contentText) ?></option>
<?php
}
?>
</select>
<?php
?>
</select>
<?php
$html = ob_get_contents();
ob_end_clean();
@ -1135,54 +1123,59 @@ function zmaCheck( $monitor )
return( daemonCheck( "zma", "-m $monitor" ) );
}
function getImageSrc( $event, $frame, $scale=SCALE_BASE, $captureOnly=false, $overwrite=false )
{
require_once('includes/Storage.php');
$eventPath = getEventPath( $event );
function getImageSrc( $event, $frame, $scale=SCALE_BASE, $captureOnly=false, $overwrite=false ) {
$Storage = new Storage( $event['StorageId'] );
$Event = new Event( $event );
$eventPath = $Event->Path();
if ( !is_array($frame) )
$frame = array( 'FrameId'=>$frame, 'Type'=>'' );
//echo "S:$scale, CO:$captureOnly<br>";
$currEvent = dbFetchOne( 'SELECT M.SaveJPEGs FROM Events AS E INNER JOIN Monitors AS M ON E.MonitorId = M.Id WHERE E.Id = '.$event['Id'] );
if ( $currEvent['SaveJPEGs'] == "4" ) {
# Snapshot only mode
if ( file_exists( $eventPath.'/snapshot.jpg' ) ) {
$captImage = "snapshot.jpg";
} else {
$captImage = sprintf( "%0".ZM_EVENT_IMAGE_DIGITS."d-capture.jpg", $frame['FrameId'] );
if ( $currEvent['SaveJPEGs'] == "0" ) {
# No JPEG saving, must pull from video
if ( ! file_exists( $Storage->Path() .'/'.$eventPath.'/'.$captImage ) ) {
# Generate the frame JPG
# See issue #1379
if ( ! file_exists( $eventPath.'/'.$captImage ) ) {
# Generate the frame JPG
if ( $Event->DefaultVideo() ) {
$command ='ffmpeg -v 0 -i '.$eventPath.'/'.$Event->DefaultVideo().' -vf "select=gte(n\\,'.$frame['FrameId'].'),setpts=PTS-STARTPTS" '.$eventPath.'/'.$captImage;
Debug( "Running $command" );
$output = array();
$retval = 0;
exec( $command, $output, $retval );
Debug("Retval: $retval, output: " . implode("\n", $output));
} else {
Error("Can't create frame images from video becuase there is no video file for this event (".$Event->DefaultVideo() );
}
}
}
$captPath = $eventPath.'/'.$captImage;
if ( ! file_exists( $captPath ) ) {
Error( "Capture file does not exist at $captPath" );
return '';
}
$thumbCaptPath = ZM_DIR_IMAGES.'/'.$event['Id'].'-'.$captImage;
//echo "CI:$captImage, CP:$captPath, TCP:$thumbCaptPath<br>";
$analImage = sprintf( "%0".ZM_EVENT_IMAGE_DIGITS."d-analyse.jpg", $frame['FrameId'] );
$analPath = $eventPath.'/'.$analImage;
$analFile = $Storage->Path()."/".$analPath;
$thumbAnalPath = ZM_DIR_IMAGES.'/'.$event['Id'].'-'.$analImage;
//echo "AI:$analImage, AP:$analPath, TAP:$thumbAnalPath<br>";
$alarmFrame = $frame['Type']=='Alarm';
$hasAnalImage = $alarmFrame && file_exists( $analFile ) && filesize( $analFile );
$hasAnalImage = $alarmFrame && file_exists( $analPath ) && filesize( $analPath );
$isAnalImage = $hasAnalImage && !$captureOnly;
if ( !ZM_WEB_SCALE_THUMBS || $scale >= SCALE_BASE || !function_exists( 'imagecreatefromjpeg' ) )
{
if ( !ZM_WEB_SCALE_THUMBS || $scale >= SCALE_BASE || !function_exists( 'imagecreatefromjpeg' ) ) {
$imagePath = $thumbPath = $isAnalImage?$analPath:$captPath;
$imageFile = $Storage->Path()."/".$imagePath;
$thumbFile = $Storage->Path()."/".$thumbPath;
}
else
{
$imageFile = $imagePath;
$thumbFile = $thumbPath;
} else {
if ( version_compare( phpversion(), "4.3.10", ">=") )
$fraction = sprintf( "%.3F", $scale/SCALE_BASE );
else
@ -1192,19 +1185,15 @@ function getImageSrc( $event, $frame, $scale=SCALE_BASE, $captureOnly=false, $ov
$thumbCaptPath = preg_replace( "/\.jpg$/", "-$scale.jpg", $thumbCaptPath );
$thumbAnalPath = preg_replace( "/\.jpg$/", "-$scale.jpg", $thumbAnalPath );
if ( $isAnalImage )
{
if ( $isAnalImage ) {
$imagePath = $analPath;
$thumbPath = $thumbAnalPath;
}
else
{
} else {
$imagePath = $captPath;
$thumbPath = $thumbCaptPath;
}
$imageFile = $Storage->Path()."/".$imagePath;
//$thumbFile = ZM_DIR_EVENTS."/".$thumbPath;
$imageFile = $imagePath;
$thumbFile = $thumbPath;
if ( $overwrite || !file_exists( $thumbFile ) || !filesize( $thumbFile ) )
{
@ -1234,8 +1223,6 @@ function getImageSrc( $event, $frame, $scale=SCALE_BASE, $captureOnly=false, $ov
'hasAnalImage' => $hasAnalImage,
);
//echo "IP:$imagePath<br>";
//echo "TP:$thumbPath<br>";
return( $imageData );
}
@ -1255,7 +1242,7 @@ function viewImagePath( $path, $querySep='&amp;' )
function createListThumbnail( $event, $overwrite=false )
{
# Load the frame with the highest score to use as a thumbnail
# Load the frame with the highest score to use as a thumbnail
if ( !($frame = dbFetchOne( "SELECT * FROM Frames WHERE EventId=? AND Score=? ORDER BY FrameId LIMIT 1", NULL, array( $event['Id'], $event['MaxScore'] ) )) )
return( false );
@ -1279,6 +1266,9 @@ function createListThumbnail( $event, $overwrite=false )
}
$imageData = getImageSrc( $event, $frame, $scale, false, $overwrite );
if ( ! $imageData ) {
return ( false );;
}
$thumbData = $frame;
$thumbData['Path'] = $imageData['thumbPath'];
$thumbData['Width'] = (int)$thumbWidth;
@ -1703,9 +1693,9 @@ function sidField()
if ( SID )
{
list( $sessname, $sessid ) = explode( "=", SID );
?>
<input type="hidden" name="<?php echo $sessname ?>" value="<?php echo $sessid ?>"/>
<?php
?>
<input type="hidden" name="<?php echo $sessname ?>" value="<?php echo $sessid ?>"/>
<?php
}
}