之前的文章介绍了在openwrt系统下使用mjpeg-streamer实现摄像头监控,同时也顺便介绍了如何配置编译motionmotion能够实现当摄像头中的视频内容有变化时自动拍照保存,有了这个功能就能实现自动上传、发送邮件、短信通知之类的功能了。

假设我们已经编译好了motion包,拷贝到开发板后,直接执行以下命令安装即可:

# opkg install /mnt/nfs/motion_3.4.0-20141018-9479d910f2149b555878
8bb86f97f26522794212-1_ramips_24kec.ipk 
Installing motion (3.4.0-20141018-9479d910f2149b5558788bb86f97f26522794212-1) to root...
Configuring motion.

motion配置文件名为motion.conf,一般是在/etc目录下。因为选项比较多,下面只列出一些比较重要的选项的值,其它可以用默认值,或者参考motion官网上的documents

daemon on
process_id_file /var/run/motion.pid
setup_mode off

#如摄像头不支持MJPEG,就只能设成其他的,如6 (YUYV):
v4l2_palette 2

#640x480已满足基本需要,太大则占用路由器CPU/带宽
width 640
height 480

#单做自动监控拍照,帧率没必要太高,否则输出的文件很多
framerate 2
auto_brightness off
contrast 0

#多少个像素发生改变的时候保存当前照片,640x480的图片设置3000已经非常灵敏
threshold 3000

#下面这个是指定照片保存的文件夹:
target_dir /root/camimg
quiet on

#下面这句是说一旦有照片被拍下来,则执行/root/upload.sh命令,
#其中%f参数会自动转化为当前图片文件的路径,传给upload.sh:
on_picture_save /root/upload.sh %f

启动应用:

