Damn_intuition 发表于 2013-3-4 23:29:34

基于USB摄像头的运动视频捕捉和远程web视频监控

本帖最后由 Damn_intuition 于 2013-3-5 11:22 编辑

一、首先确定USB摄像头可以用,
cd /dev
ls | grep video
如果有个设备名字是video0(多个摄像头数字递增)就可以了

二、本方案使用的是motion,相当简单的一个工具,让我们来安装他
sudo apt-get update
sudo apt-get install motion


三、配置motion.conf
sudo nano /etc/motion/motion.conf

ctrl+w搜索 ”target_dir“ 后面跟着个就是图片/视频文件存储的位置
ctrl+w搜索 ”control_localhost“ 将on改成off,允许非本机访问http控制台

ctrl+x Y保存退出

四、启动 motion

pi@raspberrypi /dev $ sudo motion
Processing thread 0 - config file /etc/motion/motion.conf
Motion 3.2.12 Started
ffmpeg LIBAVCODEC_BUILD 3482368 LIBAVFORMAT_BUILD 3478784
Thread 1 is from /etc/motion/motion.conf
motion-httpd/3.2.12 running, accepting connections
motion-httpd: waiting for data on port TCP 8080
Thread 1 started
cap.driver: "uvcvideo"
cap.card: "HD Pro Webcam C920"
cap.bus_info: "usb-bcm2708_usb-1.2"
cap.capabilities=0x04000001
- VIDEO_CAPTURE
- STREAMING
Test palette YUYV (640x480)
Using palette YUYV (640x480) bytesperlines 1280 sizeimage 614400 colorspace 00000008
found control 0x00980900, "Brightness", range 0,255
   "Brightness", default -8193, current 128
found control 0x00980901, "Contrast", range 0,255
   "Contrast", default 57343, current 128
found control 0x00980902, "Saturation", range 0,255
   "Saturation", default 57343, current 128
found control 0x00980913, "Gain", range 0,255
   "Gain", default 57343, current 0
mmap information:
frames=4
0 length=614400
1 length=614400
2 length=614400
3 length=614400
Using V4L2
Resizing pre_capture buffer to 1 items

五、远程控制motion

在远程通过浏览器访问 ”http://IP:8080“进行控制

  关于这些配置的具体意义,参见motion官方wiki http://www.lavrsen.dk/twiki/bin/view/Motion/WebHome中的Config options。这里,我只对其中几个解释一下。
  daemon off,关掉deamon模式。最好这项还是选off,否则运行motion后,就会直接在后台运行,需要用top命令查看出motion的进程号(pid),然后再手动kill掉这个进程。
  locate on设置探测到图像中有运动时,把运动区域用矩形框起来。
  videodevice /dev/video0 设置加载USB摄像头的设备,一般都是这个video0,当使用network webcam时,需要设置netcam_url,此时,videodevice选项自动失效。
  threshold_tune off设置是否使用motion detection阈值自动调节。当设置为on时,下一个设置threshold 4500自动失效。设置off时,可以由threshold指定当探测到多少像素变化时,判断为图像中有运动。
  ffmpeg_cap_new on这个选项是指,在detect到运动时,用视频纪录下来。
  ffmpeg_video_codec msmpeg4 设定视频的编码器
  target_dir /root/motion/snapshots当探测到运动时,图片和视频的保存路径,默认时为/var/lib/motion/snapshots。
  snapshot_interval 1设定自动采集图片的周期,当有运动被检测到时,采集频率会自动变高。




使用远程8081端口的在线视频需要将 webcam_localhost 设置为off


乱七八糟的写完了,我的描述能力十分有限,希望新人可以看懂,本着能分享点算一点的原则,只要能对一些人有所帮助那样就太好了。如有不明之处欢迎回复,互相学习探讨。

wangku001wei 发表于 2013-3-5 07:56:17

使用arduino做的么? 果断收藏了先

quqianghao 发表于 2013-3-5 08:48:37

wangku001wei 发表于 2013-3-5 07:56 static/image/common/back.gif
使用arduino做的么? 果断收藏了先

很明显这个是树莓

ailangzhou 发表于 2013-3-5 10:58:47

那种windows下免驱动的设想头能在这上面用吗?

Damn_intuition 发表于 2013-3-5 11:21:32

