2016-04-11 22:31:51 +08:00
|
|
|
<?php
|
|
|
|
//
|
|
|
|
// ZoneMinder web video view file, $Date: 2008-09-29 14:15:13 +0100 (Mon, 29 Sep 2008) $, $Revision: 2640 $
|
|
|
|
// Copyright (C) 2001-2008 Philip Coombes
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
//
|
|
|
|
|
|
|
|
// Calling sequence: ... /zm/index.php?view=video&event_id=123
|
|
|
|
//
|
|
|
|
// event_id is the id of the event to view
|
|
|
|
//
|
|
|
|
// Does not support scaling at this time.
|
|
|
|
//
|
|
|
|
|
2016-08-31 22:09:01 +08:00
|
|
|
if ( !canView( 'Events' ) ) {
|
|
|
|
$view = "error";
|
|
|
|
return;
|
2016-04-11 22:31:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
require_once('includes/Event.php');
|
|
|
|
|
|
|
|
$errorText = false;
|
2016-08-31 22:09:01 +08:00
|
|
|
$path = '';
|
|
|
|
|
2016-04-11 22:31:51 +08:00
|
|
|
if ( ! empty($_REQUEST['eid'] ) ) {
|
2016-08-31 22:09:01 +08:00
|
|
|
$Event = new Event( $_REQUEST['eid'] );
|
|
|
|
$path = $Event->Path().'/'.$Event->DefaultVideo();
|
2016-06-27 22:27:26 +08:00
|
|
|
Debug("Path: $path");
|
2016-04-11 22:31:51 +08:00
|
|
|
} else {
|
2016-08-31 22:09:01 +08:00
|
|
|
$errorText = "No video path";
|
2016-04-11 22:31:51 +08:00
|
|
|
}
|
|
|
|
|
2016-08-31 22:09:01 +08:00
|
|
|
if ( $errorText ) {
|
|
|
|
Error( $errorText );
|
|
|
|
header ("HTTP/1.0 404 Not Found");
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
$size = filesize($path);
|
|
|
|
|
|
|
|
$fh = @fopen($path,'rb');
|
|
|
|
if ( ! $fh ) {
|
|
|
|
header ("HTTP/1.0 404 Not Found");
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
$begin = 0;
|
|
|
|
$end = $size;
|
|
|
|
|
|
|
|
if ( isset( $_SERVER['HTTP_RANGE'] ) ) {
|
|
|
|
Debug("Using Range " . $_SERVER['HTTP_RANGE'] );
|
|
|
|
if ( preg_match( '/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches) ) {
|
|
|
|
$begin = intval( $matches[1] );
|
|
|
|
if ( ! empty( $matches[2]) ) {
|
|
|
|
$end = intval( $matches[2] );
|
2016-04-11 22:31:51 +08:00
|
|
|
}
|
2016-08-31 22:09:01 +08:00
|
|
|
Debug("Using Range $begin $end size: $size");
|
|
|
|
}
|
|
|
|
} # end if HTTP_RANGE
|
|
|
|
|
|
|
|
if ( $begin > 0 || $end < $size ) {
|
|
|
|
header('HTTP/1.0 206 Partial Content');
|
|
|
|
} else {
|
|
|
|
header('HTTP/1.0 200 OK');
|
2016-04-11 22:31:51 +08:00
|
|
|
}
|
2016-08-31 22:09:01 +08:00
|
|
|
|
|
|
|
header('Content-type: video/mp4');
|
|
|
|
header('Accept-Ranges: bytes');
|
|
|
|
header('Content-Length:'.($end-$begin));
|
|
|
|
header("Content-Disposition: inline;");
|
|
|
|
header("Content-Range: bytes $begin-$end/$size");
|
|
|
|
header("Content-Transfer-Encoding: binary\n");
|
|
|
|
header('Connection: close');
|
|
|
|
|
2016-09-22 22:37:32 +08:00
|
|
|
// Apparently without these we get a few extra bytes of output at the end...
|
|
|
|
ob_clean();
|
|
|
|
flush();
|
|
|
|
|
2016-08-31 22:09:01 +08:00
|
|
|
$cur = $begin;
|
|
|
|
fseek( $fh, $begin, 0 );
|
|
|
|
|
|
|
|
while( ! feof( $fh ) && $cur < $end && ( connection_status() == 0 ) ) {
|
|
|
|
#Error("Sending $cur");
|
|
|
|
print fread( $fh, min( 1024*16, $end - $cur ) );
|
|
|
|
$cur += 1024*16;
|
|
|
|
usleep(100);
|
|
|
|
}
|