# motion -c /etc/motion.conf &
root@OpenWrt:/etc# [0] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion.conf
[0] [ALR] [ALL] conf_cmdparse: Unknown config option "ffmpeg_output_movies"
[0] [ALR] [ALL] conf_cmdparse: Unknown config option "ffmpeg_output_debug_movies"
[0] [ALR] [ALL] conf_cmdparse: Unknown config option "ffmpeg_timelapse"
[0] [ALR] [ALL] conf_cmdparse: Unknown config option "ffmpeg_timelapse_mode"
[0] [ALR] [ALL] conf_cmdparse: Unknown config option "ffmpeg_bps"
[0] [ALR] [ALL] conf_cmdparse: Unknown config option "ffmpeg_variable_bitrate"
[0] [ALR] [ALL] conf_cmdparse: Unknown config option "ffmpeg_video_codec"
[0] [ALR] [ALL] conf_cmdparse: Unknown config option "ffmpeg_deinterlace"
[0] [ALR] [ALL] conf_cmdparse: Unknown config option "movie_filename"
[0] [ALR] [ALL] conf_cmdparse: Unknown config option "timelapse_filename"
[0] [NTC] [ALL] motion_startup: Motion 3.4.0-Git-78ba2da Started
[0] [NTC] [ALL] motion_startup: Logging to syslog
[0] [NTC] [ALL] motion_startup: Using log type (ALL) log level (NTC)
[0] [NTC] [ALL] main: Thread 1 is from /etc/motion.conf
[0] [NTC] [ALL] main: Thread 1 is device: /dev/video0 input -1
[0] [NTC] [ALL] main: Stream port 8081
[0] [NTC] [ALL] main: Waiting for threads to finish, pid: 1546
[0] [NTC] [STR] httpd_run: motion-httpd testing : IPV4 addr: 127.0.0.1 port: 8080
[0] [NTC] [STR] httpd_run: motion-httpd Bound : IPV4 addr: 127.0.0.1 port: 8080
[0] [NTC] [STR] httpd_run: motion-httpd/3.4.0-Git-78ba2da running, accepting connections
[0] [NTC] [STR] httpd_run: motion-httpd: waiting for data on 127.0.0.1 port TCP 8080
[1] [NTC] [ALL] motion_init: Thread 1 started , motion detection Enabled
[1] [NTC] [VID] vid_v4lx_start: Using videodevice /dev/video0 and input -1
[1] [NTC] [VID] v4l2_get_capability: 
------------------------
cap.driver: "uvcvideo"
cap.card: "UVC Camera (046d:081b)"
cap.bus_info: "usb-101c0000.ehci-1"
cap.capabilities=0x84000001
------------------------
[1] [NTC] [VID] v4l2_get_capability: - VIDEO_CAPTURE
[1] [NTC] [VID] v4l2_get_capability: - STREAMING
[1] [NTC] [VID] v4l2_select_input: name = "Camera 1", type 0x00000002, status 00000000
[1] [NTC] [VID] v4l2_select_input: - CAMERA
[1] [WRN] [VID] v4l2_select_input: Device doesn't support VIDIOC_G_STD
[1] [NTC] [VID] v4l2_set_pix_format: Config palette index 17 (YU12) doesn't work.
[1] [NTC] [VID] v4l2_set_pix_format: Supported palettes:
[1] [NTC] [VID] v4l2_set_pix_format: (0) YUYV (YUV 4:2:2 (YUYV))
[1] [NTC] [VID] v4l2_set_pix_format: 0 - YUV 4:2:2 (YUYV) (compressed : 0) (0x56595559)
[1] [NTC] [VID] v4l2_set_pix_format: (1) MJPG (MJPEG)
[1] [NTC] [VID] v4l2_set_pix_format: 1 - MJPEG (compressed : 1) (0x47504a4d)
[1] [NTC] [VID] v4l2_set_pix_format Selected palette YUYV
[1] [NTC] [VID] v4l2_do_set_pix_format: Testing palette YUYV (320x240)
[1] [NTC] [VID] v4l2_do_set_pix_format: Using palette YUYV (320x240) bytesperlines 640 sizeimage 153600 colorspace 00000008
[1] [NTC] [VID] v4l2_scan_controls: found control 0x00980900, "Brightness", range 0,255 
[1] [NTC] [VID] v4l2_scan_controls:     "Brightness", default 128, current 128
[1] [NTC] [VID] v4l2_scan_controls: found control 0x00980901, "Contrast", range 0,255 
[1] [NTC] [VID] v4l2_scan_controls:     "Contrast", default 32, current 32
[1] [NTC] [VID] v4l2_scan_controls: found control 0x00980902, "Saturation", range 0,255 
[1] [NTC] [VID] v4l2_scan_controls:     "Saturation", default 32, current 32
[1] [NTC] [VID] v4l2_scan_controls: found control 0x00980913, "Gain", range 0,255 
[1] [NTC] [VID] v4l2_scan_controls:     "Gain", default 64, current 64
[1] [NTC] [VID] vid_v4lx_start: Using V4L2
[1] [NTC] [ALL] image_ring_resize: Resizing pre_capture buffer to 1 items
[1] [NTC] [STR] http_bindsock: motion-stream testing : IPV4 addr: 127.0.0.1 port: 8081
[1] [NTC] [STR] http_bindsock: motion-stream Bound : IPV4 addr: 127.0.0.1 port: 8081
[1] [NTC] [ALL] motion_init: Started motion-stream server in port 8081 auth Disabled

当检测到有motion产生的时候,就会输出以下的类似日志:

[1] [NTC] [EVT] event_newfile: File of type 1 saved to: ./02-20171104171022-01.jpg
[1] [NTC] [EVT] event_newfile: File of type 1 saved to: ./02-20171104171023-00.jpg
[1] [NTC] [EVT] event_newfile: File of type 1 saved to: ./02-20171104171023-01.jpg
[1] [NTC] [EVT] event_newfile: File of type 1 saved to: ./02-20171104171024-00.jpg
[1] [NTC] [EVT] event_newfile: File of type 1 saved to: ./02-20171104171024-01.jpg
[1] [NTC] [EVT] event_newfile: File of type 1 saved to: ./02-20171104171025-00.jpg

motion

参考文章

使用motion实现摄像头自动拍照上传
摄像头用motion做监控非常棒


txgcwm
764 声望71 粉丝

Linux C/C++


引用和评论

0 条评论