2008-07-14 21:54:50 +08:00
< ? php
//
// ZoneMinder web video view file, $Date$, $Revision$
2008-07-25 17:48:16 +08:00
// Copyright (C) 2001-2008 Philip Coombes
2008-07-14 21:54:50 +08:00
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
2016-12-26 23:23:16 +08:00
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2008-07-14 21:54:50 +08:00
//
2018-06-06 23:41:00 +08:00
if ( ! canView ( 'Events' ) ) {
$view = 'error' ;
2017-08-09 21:54:27 +08:00
return ;
2008-07-14 21:54:50 +08:00
}
2017-08-09 21:54:27 +08:00
require_once ( 'includes/Event.php' );
2015-02-24 03:31:15 +08:00
$eid = validInt ( $_REQUEST [ 'eid' ]);
2020-02-26 07:12:25 +08:00
$event = new ZM\Event ( $eid );
2008-07-14 21:54:50 +08:00
2020-02-26 07:12:25 +08:00
if ( ! canView ( 'Monitors' , $event -> MonitorId () ) ) {
$view = 'error' ;
return ;
2015-02-24 03:31:15 +08:00
}
2008-07-14 21:54:50 +08:00
2020-02-26 07:12:25 +08:00
$monitor = $event -> Monitor ();
2018-06-06 23:41:00 +08:00
if ( isset ( $_REQUEST [ 'rate' ]) )
2017-08-09 21:54:27 +08:00
$rate = validInt ( $_REQUEST [ 'rate' ]);
2008-09-26 17:47:20 +08:00
else
2020-02-26 07:12:25 +08:00
$rate = reScale ( RATE_BASE , $monitor -> DefaultRate (), ZM_WEB_DEFAULT_RATE );
2018-06-06 23:41:00 +08:00
if ( isset ( $_REQUEST [ 'scale' ]) )
2017-08-09 21:54:27 +08:00
$scale = validInt ( $_REQUEST [ 'scale' ]);
2008-09-26 17:47:20 +08:00
else
2020-02-26 07:12:25 +08:00
$scale = reScale ( SCALE_BASE , $monitor -> DefaultScale (), ZM_WEB_DEFAULT_SCALE );
2008-07-14 21:54:50 +08:00
2020-02-26 07:12:25 +08:00
$event_path = $event -> Path ();
2008-07-14 21:54:50 +08:00
$videoFormats = array ();
2018-06-06 23:41:00 +08:00
$ffmpegFormats = preg_split ( '/\s+/' , ZM_FFMPEG_FORMATS );
2017-08-09 21:54:27 +08:00
foreach ( $ffmpegFormats as $ffmpegFormat ) {
2018-06-06 23:41:00 +08:00
if ( preg_match ( '/^([^*]+)(\*\*?)$/' , $ffmpegFormat , $matches ) ) {
2017-08-09 21:54:27 +08:00
$videoFormats [ $matches [ 1 ]] = $matches [ 1 ];
if ( ! isset ( $videoFormat ) && $matches [ 2 ] == '*' ) {
$videoFormat = $matches [ 1 ];
2008-07-14 21:54:50 +08:00
}
2017-08-09 21:54:27 +08:00
} else {
$videoFormats [ $ffmpegFormat ] = $ffmpegFormat ;
}
2008-07-14 21:54:50 +08:00
}
$videoFiles = array ();
2020-02-26 07:12:25 +08:00
if ( $dir = opendir ( $event_path ) ) {
2018-06-06 23:41:00 +08:00
while ( ( $file = readdir ( $dir )) !== false ) {
2020-02-26 07:12:25 +08:00
$file = $event_path . '/' . $file ;
2018-06-06 23:41:00 +08:00
if ( is_file ( $file ) ) {
if ( preg_match ( '/\.(?:' . join ( '|' , $videoFormats ) . ')$/' , $file ) ) {
2017-08-09 21:54:27 +08:00
$videoFiles [] = $file ;
}
2008-07-14 21:54:50 +08:00
}
2017-08-09 21:54:27 +08:00
}
2018-06-06 23:41:00 +08:00
closedir ( $dir );
2008-07-14 21:54:50 +08:00
}
2017-08-09 21:54:27 +08:00
if ( isset ( $_REQUEST [ 'deleteIndex' ]) ) {
$deleteIndex = validInt ( $_REQUEST [ 'deleteIndex' ]);
2018-06-06 23:41:00 +08:00
unlink ( $videoFiles [ $deleteIndex ]);
unset ( $videoFiles [ $deleteIndex ]);
2008-07-14 21:54:50 +08:00
}
2017-08-09 21:54:27 +08:00
if ( isset ( $_REQUEST [ 'downloadIndex' ]) ) {
2018-06-06 23:55:51 +08:00
// can't be output buffering, as this file might be large
ob_end_clean ();
2017-08-09 21:54:27 +08:00
$downloadIndex = validInt ( $_REQUEST [ 'downloadIndex' ]);
2020-02-26 07:12:25 +08:00
ZM\Error ( " Download $downloadIndex , file: " . $videoFiles [ $downloadIndex ]);
2018-06-06 23:41:00 +08:00
header ( 'Pragma: public' );
header ( 'Expires: 0' );
header ( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header ( 'Cache-Control: private' , false ); // required by certain browsers
header ( 'Content-Description: File Transfer' );
header ( 'Content-disposition: attachment; filename="' . basename ( $videoFiles [ $downloadIndex ]) . '"' ); // basename is required because the video index contains the path and firefox doesn't strip the path but simply replaces the slashes with an underscore.
header ( 'Content-Transfer-Encoding: binary' );
header ( 'Content-Type: application/force-download' );
header ( 'Content-Length: ' . filesize ( $videoFiles [ $downloadIndex ]));
readfile ( $videoFiles [ $downloadIndex ]);
2017-08-09 21:54:27 +08:00
exit ;
2008-07-14 21:54:50 +08:00
}
$focusWindow = true ;
2018-06-06 23:41:00 +08:00
xhtmlHeaders ( __FILE__ , translate ( 'Video' ));
2008-07-14 21:54:50 +08:00
?>
< body >
< div id = " page " >
< div id = " header " >
< div id = " headerButtons " >
2019-01-16 22:59:58 +08:00
< a href = " # " data - on - click = " closeWindow " >< ? php echo translate ( 'Close' ) ?> </a>
2008-07-14 21:54:50 +08:00
</ div >
2015-05-10 21:10:30 +08:00
< h2 >< ? php echo translate ( 'Video' ) ?> </h2>
2008-07-14 21:54:50 +08:00
</ div >
< div id = " content " >
< ? php
2017-08-09 21:54:27 +08:00
if ( isset ( $_REQUEST [ 'showIndex' ]) ) {
$showIndex = validInt ( $_REQUEST [ 'showIndex' ]);
2018-06-06 23:41:00 +08:00
preg_match ( '/([^\/]+)\.([^.]+)$/' , $videoFiles [ $showIndex ], $matches );
2017-08-09 21:54:27 +08:00
$name = $matches [ 1 ];
$videoFormat = $matches [ 2 ];
2008-07-14 21:54:50 +08:00
?>
2018-06-06 23:41:00 +08:00
< h3 id = " videoFile " >< ? php echo substr ( $videoFiles [ $showIndex ], strlen ( ZM_DIR_EVENTS ) + 1 ) ?> </h3>
< div id = " imageFeed " >< ? php outputVideoStream ( 'videoStream' , $videoFiles [ $showIndex ], validInt ( $_REQUEST [ 'width' ]), validInt ( $_REQUEST [ 'height' ]), $videoFormat , $name ) ?> </div>
2008-07-14 21:54:50 +08:00
< ? php
2017-08-09 21:54:27 +08:00
} else {
2008-07-14 21:54:50 +08:00
?>
2020-10-05 22:37:00 +08:00
< form name = " contentForm " id = " videoForm " method = " post " action = " ? " >
2020-02-26 07:12:25 +08:00
< input type = " hidden " name = " id " value = " <?php echo $event->Id () ?> " />
2018-06-06 23:41:00 +08:00
< table id = " contentTable " class = " minor " >
2008-07-14 21:54:50 +08:00
< tbody >
< tr >
2015-05-10 21:10:30 +08:00
< th scope = " row " >< ? php echo translate ( 'VideoFormat' ) ?> </th>
2018-06-06 23:41:00 +08:00
< td >< ? php echo buildSelect ( 'videoFormat' , $videoFormats ) ?> </td>
2008-07-14 21:54:50 +08:00
</ tr >
< tr >
2015-05-10 21:10:30 +08:00
< th scope = " row " >< ? php echo translate ( 'FrameRate' ) ?> </th>
2018-06-06 23:41:00 +08:00
< td >< ? php echo buildSelect ( 'rate' , $rates ) ?> </td>
2008-07-14 21:54:50 +08:00
</ tr >
< tr >
2015-05-10 21:10:30 +08:00
< th scope = " row " >< ? php echo translate ( 'VideoSize' ) ?> </th>
2018-06-06 23:41:00 +08:00
< td >< ? php echo buildSelect ( 'scale' , $scales ) ?> </td>
2008-07-14 21:54:50 +08:00
</ tr >
< tr >
2015-05-10 21:10:30 +08:00
< th scope = " row " >< ? php echo translate ( 'OverwriteExisting' ) ?> </th>
2008-07-14 21:54:50 +08:00
< td >< input type = " checkbox " name = " overwrite " value = " 1 " < ? php if ( ! empty ( $_REQUEST [ 'overwrite' ]) ) { ?> checked="checked"<?php } ?>/></td>
</ tr >
</ tbody >
</ table >
2020-02-26 07:12:25 +08:00
< button type = " button " data - on - click = " generateVideo " < ? php if ( ! ZM_OPT_FFMPEG ) { ?> disabled="disabled"<?php } ?>>
< ? php echo translate ( 'GenerateVideo' ) ?>
</ button >
2008-07-14 21:54:50 +08:00
</ form >
< ? php
2017-08-09 21:54:27 +08:00
if ( isset ( $_REQUEST [ 'generated' ]) ) {
2008-07-14 21:54:50 +08:00
?>
2018-06-06 23:41:00 +08:00
< h2 id = " videoProgress " class = " <?php echo $_REQUEST['generated'] ?'infoText':'errorText' ?> " >
< span id = " videoProgressText " >< ? php echo $_REQUEST [ 'generated' ] ? translate ( 'VideoGenSucceeded' ) : translate ( 'VideoGenFailed' ) ?> </span>
< span id = " videoProgressTicker " ></ span >
</ h2 >
2008-07-14 21:54:50 +08:00
< ? php
2017-08-09 21:54:27 +08:00
} else {
2008-07-14 21:54:50 +08:00
?>
2018-06-06 23:41:00 +08:00
< h2 id = " videoProgress " class = " hidden warnText " >
< span id = " videoProgressText " >< ? php echo translate ( 'GeneratingVideo' ) ?> </span>
< span id = " videoProgressTicker " ></ span >
</ h2 >
2008-07-14 21:54:50 +08:00
< ? php
2017-08-09 21:54:27 +08:00
}
2008-07-14 21:54:50 +08:00
?>
2015-05-10 21:10:30 +08:00
< h2 id = " videoFilesHeader " >< ? php echo translate ( 'VideoGenFiles' ) ?> </h2>
2008-07-14 21:54:50 +08:00
< ? php
2017-08-09 21:54:27 +08:00
if ( count ( $videoFiles ) == 0 ) {
2008-07-14 21:54:50 +08:00
?>
2015-05-10 21:10:30 +08:00
< h3 id = " videoNoFiles " >< ? php echo translate ( 'VideoGenNoFiles' ) ?> </h3>
2008-07-14 21:54:50 +08:00
< ? php
2017-08-09 21:54:27 +08:00
} else {
2008-07-14 21:54:50 +08:00
?>
2018-06-06 23:41:00 +08:00
< table id = " videoTable " class = " major " >
2008-07-14 21:54:50 +08:00
< thead >
< tr >
2015-05-10 21:10:30 +08:00
< th scope = " row " >< ? php echo translate ( 'Format' ) ?> </th>
< th scope = " row " >< ? php echo translate ( 'Size' ) ?> </th>
< th scope = " row " >< ? php echo translate ( 'Rate' ) ?> </th>
< th scope = " row " >< ? php echo translate ( 'Scale' ) ?> </th>
< th scope = " row " >< ? php echo translate ( 'Action' ) ?> </th>
2008-07-14 21:54:50 +08:00
</ tr >
</ thead >
< tbody >
< ? php
2017-08-09 21:54:27 +08:00
$index = 0 ;
foreach ( $videoFiles as $file ) {
2018-06-06 23:41:00 +08:00
if ( filesize ( $file ) > 0 ) {
preg_match ( '/^(.+)-((?:r[_\d]+)|(?:F[_\d]+))-((?:s[_\d]+)|(?:S[0-9a-z]+))\.([^.]+)$/' , $file , $matches );
if ( preg_match ( '/^r(.+)$/' , $matches [ 2 ], $temp_matches ) ) {
2017-08-09 21:54:27 +08:00
$rate = ( int )( 100 * preg_replace ( '/_/' , '.' , $temp_matches [ 1 ] ) );
$rateText = isset ( $rates [ $rate ]) ? $rates [ $rate ] : ( $rate . " x " );
2018-06-06 23:41:00 +08:00
} elseif ( preg_match ( '/^F(.+)$/' , $matches [ 2 ], $temp_matches ) ) {
$rateText = $temp_matches [ 1 ] . 'fps' ;
2017-08-09 21:54:27 +08:00
}
2018-06-06 23:41:00 +08:00
if ( preg_match ( '/^s(.+)$/' , $matches [ 3 ], $temp_matches ) ) {
$scale = ( int )( 100 * preg_replace ( '/_/' , '.' , $temp_matches [ 1 ]) );
$scaleText = isset ( $scales [ $scale ]) ? $scales [ $scale ] : ( $scale . 'x' );
} elseif ( preg_match ( '/^S(.+)$/' , $matches [ 3 ], $temp_matches ) ) {
2017-08-09 21:54:27 +08:00
$scaleText = $temp_matches [ 1 ];
}
2020-02-26 07:12:25 +08:00
$width = $scale ? reScale ( $event -> Width (), $scale ) : $event -> Width ();
$height = $scale ? reScale ( $event -> Height (), $scale ) : $event -> Height ();
2008-07-14 21:54:50 +08:00
?>
< tr >
2014-12-05 07:44:23 +08:00
< td >< ? php echo $matches [ 4 ] ?> </td>
2018-06-06 23:41:00 +08:00
< td >< ? php echo filesize ( $file ) ?> </td>
2014-12-05 07:44:23 +08:00
< td >< ? php echo $rateText ?> </td>
< td >< ? php echo $scaleText ?> </td>
2020-02-26 07:12:25 +08:00
< td >
< ? php echo makePopupLink ( '?view=' . $view . '&eid=' . $event -> Id () . '&width=' . $width . '&height=' . $height . '&showIndex=' . $index , 'zmVideo' . $event -> Id () . '-' . $scale , array ( 'videoview' , $width , $height ), translate ( 'View' ) ); ?>
& nbsp ; /& nbsp ;
< a href = " # "
data - on - click - this = " downloadVideo " data - file - index = " <?php echo $index ?> " >< ? php echo translate ( 'Download' ) ?> </a>
& nbsp ; /& nbsp ;
< a href = " # " data - on - click - this = " deleteVideo " data - file - index = " <?php echo $index ?> " >< ? php echo translate ( 'Delete' ) ?> </a>
</ td >
2008-07-14 21:54:50 +08:00
</ tr >
< ? php
2017-08-09 21:54:27 +08:00
$index ++ ;
2020-02-26 07:12:25 +08:00
} # end if filesize
} # end foreach videoFile
2008-07-14 21:54:50 +08:00
?>
</ tbody >
</ table >
< ? php
2017-08-09 21:54:27 +08:00
}
2008-07-14 21:54:50 +08:00
}
?>
</ div >
</ div >
2020-10-05 22:37:00 +08:00
< ? php xhtmlFooter () ?>