You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
170 lines
5.8 KiB
170 lines
5.8 KiB
<?php
|
|
require_once('../ajax_asm.php');
|
|
if( 1 ){//$CUser->Data['id'] > 1 ){
|
|
$VID = intval( $_GET['VID'] );
|
|
$DTS = intval( $_GET['TS'] );
|
|
$DTSM = intval( $_GET['TSM'] );
|
|
$START_FRAME = 0;
|
|
if( isset( $_GET['sf'] ) ) $START_FRAME = intval( $_GET['sf'] );
|
|
if( $VID && $DTS ){
|
|
$DS = date("Y/m/d", $DTS );
|
|
$QS = "SELECT * FROM `videos` WHERE `id` = {$VID}";
|
|
$ZIZI = new SQLite_DB( '/srv/www/web/lib/controller/data/reports/'.$DS.'/report.db');
|
|
$LREC = $ZIZI->Query( $QS );
|
|
if( count( $LREC ) ){
|
|
$Data = $LREC[0];
|
|
|
|
$FILE = "/srv/www/web/lib/controller/data/reports/{$DS}/{$Data['md5']}.{$Data['ext']}";
|
|
$FPS = intval( $Data['fps'] );
|
|
if( $FPS < 1 ) $FPS = 15;
|
|
if( $START_FRAME == 0 ){
|
|
$AETS = floatval( $DTS ) + floatval( $DTSM ) / 1000.0;
|
|
$AVTS = floatval( $Data['uts'] ) + floatval( $Data['uts_ms'] ) / 1000.0;
|
|
$START_FRAME = intval( ( $AETS - $AVTS )/ ( 1.0/ $FPS ) );
|
|
};
|
|
ob_implicit_flush(true);
|
|
//ignore_user_abort(true);
|
|
while( ob_get_level() ) ob_end_clean();
|
|
|
|
header("Cache-Control: no-store, no-cache, post-check=0, pre-check=0");
|
|
header("Pragma: no-cache");
|
|
header("MIME-version: 1.0");
|
|
header("Connection: close");
|
|
header("Content-Transfer-Encoding: BINARY");
|
|
header("Content-type: multipart/x-mixed-replace;boundary=MPFrame");
|
|
|
|
|
|
//$FILE = '/srv/www/web/lib/controller/data/reports/2024/02/14/d156c150ca14ac484f28ef4ad70666b2.mjpeg';
|
|
$FID = fopen( $FILE, "r");
|
|
$BUFFER = "";
|
|
$FRAME = "";
|
|
|
|
if( $FID === false ){
|
|
|
|
} else {
|
|
$end = false;
|
|
$start = false;
|
|
$CURRENT_FRAME = 0;
|
|
while( !feof( $FID ) ){
|
|
$BUFFER .= fread( $FID, 8192 );
|
|
if( $start === false ) $start = strpos( $BUFFER, "\xFF\xD8" );
|
|
if( $start !== false && $end === false ) $end = strpos( $BUFFER, "\xFF\xD9", $start );
|
|
if( $start !== false && $end !== false ){
|
|
$end += 2;
|
|
$CONTENT_LEN = $end - $start;
|
|
$FRAME = substr( $BUFFER, $start, $CONTENT_LEN );
|
|
$BUFFER = substr( $BUFFER, $end );
|
|
$start = false;
|
|
$end = false;
|
|
$CURRENT_FRAME++;
|
|
if( $CURRENT_FRAME > $START_FRAME ){
|
|
echo "--MPFrame\r\nContent-type: image/jpeg\r\nContent-length: {$CONTENT_LEN}\r\n\r\n";
|
|
echo $FRAME;
|
|
echo "\r\n\r\n";
|
|
usleep( 1000000 / $FPS ); // 15 fps?
|
|
};
|
|
if( connection_status() != 0 ){
|
|
fclose( $FID );
|
|
error_log('Connection aborted.');
|
|
exit();
|
|
};
|
|
};
|
|
};
|
|
if( $CURRENT_FRAME <= $START_FRAME ){
|
|
echo "--MPFrame\r\nContent-type: image/jpeg\r\nContent-length: {$CONTENT_LEN}\r\n\r\n";
|
|
echo $FRAME;
|
|
echo "\r\n\r\n";
|
|
};
|
|
fclose( $FID );
|
|
};
|
|
//file_put_contents('/srv/samba/Mojo_Web/lib/controller/test.txt',"KOKOMO");
|
|
exit();
|
|
} else echo " No Recoe";
|
|
} else echo " No Param";
|
|
} else echo " No ACC";
|
|
|
|
function readPixel($url, $x, $y, $callback)
|
|
{
|
|
$loop = 0;
|
|
//Megasaturnv 2018-01-12
|
|
// Mjpeg URL
|
|
$camurl = $url;
|
|
//$camurl="http://username:password@192.168.1.100:8081/" // HTTP Auth mjpeg URL (optional)
|
|
$boundary="--BoundaryString"; // $boundary = The boundary string between jpegs in an mjpeg stream
|
|
//NOTE: $boundary changes between mjpeg stream providers. For example, https://github.com/Motion-Project/motion uses '--BoundaryString'. https://github.com/ZoneMinder/ZoneMinder uses '--ZoneMinderFrame'. To find out $boundary for your stream you will need to save 1 or more frames of the mjpeg and open it with a text editor. --<boundary string> should be visible on the first line
|
|
$f = fopen($camurl, "r"); // Open mjpeg url as $f in readonly mode
|
|
$r = ""; // Set $r to blank variable
|
|
|
|
if($f) {
|
|
while (true){
|
|
$r.=fread($f, 50000);
|
|
|
|
$startsearch = strpos($r, "Content-Length: ");
|
|
if($startsearch!==false){
|
|
$r = substr($r, $startsearch+16);
|
|
|
|
$index=0;
|
|
$length = "";
|
|
while(true){
|
|
$char = substr($r, $index, 1);
|
|
$index++;
|
|
|
|
if(is_numeric($char)){
|
|
$length.= $char;
|
|
}else{
|
|
break;
|
|
}
|
|
}
|
|
|
|
$r = substr($r, strlen($length)+4);
|
|
$totalbytes = $length-0;
|
|
$havebytes=strlen($r);
|
|
$remain = $totalbytes-$havebytes;
|
|
|
|
//echo "Length:$length\n";
|
|
//echo "Stream:$r\n";
|
|
//echo "HaveBytes $havebytes totalbytes: $totalbytes, Remain: $remain\n";
|
|
|
|
while($havebytes < $totalbytes){
|
|
$r .=fread($f, $totalbytes-$havebytes);
|
|
$havebytes = strlen($r);
|
|
}
|
|
|
|
//save/debug image
|
|
//file_put_contents("test.jpg", $r);
|
|
|
|
$im = imagecreatefromstring($r);
|
|
|
|
//test if image is valid
|
|
//$valid = ($im != FALSE);
|
|
//echo ($valid?"VALID":"INVALID")."\n";
|
|
//echo imagesx($im).'x'.imagesy($im) ."\n";
|
|
|
|
$rgb = imagecolorat ($im, $x, $y);
|
|
|
|
$r = ($rgb >> 16) & 0xFF;
|
|
$g = ($rgb >> 8) & 0xFF;
|
|
$b = $rgb & 0xFF;
|
|
|
|
imagedestroy($im);
|
|
$loop++;
|
|
|
|
if($callback($r,$g,$b, $loop)){
|
|
echo "TEST colors: $r $g $b\n";
|
|
}else{
|
|
fclose($f);
|
|
return true;
|
|
}
|
|
|
|
$r="";
|
|
}
|
|
}
|
|
} else {
|
|
echo "Error, cannot open URL"; // Error message if $camurl cannot be opened
|
|
}
|
|
|
|
fclose($f); // Close the url
|
|
}
|
|
|
|
|
|
?>
|