ailangzhou 发表于 2013-3-5 10:58 static/image/common/back.gif
那种windows下免驱动的设想头能在这上面用吗?

大多数的摄像头都可以的,话说目前很难买到不支持的摄像头。{:3_59:}

heiketiguo 发表于 2013-3-5 22:38:47

运动视频捕捉怎么办?

Damn_intuition 发表于 2013-3-5 22:43:00

heiketiguo 发表于 2013-3-5 22:38 static/image/common/back.gif
运动视频捕捉怎么办?

默认会生成运动视频。swf格式。
############################################################
# FFMPEG related options
# Film (mpeg) file output, and deinterlacing of the video input
# The options movie_filename and timelapse_filename are also used
# by the ffmpeg feature
############################################################

# Use ffmpeg to encode mpeg movies in realtime (default: off)
ffmpeg_cap_new on

# Use ffmpeg to make movies with only the pixels moving
# object (ghost images) (default: off)
ffmpeg_cap_motion off

# Use ffmpeg to encode a timelapse movie
# Default value 0 = off - else save frame every Nth second
ffmpeg_timelapse 0

# The file rollover mode of the timelapse video
# Valid values: hourly, daily (default), weekly-sunday, weekly-monday, monthly, manual
ffmpeg_timelapse_mode daily

# Bitrate to be used by the ffmpeg encoder (default: 400000)
# This option is ignored if ffmpeg_variable_bitrate is not 0 (disabled)
ffmpeg_bps 500000

# Enables and defines variable bitrate for the ffmpeg encoder.
# ffmpeg_bps is ignored if variable bitrate is enabled.
# Valid values: 0 (default) = fixed bitrate defined by ffmpeg_bps,
# or the range 2 - 31 where 2 means best quality and 31 is worst.
ffmpeg_variable_bitrate 0

# Codec to used by ffmpeg for the video compression.
# Timelapse mpegs are always made in mpeg1 format independent from this option.
# Supported formats are: mpeg1 (ffmpeg-0.4.8 only), mpeg4 (default), and msmpeg4.
# mpeg1 - gives you files with extension .mpg
# mpeg4 or msmpeg4 - gives you files with extension .avi
# msmpeg4 is recommended for use with Windows Media Player because
# it requires no installation of codec on the Windows client.
# swf - gives you a flash film with extension .swf
# flv - gives you a flash video with extension .flv
# ffv1 - FF video codec 1 for Lossless Encoding ( experimental )
# mov - QuickTime ( testing )
ffmpeg_video_codec swf

# Use ffmpeg to deinterlace video. Necessary if you use an analog camera
# and see horizontal combing on moving objects in video or pictures.
# (default: off)
ffmpeg_deinterlace off

ailangzhou 发表于 2013-3-11 12:49:29

可以用了。。不错 不过显示方面好像只有chroma可以看到图片搜狗之类的好像看不了。

Damn_intuition 发表于 2013-3-11 18:39:21

ailangzhou 发表于 2013-3-11 12:49 static/image/common/back.gif
可以用了。。不错 不过显示方面好像只有chroma可以看到图片搜狗之类的好像看不了。

对。的确有这个现象。
我一直用chroma

sommily 发表于 2013-5-3 22:57:46

为什么 webcam_localhost 设置为off8081 还是打不开?

久候 发表于 2013-5-17 20:54:46

直接看不懂啊

Damn_intuition 发表于 2013-6-24 15:45:58

久候 发表于 2013-5-17 20:54 static/image/common/back.gif
直接看不懂啊

我其实已经尽量写的简单了。
努力吧,慢慢来就看懂了。
如果遇到实在不理解的可以查一下资料或者留言问我。

renye616 发表于 2013-10-13 18:03:34

本帖最后由 renye616 于 2013-10-13 18:09 编辑

为什么看不到监控视频呢?

还有error reading first header re-try 什么意思 怎么解决?

Damn_intuition 发表于 2013-10-13 18:50:26

renye616 发表于 2013-10-13 18:03 static/image/common/back.gif
为什么看不到监控视频呢?

还有error reading first header re-try 什么意思 怎么解决?

能不能发出全部错误信息。。

morningcui 发表于 2014-3-27 14:08:26

果断收藏!
页: [1] 2
查看完整版本: 基于USB摄像头的运动视频捕捉和远程web视频监控