doucuo4413 2015-06-24 12:59
浏览 21
已采纳

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

I try to get a webcam image direct to my PHP script on a debian system. For this, I tried to open a file handling to /dev/video0, but that doesn't work. Using the software "streamer" I got an image to the disk, the webcam works on /dev/video0

I don't want to save the image to the disk first, because I need to refresh it in a short interval. My idea is to get an image direct to the standard output and use php passthru to pipe the output to the client browser:

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

I hoped that avconv has the option to push the image to the standard output, but I could not find any option like this. Is there a possibility to get the webcam image (via avconv or another tool) direct in php as an binary stream?

Thanks a lot! Sebastian

  • 写回答

2条回答 默认 最新

  • duanbei1598 2017-10-23 14:24
    关注

    This works without the need of a temporary file:

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

    (from https://gist.github.com/megasaturnv/a42ed77d3d08d0d3d91725dbe06a0efe)

    This also works in an img tag: https://gist.github.com/megasaturnv/6e5965732d4cff91f2e976e7a39efbaa

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?