CubieBoard中文论坛

 找回密码
 立即注册
搜索
热搜: unable
查看: 10640|回复: 7

PHP读取mjpg-streamer的视频流并且输出图片

[复制链接]
发表于 2013-5-11 18:35:29 | 显示全部楼层 |阅读模式
本帖最后由 tll 于 2013-5-11 18:46 编辑

先炫一下:http://110.80.100.114:81/(随时可能关闭啊)
大家都知道,MJ(mjpg-streamer)自带web服务器,但是大家都知道,那东西不能跑PHP什么的,甚不方便
于是,我打算用apache当我的webserver~
我写了个用php获取MJ视频流再输出到apache。
记得安装curl的php扩展啊
以下是代码:
  1. <?php
  2. $ch = curl_init();
  3. curl_setopt($ch, CURLOPT_URL,
  4. "127.0.0.1/?action=snapshot");  
  5. curl_setopt($ch,
  6. CURLOPT_RETURNTRANSFER, 1);
  7. $output = curl_exec($ch);
  8. curl_close($ch);

  9. $file_size=count($output);
  10. Header("Content-type: image/jpeg");

  11. Header("Accept-Ranges: bytes");
  12. Header("Accept-Length:".$file_size);

  13. echo $output;
  14. ?>
复制代码
然后,保存为getfile.php,到根目录,再把apache的端口调成81,重启
打开MJ,端口设置为80(因为我没映射所以MJ的80端口外网是访问不到的)
再写个index.html:

  1. Hello~


  2. FROM PHP - MJPG-STREAMER


  3. <!--<img src="getfile.php" />-->
  4. <script type="text/javascript">
  5. var imageNr = 0; // Serial number of current image
  6. var finished = new Array();
  7. var paused = false;

  8. function createImageLayer() {
  9.   var img = new Image();
  10.   img.style.position = "absolute";
  11.   img.style.zIndex = -1;
  12.   img.onload = imageOnload;
  13.   img.onclick = imageOnclick;
  14.   img.src = "getfile.php?id=" + (++imageNr);
  15.   var webcam = document.getElementById("webcam");
  16.   webcam.insertBefore(img, webcam.firstChild);
  17. }
  18. function imageOnload() {
  19.   this.style.zIndex = imageNr; // Image finished, bring to front!
  20.   while (1 < finished.length) {

  21.    var del = finished.shift(); // Delete old image(s) from docuent
  22.     del.parentNode.removeChild(del);
  23.   }
  24.   finished.push(this);
  25.   if (!paused) createImageLayer();
  26. }

  27. function imageOnclick() { // Clicking on the image will pause the stream
  28.   paused = !paused;
  29.   if (!paused) createImageLayer();
  30. }

  31. </script>
  32. <body onload="createImageLayer();">
  33. <div id="webcam"></div>
复制代码
好了,访问一下 http://你的ip:81,看看是不是有这个效果吧(会动的)
效果:
QQ截图20130511184523.png
回复

使用道具 举报

发表于 2013-5-11 20:22:39 | 显示全部楼层
感谢分享~!!
其实mjpg-streamer和motion是类似的,主要是实时监控的资源占用实在太大,CB的性能不足以支持实时监控的多并发,做一个私人的小监控还是不错的。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-5-11 20:38:24 | 显示全部楼层
Cannikin 发表于 2013-5-11 20:22
感谢分享~!!
其实mjpg-streamer和motion是类似的,主要是实时监控的资源占用实在太大,CB的性能不足以支 ...

我就是如此啊~
回复 支持 反对

使用道具 举报

发表于 2013-5-15 10:57:52 | 显示全部楼层
tll 发表于 2013-5-11 20:38
我就是如此啊~

http://cb.e-fly.org/cb-webcam.html

看这里~~ 楼上的楼上的~
回复 支持 反对

使用道具 举报

发表于 2013-5-15 14:36:56 | 显示全部楼层
其实不用这么麻烦,一个html文件就能搞定。加入代码(IP和端口号根据实际填写):
<img src="http://127.0.0.1:8090/?action=stream" />

另外,mjpg-streamer做监控的确很不错,找个硬件支持mjpeg的摄像头(如:Logitech C270),640*480下CPU占用率不会超过1%,即使上720p高清也很流畅。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-5-16 06:13:29 | 显示全部楼层
allen 发表于 2013-5-15 14:36
其实不用这么麻烦,一个html文件就能搞定。加入代码(IP和端口号根据实际填写):

不是不是,这样的话cb要开两个端口用php之只用一个
回复 支持 反对

使用道具 举报

发表于 2014-7-24 10:54:47 | 显示全部楼层
good,mark一下
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|粤ICP备13051116号|cubie.cc---深刻的嵌入式技术讨论社区

GMT+8, 2024-6-2 15:14 , Processed in 0.025076 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2012 Comsenz Inc. | Style by Coxxs

返回顶部