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

avconv webcam image to standard output for using in php

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

上工作

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

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

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

非常感谢! 塞巴斯蒂安

我找到的唯一方法是保存到文件,然后 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";
}

希望对您有所帮助

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

<?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