概述
买了一个罗技的usb接口的摄像头,想通过raspberry pi做一个视频的实时监控器,看了一下这各功能可以通过两款软件实现:motion和mjpg-streamer,先来简单介绍下这两个软件。
motion
是一个基于命令行的,在Linux系统下使用的,捕捉图片或者视频流的软件,可以吧摄像头设备的画面捕捉下来。下面是wikipedia的介绍:
[html]view plaincopy
Motion, a software motion detector, is a free, open source CCTV software application developed for Linux.
It can monitor video signal from one or more cameras and is able to detect if a significant part of the picture has changed saving away video when it detects that motion is occurring (it can also do time lapse videos, et al.).
The program is written in C and is made for Linux (exploiting video4linux interface). Motion is a command line based tool whose output can be either jpeg, netpbm files or mpeg video sequences. It is strictly command line driven and can run as a daemon with a rather small footprint[1] and low CPU usage.
mjpg-streamer
同样,也是一款linux下的图片,视频捕捉软件:
[html]view plaincopy
MJPG-streamer takes JPGs from Linux-UVC compatible webcams, filesystem or other input plugins and streams them as M-JPEG via HTTP to webbrowsers, VLC and other software. It is the successor of uvc-streamer, a Linux-UVC streaming application with Pan/Tilt
引自:https://sourceforge.net/projects/mjpg-streamer/的介绍。
我使用以上的两者都做了尝试,事实证明mjpg的效果比motion好太多,主要体现在delay上。motion卡顿太致命了,延迟在30s+,而mjpg就好很多。但是无奈motion实现很简单,mjpg则是废了一些功夫才成功。下面上干货
使用motion实现
[html]view plaincopy
sudo apt-get update
[html]view plaincopy
sudo apt-get install motion
[html]view plaincopy
sudo nano /etc/default/motion
把“start_motion_daemon=no”的选项改为yes。然后
[html]view plaincopy
sudo nano /etc/motion/motion.conf
daemon on
width 640
height 480
framerate 100
stream_localhost off
主要把上面这几项修改了,这个文件很长,可以使用ctl+v翻页。最后ctl+o保存,ctl+x退出。
然后启动motion:
[html]view plaincopy
sudo motion
然后打开浏览器
ip:8081即可访问。
下面的是我的截图
如果要关闭,可以:
[html]view plaincopy
sudo killall -TERM motion
之前也提到了,这个方案的致命伤是太卡了,根本不能满足需求。。。后来我就上google,有人提到了使用motion确实很卡,无法避免,除非使用mjpg,这个效果最好,无奈之下,又开启了默默探索以旅。。。
关于motion的参考:
http://www.techradar.com/how-to/computing/use-a-raspberry-pi-to-remotely-watch-your-home-1314466
使用mjpg-streamer实现
这个稍微麻烦点,而且一般资源在google,大家查的时候要注意,google上很多资源是针对树莓派自带的摄像机模块来的,但是对于像我这样的穷屌丝来说,还不如买个其他摄像头来的划算,如果不用自带的摄像头,那么配置是不一样的,这点要注意。
[html]view plaincopy
sudo apt-get update
sudo apt-get install libjpeg8-dev imagemagick libv4l-dev
ln -s /usr/include/linux/videodev2.h /usr/include/linux/videodev.h
wget http://sourceforge.net/code-snapshots/svn/m/mj/mjpg-streamer/code/mjpg-streamer-code-182.zip
unzip mjpg-streamer-code-182.zip
cd mjpg-streamer
make mjpg_streamer input_file.so input_uvc.so output_http.so
sudo cp mjpg_streamer /usr/local/bin
sudo cp output_http.so input_file.so input_uvc.so /usr/local/lib/
sudo cp -R www /usr/local/www
启动:
[html]view plaincopy
/usr/local/bin/mjpg_streamer -i "/usr/local/lib/input_uvc.so -y" -o "/usr/local/lib/output_http.so -w /usr/local/www"
最终:http://192.168.2.12:8080/stream.html,当然要成你的ip。截图:
这是mjpg的主页,点击stream可以看到视频流,如下图:
参考:http://blog.cudmore.io/post/2015/03/15/Installing-mjpg-streamer-on-a-raspberry-pi/
http://electronsfree.blogspot.com/2016/04/raspberry-pi-3-with-better-raspicam.html
网友评论