avconv网络摄像头图像到php中使用的标准输出


avconv webcam image to standard output for using in php

我试图在debian系统上直接将网络摄像头图像获取到我的PHP脚本中。为此,我尝试打开一个处理/dev/video0的文件,但这不起作用。使用软件"streamer"我得到了一个磁盘图像,网络摄像头在/dev/video0 上工作

我不想先将图像保存到磁盘,因为我需要在短时间内刷新它。我的想法是将图像直接发送到标准输出,并使用php passthrough将输出管道发送到客户端浏览器:

$header("Content-type: image/jpeg");
passthru('avconv /dev/video0 someparamters for direct output');

我希望avconv可以选择将图像推送到标准输出,但我找不到这样的选项。是否有可能(通过avconv或其他工具)直接在php中获得网络摄像头图像作为二进制流?

非常感谢!Sebastian

这不需要临时文件即可工作:

<?php
header("content-type: image/jpeg");
echo passthru("avconv -f video4linux2 -i /dev/video0 -vframes 1 -s 1280x1024 pipe:.jpg 2>/dev/null");
?>

(来自https://gist.github.com/megasaturnv/a42ed77d3d08d0d3d91725dbe06a0efe)

这也适用于img标记:https://gist.github.com/megasaturnv/6e5965732d4cff91f2e976e7a39efbaa

我找到的唯一方法是保存到一个文件,然后保存file_get_contents

$filename = "snapshot.jpg";
system("avconv -f video4linux2 -i /dev/video0 -vframes 1 -s 1280x800 ".$filename);
if( file_exists( $filename ) ){
  header("content-type: image/jpeg");
  echo file_get_contents( $filename );
} else {
  echo "Error loading the snapshot";
}

希望这能帮助