Merge pull request #7 from connortechnology/feature-h264-videostorage

Feature h264 videostorage
This commit is contained in:
Steve Gilvarry 2016-09-01 01:07:33 +10:00 committed by GitHub
commit e371d9ec7f
4 changed files with 63 additions and 22 deletions

View File

@ -38,6 +38,7 @@ if [ "$1" = "configure" ]; then
invoke-rc.d zoneminder stop || true invoke-rc.d zoneminder stop || true
zmupdate.pl --nointeractive zmupdate.pl --nointeractive
zmupdate.pl --nointeractive -f zmupdate.pl --nointeractive -f
echo "Done Updating, starting ZoneMinder"
invoke-rc.d zoneminder start || true invoke-rc.d zoneminder start || true
else else
echo 'NOTE: mysql not running, please start mysql and run dpkg-reconfigure zoneminder when it is running.' echo 'NOTE: mysql not running, please start mysql and run dpkg-reconfigure zoneminder when it is running.'

View File

@ -38,6 +38,7 @@ if [ "$1" = "configure" ]; then
invoke-rc.d zoneminder stop || true invoke-rc.d zoneminder stop || true
zmupdate.pl --nointeractive zmupdate.pl --nointeractive
zmupdate.pl --nointeractive -f zmupdate.pl --nointeractive -f
echo "Done Updating, starting ZoneMinder"
invoke-rc.d zoneminder start || true invoke-rc.d zoneminder start || true
else else
echo 'NOTE: mysql not running, please start mysql and run dpkg-reconfigure zoneminder when it is running.' echo 'NOTE: mysql not running, please start mysql and run dpkg-reconfigure zoneminder when it is running.'

View File

@ -41,6 +41,7 @@ if [ "$1" = "configure" ]; then
deb-systemd-invoke stop zoneminder.service || exit $? deb-systemd-invoke stop zoneminder.service || exit $?
zmupdate.pl --nointeractive zmupdate.pl --nointeractive
zmupdate.pl --nointeractive -f zmupdate.pl --nointeractive -f
echo "Done Updating, starting ZoneMinder"
deb-systemd-invoke start zoneminder.service || exit $? deb-systemd-invoke start zoneminder.service || exit $?
else else

View File

@ -25,36 +25,74 @@
// Does not support scaling at this time. // Does not support scaling at this time.
// //
if ( !canView( 'Events' ) ) if ( !canView( 'Events' ) ) {
{
$view = "error"; $view = "error";
return; return;
} }
require_once('includes/Storage.php');
require_once('includes/Event.php'); require_once('includes/Event.php');
$Storage = NULL;
$errorText = false; $errorText = false;
$path = '';
if ( ! empty($_REQUEST['eid'] ) ) { if ( ! empty($_REQUEST['eid'] ) ) {
$Event = new Event( $_REQUEST['eid'] ); $Event = new Event( $_REQUEST['eid'] );
$Storage = $Event->Storage(); $path = $Event->Path().'/'.$Event->DefaultVideo();
$path = $Event->Relative_Path().'/'.$Event->DefaultVideo(); Debug("Path: $path");
Error("Path: $path");
} else { } else {
$errorText = "No video path"; $errorText = "No video path";
} }
if ( $errorText ) if ( $errorText ) {
Error( $errorText ); Error( $errorText );
else{ header ("HTTP/1.0 404 Not Found");
# FIXME guess it from the video file die();
header( 'Content-type: video/mp4' ); }
if ( ! readfile( $Storage->Path().'/'.$path ) ) {
Error("No bytes read from ". $Storage->Path() . '/'.$path ); $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] );
}
Debug("Using Range $begin $end size: $size");
}
} # end if HTTP_RANGE
if ( $begin > 0 || $end < $size ) {
header('HTTP/1.0 206 Partial Content');
} else { } else {
Error("Success sending " . $Storage->Path().'/'.$path ); header('HTTP/1.0 200 OK');
} }
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');
$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);
} }
?> ?>