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.

163 lines
5.5 KiB

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