Web Interface For Lite Argus Control modules
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.9 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. require_once('../ajax_asm.php');
  3. if( 1 ){//$CUser->Data['id'] > 1 ){
  4. $VID = intval( $_GET['VID'] );
  5. $DTS = intval( $_GET['TS'] );
  6. $DTSM = intval( $_GET['TSM'] );
  7. $START_FRAME = 0;
  8. if( isset( $_GET['sf'] ) ) $START_FRAME = intval( $_GET['sf'] );
  9. if( $VID && $DTS ){
  10. $DS = date("Y/m/d", $DTS );
  11. // VID is a global video id (see report_files.php)
  12. $QS = "SELECT * FROM `videos` WHERE `id` = " . reportRawId( $VID );
  13. $ZIZI = reportOpenSlot( $DS, reportSlotOf( $VID ) );
  14. $LREC = $ZIZI ? $ZIZI->Query( $QS ) : array();
  15. if( count( $LREC ) ){
  16. $Data = $LREC[0];
  17. $FILE = $SYSPath . "/lib/controller/data/reports/{$DS}/{$Data['md5']}.{$Data['ext']}";
  18. $FPS = intval( $Data['fps'] );
  19. if( $FPS < 1 ) $FPS = 15;
  20. if( $START_FRAME == 0 ){
  21. $AETS = floatval( $DTS ) + floatval( $DTSM ) / 1000.0;
  22. $AVTS = floatval( $Data['uts'] ) + floatval( $Data['uts_ms'] ) / 1000.0;
  23. $START_FRAME = intval( ( $AETS - $AVTS )/ ( 1.0/ $FPS ) );
  24. };
  25. ob_implicit_flush(true);
  26. //ignore_user_abort(true);
  27. while( ob_get_level() ) ob_end_clean();
  28. header("Cache-Control: no-store, no-cache, post-check=0, pre-check=0");
  29. header("Pragma: no-cache");
  30. header("MIME-version: 1.0");
  31. header("Connection: close");
  32. header("Content-Transfer-Encoding: BINARY");
  33. header("Content-type: multipart/x-mixed-replace;boundary=MPFrame");
  34. //$FILE = $SYSPath . '/lib/controller/data/reports/2024/02/14/d156c150ca14ac484f28ef4ad70666b2.mjpeg';
  35. $FID = fopen( $FILE, "r");
  36. $BUFFER = "";
  37. $FRAME = "";
  38. if( $FID === false ){
  39. } else {
  40. $end = false;
  41. $start = false;
  42. $CURRENT_FRAME = 0;
  43. while( !feof( $FID ) ){
  44. $BUFFER .= fread( $FID, 8192 );
  45. if( $start === false ) $start = strpos( $BUFFER, "\xFF\xD8" );
  46. if( $start !== false && $end === false ) $end = strpos( $BUFFER, "\xFF\xD9", $start );
  47. if( $start !== false && $end !== false ){
  48. $end += 2;
  49. $CONTENT_LEN = $end - $start;
  50. $FRAME = substr( $BUFFER, $start, $CONTENT_LEN );
  51. $BUFFER = substr( $BUFFER, $end );
  52. $start = false;
  53. $end = false;
  54. $CURRENT_FRAME++;
  55. if( $CURRENT_FRAME > $START_FRAME ){
  56. echo "--MPFrame\r\nContent-type: image/jpeg\r\nContent-length: {$CONTENT_LEN}\r\n\r\n";
  57. echo $FRAME;
  58. echo "\r\n\r\n";
  59. usleep( 1000000 / $FPS ); // 15 fps?
  60. };
  61. if( connection_status() != 0 ){
  62. fclose( $FID );
  63. error_log('Connection aborted.');
  64. exit();
  65. };
  66. };
  67. };
  68. if( $CURRENT_FRAME <= $START_FRAME ){
  69. echo "--MPFrame\r\nContent-type: image/jpeg\r\nContent-length: {$CONTENT_LEN}\r\n\r\n";
  70. echo $FRAME;
  71. echo "\r\n\r\n";
  72. };
  73. fclose( $FID );
  74. };
  75. //file_put_contents( $SYSPath . '/lib/controller/test.txt',"KOKOMO");
  76. exit();
  77. } else echo " No Recoe";
  78. } else echo " No Param";
  79. } else echo " No ACC";
  80. function readPixel($url, $x, $y, $callback)
  81. {
  82. $loop = 0;
  83. //Megasaturnv 2018-01-12
  84. // Mjpeg URL
  85. $camurl = $url;
  86. //$camurl="http://username:password@192.168.1.100:8081/" // HTTP Auth mjpeg URL (optional)
  87. $boundary="--BoundaryString"; // $boundary = The boundary string between jpegs in an mjpeg stream
  88. //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
  89. $f = fopen($camurl, "r"); // Open mjpeg url as $f in readonly mode
  90. $r = ""; // Set $r to blank variable
  91. if($f) {
  92. while (true){
  93. $r.=fread($f, 50000);
  94. $startsearch = strpos($r, "Content-Length: ");
  95. if($startsearch!==false){
  96. $r = substr($r, $startsearch+16);
  97. $index=0;
  98. $length = "";
  99. while(true){
  100. $char = substr($r, $index, 1);
  101. $index++;
  102. if(is_numeric($char)){
  103. $length.= $char;
  104. }else{
  105. break;
  106. }
  107. }
  108. $r = substr($r, strlen($length)+4);
  109. $totalbytes = $length-0;
  110. $havebytes=strlen($r);
  111. $remain = $totalbytes-$havebytes;
  112. //echo "Length:$length\n";
  113. //echo "Stream:$r\n";
  114. //echo "HaveBytes $havebytes totalbytes: $totalbytes, Remain: $remain\n";
  115. while($havebytes < $totalbytes){
  116. $r .=fread($f, $totalbytes-$havebytes);
  117. $havebytes = strlen($r);
  118. }
  119. //save/debug image
  120. //file_put_contents("test.jpg", $r);
  121. $im = imagecreatefromstring($r);
  122. //test if image is valid
  123. //$valid = ($im != FALSE);
  124. //echo ($valid?"VALID":"INVALID")."\n";
  125. //echo imagesx($im).'x'.imagesy($im) ."\n";
  126. $rgb = imagecolorat ($im, $x, $y);
  127. $r = ($rgb >> 16) & 0xFF;
  128. $g = ($rgb >> 8) & 0xFF;
  129. $b = $rgb & 0xFF;
  130. imagedestroy($im);
  131. $loop++;
  132. if($callback($r,$g,$b, $loop)){
  133. echo "TEST colors: $r $g $b\n";
  134. }else{
  135. fclose($f);
  136. return true;
  137. }
  138. $r="";
  139. }
  140. }
  141. } else {
  142. echo "Error, cannot open URL"; // Error message if $camurl cannot be opened
  143. }
  144. fclose($f); // Close the url
  145. }
  146. ?>