Gaw*_*ran 7 php image ip-camera
如果没有新的请求说1秒,PHP有没有办法采取一些行动(例如mysql插入)?
我想要实现的是确定从IP摄像机发送的图像序列的开始和结束.相机在检测到的移动时发送一系列图像,并在移动停止时停止发送.我知道相机每秒制作5张图像(每200毫秒).当没有超过1秒的新图像时,我想将最后一个图像标记为序列的结尾,在mysql中插入记录,将img放在适当的文件夹中(其中所有其他img来自相同的序列已经写入)并指示app在该文件夹中制作MJPEG图像剪辑.
现在我能够使用Alternative PHP cash来确定序列中的第一个图像,以节省前一个请求的参考时间,但问题是因为下一个图像序列可能在几个小时之后发生,如果有,我不能指示PHP关闭序列只有在第一次请求新序列到达时才会有一段时间没有请求.
我真的需要帮助.我的PHP几乎像我的英语一样......
我的问题的伪代码:
<?php
if(isset($headers["Content-Disposition"]))
{
$frame_time = microtime(true);
if(preg_match('/.*filename=[\'\"]([^\'\"]+)/', $headers["Content-Disposition"], $matches))
{ $filename = $matches[1]; }
else if(preg_match("/.*filename=([^ ]+)/", $headers["Content-Disposition"], $matches))
{ $filename = $matches[1]; }
}
preg_match("/(anpr[1-9])/", $filename, $anprs);
$anpr = $anprs[1];
$apc_key = $anpr."_last_time"; //there are several cameras so I have to distinguish those
$last = apc_fetch($apc_key);
if (($frame_time - $last)>1)
{
$stream = "START"; //New sequence starts
} else {
$stream = "-->"; //Streaming
};
$file = fopen('php://input', 'r');
$temp = fopen("test/".$filename, 'w');
$imageSize = stream_copy_to_stream($file, $temp); //save image file on the file system
fclose($temp);
fclose($file);
apc_store($apc_key, $frame_time); //replace cashed time with this frame time in APC
// here goes mysql stuff...
/* Now... if there is no new requests for 1 second $stream = "END";
calling app with exec() or similar to grab all images in the particular folder and make
MJPEG... if new request arrives cancel timer or whatever and execute script again. */
?>
Run Code Online (Sandbox Code Playgroud)
小智 -1
将来自相机的每个请求及其所有数据和时间戳存储在文件中(以 php 序列化形式)。在 cronjob 中(每 10 秒左右)运行一个脚本,该脚本读取该文件并查找在下一个请求之前超过一秒的请求。保存此类请求的数据并删除所有其他请求。
| 归档时间: |
|
| 查看次数: |
368 次 |
| 最近记录: |