概述
买了一个罗技的usb接口的摄像头,想通过raspberry pi做一个视频的实时监控器,看了一下这各功能可以通过两款软件实现:motion和mjpg-streamer,先来简单介绍下这两个软件。
motion
是一个基于命令行的,在linux系统下使用的,捕捉图片或者视频流的软件,可以吧摄像头设备的画面捕捉下来。下面是wikipedia的介绍:
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下的图片,视频捕捉软件:
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实现
sudo apt-get update
sudo apt-get install motion
sudo nano /etc/default/motion
把“
start_motion_daemon=no”的选项改为yes。然后
sudo nano /etc/motion/motion.conf
daemon on
width 640
height 480
framerate 100
stream_localhost off
主要把上面这几项修改了,这个文件很长,可以使用ctl+v翻页。最后ctl+o保存,ctl+x退出。sudo motion
然后打开浏览器
sudo killall -TERM motion
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
启动:
/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
至此两种实现全部给出!