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.

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