USB Cam Intro to Motion and Zoneminder

I wrote this as intro notes at work BEFORE the last Post on Zoneminder Nightmares, but it may be useful if you are new to all this as I was/still am.

It may be useful as an intro for Motion which I haven't looked at much yet, but is better and less complex for a Pi and small scale monitoring than ZM from what I have read.

ffmpeg is no longer available in mint 17.2, so I assume avconv replaces it which is in the package:

apt-get install libav-tools

Run:

MintServer stevee # tail -f /var/log/syslog

Plug in Webcam and watch for driver registry:

Aug 7 09:17:31 MintServer anacron[1015]: Job `cron.daily' terminated

Aug 7 09:26:45 MintServer anacron[1015]: Job `cron.monthly' started

Aug 7 09:26:45 MintServer anacron[1015]: Job `cron.monthly' terminated

Aug 7 09:26:45 MintServer anacron[1015]: Normal exit (2 jobs run)

Aug 7 09:26:45 MintServer anacron[3728]: Updated timestamp for job `cron.monthly' to 2015-08-07

Aug 7 09:32:03 MintServer kernel: [ 1238.788042] usb 2-8: new full-speed USB device number 4 using ohci-pci

Aug 7 09:32:03 MintServer kernel: [ 1238.992059] usb 2-8: New USB device found, idVendor=05a9, idProduct=a511

Aug 7 09:32:03 MintServer kernel: [ 1238.992071] usb 2-8: New USB device strings: Mfr=0, Product=0, SerialNumber=0

Aug 7 09:32:03 MintServer mtp-probe: checking bus 2, device 4: "/sys/devices/pci0000:00/0000:00:02.0/usb2/2-8"

Aug 7 09:32:03 MintServer mtp-probe: bus: 2, device: 4 was not an MTP device

Aug 7 09:32:03 MintServer kernel: [ 1239.043675] media: Linux media interface: v0.10

Aug 7 09:32:03 MintServer kernel: [ 1239.074424] Linux video capture interface: v2.00

Aug 7 09:32:03 MintServer kernel: [ 1239.090671] gspca_main: v2.14.0 registered

Aug 7 09:32:03 MintServer kernel: [ 1239.105343] gspca_main: ov519-2.14.0 probing 05a9:a511

Aug 7 09:32:04 MintServer kernel: [ 1240.604238] input: ov519 as /devices/pci0000:00/0000:00:02.0/usb2/2-8/input/input16

Aug 7 09:32:05 MintServer kernel: [ 1240.616144] usbcore: registered new interface driver ov519USB

Install motion:

apt-get install motion

The motion daemon on/off - for later – is in:

vi /etc/motion/motion.conf

and

vi /etc/default/motion

in each file respectively below.:

# Start in daemon (background) mode and release terminal (default: off)
daemon off

# set to 'yes' to enable the motion daemon
start_motion_daemon=no

You may need to create the default PID directory /var/run/motion/ for when you run Daemon mode - in Raspbian/Mint the PID goes in:

# File to store the process ID, also called pid file. (default: not defined)
process_id_file /var/run/motion/motion.pid

make a dir for camera images if not default location e.g.:

mkdir /Share/motion

Backup the config file first. The motion conf file is in:

cp -v /etc/motion/motion.conf /Share/motion.conf.bak

copy a hidden DIRECTORY version for your user to run if required, and edit that version, unless you WANT to run as root?:

cp -v /etc/motion/motion.conf     /home/stevee/.motion/motion.conf

Threads and config files
If Motion was invoked with command line option -c pathname
Motion will expect the config file to be as specified. When you
specify the config file on the command line with -c you can call
it anything.
If you do not specify -c or the filename you give Motion does
not exist, Motion will search for the configuration file called
'motion.conf' in the following order:
1. Current directory from where motion was invoked
2. Then in a directory called '.motion' in the current users
home directory (shell environment variable $HOME). E.g.
/home/goofy/.motion/motion.conf

sudo vi /etc/motion/motion.conf

Key parts to note:

# Start in Setup-Mode, daemon disabled. (default: off)

setup_mode off

# Videodevice to be used for capturing (default /dev/video0)

# for FreeBSD default is /dev/bktr0

videodevice /dev/video0

# v4l2_palette allows to choose preferable palette to be use by motion

# to capture from those supported by your videodevice. (default: 8)

# E.g. if your videodevice supports both V4L2_PIX_FMT_SBGGR8 and

# V4L2_PIX_FMT_MJPEG then motion will by default use V4L2_PIX_FMT_MJPEG.

# Setting v4l2_palette to 1 forces motion to use V4L2_PIX_FMT_SBGGR8

# instead.

#

# Values :

# V4L2_PIX_FMT_SN9C10X : 0 'S910'

# V4L2_PIX_FMT_SBGGR8 : 1 'BA81'

# V4L2_PIX_FMT_MJPEG : 2 'MJPEG'

# V4L2_PIX_FMT_JPEG : 3 'JPEG'

# V4L2_PIX_FMT_RGB24 : 4 'RGB3'

# V4L2_PIX_FMT_UYVY : 5 'UYVY'

# V4L2_PIX_FMT_YUYV : 6 'YUYV'

# V4L2_PIX_FMT_YUV422P : 7 '422P'

# V4L2_PIX_FMT_YUV420 : 8 'YU12'

v4l2_palette 8

Try the default 8 above first, then others above for your camera, unless you know its specs. Note v4l2 may need to be installed also. A PiCam and a Creative Optia webcam can run in YUYV.

# The video input to be used (default: 8)

# Should normally be set to 0 or 1 for video/TV cards, and 8 for USB cameras

input 8

# Image width (pixels). Valid range: Camera dependent, default: 352

width 320

Try 640 above after its working, or values given by cam specs.

# Image height (pixels). Valid range: Camera dependent, default: 288

height 240

Try 480 above after its working

# Maximum number of frames to be captured per second.

# Valid range: 2-100. Default: 100 (almost no limit).

framerate 2

# Minimum time in seconds between capturing picture frames from the camera.

# Default: 0 = disabled - the capture rate is given by the camera framerate.

# This option is used when you want to capture images at a rate lower than 2 per second.

minimum_frame_time 0

# 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

Analog camera?

# 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

Where do you want the output?

# Target base directory for pictures and films

# Recommended to use absolute path. (Default: current working directory)

target_dir  /tmp/motion

############################################################

# Live Webcam Server

############################################################

# The mini-http server listens to this port for requests (default: 0 = disabled)

webcam_port 8081

# Quality of the jpeg (in percent) images produced (default: 50)

webcam_quality 50

# Output frames at 1 fps when no motion is detected and increase to the

# rate given by webcam_maxrate when motion is detected (default: off)

webcam_motion off

# Maximum framerate for webcam streams (default: 1)

webcam_maxrate 1

# Restrict webcam connections to localhost only (default: on)

webcam_localhost on

# Limits the number of images per connection (default: 0 = unlimited)

# Number can be defined by multiplying actual webcam rate by desired number of seconds

# Actual webcam rate is the smallest of the numbers framerate and webcam_maxrate

webcam_limit 0

############################################################

# HTTP Based Control

############################################################

# TCP/IP port for the http server to listen on (default: 0 = disabled)

control_port 8080

I want to view camera from remote PCs so turn local off

# Restrict control connections to localhost only (default: on)

control_localhost off

# Output for http server, select off to choose raw text plain (default: on)

control_html_output on

Access Page Security?

# Authentication for the http based control. Syntax username:password

# Default: not defined (Disabled)

; control_authentication username:password

When happy with your settings, run motion to test it – it wont run as a daemon until you change it after it works manually.

MintServer stevee # motion

[0] Processing thread 0 - config file /etc/motion/motion.conf

[0] Motion 3.2.12 Started

[0] ffmpeg LIBAVCODEC_BUILD 3547904 LIBAVFORMAT_BUILD 3544067

[0] Thread 1 is from /etc/motion/motion.conf

[0] motion-httpd/3.2.12 running, accepting connections

[1] Thread 1 started

[0] motion-httpd: waiting for data on port TCP 8080

[1] cap.driver: "ov519"

[1] cap.card: "USB Camera (05a9:a511)"

[1] cap.bus_info: "usb-0000:00:02.0-8"

[1] cap.capabilities=0x85000001

[1] - VIDEO_CAPTURE

[1] - READWRITE

[1] - STREAMING

[1] Config palette index 8 (YU12) doesn't work.

[1] Supported palettes:

[1] 0: O511 (O511)

[1] Unable to find a compatible palette format.

[1] ioctl (VIDIOCGCAP): Inappropriate ioctl for device

[1] Could not fetch initial image from camera

[1] Motion continues using width and height from config file(s)

[1] Resizing pre_capture buffer to 1 items

[1] Started stream webcam server in port 8081

[1] Retrying until successful connection with camera

[1] cap.driver: "ov519"

[1] cap.card: "USB Camera (05a9:a511)"

[1] cap.bus_info: "usb-0000:00:02.0-8"

[1] cap.capabilities=0x85000001

[1] - VIDEO_CAPTURE

[1] - READWRITE

[1] - STREAMING

[1] Config palette index 8 (YU12) doesn't work.

[1] Supported palettes:

[1] 0: O511 (O511)

[1] Unable to find a compatible palette format.

[1] ioctl (VIDIOCGCAP): Inappropriate ioctl for device

It won't work with this camera as is.

apt-get install v4l-utils

Change for a compatible camera…

If you have a compatible camera (Creative Optia), you may get something like:

[1] Config palette index 8 (YU12) doesn't work.
[1] Supported palettes:
[1] 0: MJPG (MJPEG)
[1] 1: YUYV (YUV 4:2:2 (YUYV))
[1] Selected palette YUYV
[1] Test palette YUYV (320x240)
[1] Using palette YUYV (320x240) bytesperlines 640 sizeimage 153600 colorspace 00000000
[1] found control 0x00980900, "Brightness", range 0,100
[1] "Brightness", default 30, current 20
[1] found control 0x00980901, "Contrast", range 0,6
[1] "Contrast", default 2, current 1
[1] found control 0x00980902, "Saturation", range 0,8
[1] "Saturation", default 3, current 2
[1] found control 0x00980903, "Hue", range -4,4
[1] "Hue", default 0, current 0
[1] found control 0x00980910, "Gamma", range 0,7
[1] "Gamma", default 3, current 3
[1] mmap information:
[1] frames=4
[1] 0 length=153600
[1] 1 length=153600
[1] 2 length=153600
[1] 3 length=153600
[1] Using V4L2
[1] Resizing pre_capture buffer to 1 items
[1] Started stream webcam server in port 8081
[1] File of type 1 saved to: /Share/motion/01-20150810163450-09.jpg

Try palettes 6 or 2 in this case above:

[1] 0: MJPG (MJPEG)
[1] 1: YUYV (YUV 4:2:2 (YUYV))

If you want to know all the specs from your camera (these are from a PiCam on Raspbian), use:

root@PiBlanc:~# v4l2-ctl --all
Driver Info (not using libv4l2):
Driver name : bm2835 mmal
Card type : mmal service 16.1
Bus info : platform:bcm2835-v4l2
Driver version: 3.18.11
Capabilities : 0x85200005
Video Capture
Video Overlay
Read/Write
Streaming
Device Capabilities
Device Caps : 0x05200005
Video Capture
Video Overlay
Read/Write
Streaming
Priority: 2
Video input : 0 (Camera 0: ok)
Format Video Capture:
Width/Height : 320/240
Pixel Format : 'YUYV'
Field : None
Bytes per Line: 640
Size Image : 153600
Colorspace : Broadcast NTSC/PAL (SMPTE170M/ITU601)
Custom Info : feedcafe
Format Video Overlay:
Left/Top : 150/50
Width/Height: 1024/768
Field : None
Chroma Key : 0x00000000
Global Alpha: 0x00
Clip Count : 0
Clip Bitmap : No
Framebuffer Format:
Capability :
Flags : Overlay Matches Capture/Output Size
Width : 320
Height : 240
Pixel Format : 'YU12'
Bytes per Line: 480
Size image : 115200
Colorspace : Broadcast NTSC/PAL (SMPTE170M/ITU601)
Streaming Parameters Video Capture:
Capabilities : timeperframe
Frames per second: 30.000 (30000/1000)
Read buffers : 1

User Controls

brightness (int) : min=0 max=100 step=1 default=50 value=2 flags=slider
contrast (int) : min=-100 max=100 step=1 default=0 value=1 flags=slider
saturation (int) : min=-100 max=100 step=1 default=0 value=2 flags=slider
red_balance (int) : min=1 max=7999 step=1 default=1000 value=1000 flags=slider
blue_balance (int) : min=1 max=7999 step=1 default=1000 value=1000 flags=slider
horizontal_flip (bool) : default=0 value=0
vertical_flip (bool) : default=0 value=0
power_line_frequency (menu) : min=0 max=3 default=1 value=1
sharpness (int) : min=-100 max=100 step=1 default=0 value=0 flags=slider
color_effects (menu) : min=0 max=15 default=0 value=0
rotate (int) : min=0 max=360 step=90 default=0 value=0
color_effects_cbcr (int) : min=0 max=65535 step=1 default=32896 value=32896

Codec Controls

video_bitrate_mode (menu) : min=0 max=1 default=0 value=0 flags=update
video_bitrate (int) : min=25000 max=25000000 step=25000 default=10000000 value=10000000
repeat_sequence_header (bool) : default=0 value=0
h264_i_frame_period (int) : min=0 max=2147483647 step=1 default=60 value=60
h264_level (menu) : min=0 max=11 default=11 value=11
h264_profile (menu) : min=0 max=4 default=4 value=4

Camera Controls

auto_exposure (menu) : min=0 max=3 default=0 value=0
exposure_time_absolute (int) : min=1 max=10000 step=1 default=1000 value=1000
exposure_dynamic_framerate (bool) : default=0 value=0
auto_exposure_bias (intmenu): min=0 max=24 default=12 value=12
white_balance_auto_preset (menu) : min=0 max=9 default=1 value=1
image_stabilization (bool) : default=0 value=0
iso_sensitivity (intmenu): min=0 max=4 default=0 value=0
exposure_metering_mode (menu) : min=0 max=2 default=0 value=0
scene_mode (menu) : min=0 max=13 default=0 value=0

JPEG Compression Controls

compression_quality (int) : min=1 max=100 step=1 default=30 value=30

If your camera is compatible, you should get an output stream viewable in Firefox/Kmeleon or other, which does video format/implementation compatible rendering.

Chrome does not work for this in Mint or IE8 in Win.

Motion8081.jpg

############################################################
# Image File Output
############################################################

# Output 'normal' pictures when motion is detected (default: on)
# Valid values: on, off, first, best, center
# When set to 'first', only the first picture of an event is saved.
# Picture with most motion of an event is saved when set to 'best'.
# Picture with motion nearest center of picture is saved when set to 'center'.
# Can be used as preview shot for the corresponding movie.
output_normal first

Zoneminder:

This installs loads of mysql server stuff, and if you have installed prior versions and have the "Can't change mysql password..." problem – you have to do a COMPLETE uninstall and PURGE of ALL prior related mysql versions, files, directories etc.

Useful commands to see what's left in after

apt-get remove --purge mysql*

are:

which mysql

If no results then mysql is mostly removed.

mysql --version

If no results then mysql is mostly removed.

apt-get autoremove

apt-get autoclean

rm -vr /etc/mysql/*

There is another cmd to list all mysql related files like php5 etc but I lost and forgot it, sorry…

if all is ok:

apt-get install zoneminder

service zoneminder status

ZoneMinder is running

Check apache2 is running :

service apache2 status

* apache2 is running

Check mysql is running :

service mysql status

mysql start/running, process 7794

See if zoneminder web service on 8080 is running – no.

nmap 127.0.0.1

Starting Nmap 6.40 ( http://nmap.org ) at 2015-08-07 10:41 BST

Nmap scan report for localhost (127.0.0.1)

Host is up (0.000042s latency).

Not shown: 994 closed ports

PORT STATE SERVICE

22/tcp open ssh

80/tcp open http

139/tcp open netbios-ssn

445/tcp open microsoft-ds

631/tcp open ipp

3306/tcp open mysql

Open a browser and try 127.0.0.1 to check apache2 and browser is ok:


Check there is a zm DB in mysql:

mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 88

Server version: 5.5.44-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases ;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| zm |

+--------------------+

4 rows in set (0.04 sec)

Change apache2 to the zm default folders found in:

vi /usr/share/zoneminder

ZM_PATH_DATA=/usr/share/zoneminder

Note the other parameters in that file above for change later, like user/pword etc.

vi /etc/apache2/sites-available/000-default.conf

ServerAdmin webmaster@localhost

DocumentRoot /usr/share/zoneminder

service apache2 restart

* Restarting web server apache2

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.1.244. Set the 'ServerName' directive globally to suppress this message

get rid of that msg:

vi /etc/apache2/apache2.conf

# Global configuration

#

ServerName MintServer

service apache2 restart

* Restarting web server apache2 [ OK ]

service zoneminder restart

Stopping ZoneMinder: success

Starting ZoneMinder: success

Note: 127.0.0.1 is NOT a localhost link equivalent for zm! Use "localhost" in the browser:


Use the web console to add NewMonitor, check logs etc.


Hardly a surprise, but this camera (OV519) doesn't work, but should view in here:


10/8/15

Only once running in daemon mode will Motion take jpegs whilst only movement occurs, with each frame being saved into the set directory.

When testing on non daemon mode, a stream of jpegs are continuously output, presumably until the storage space is filled, if left running.

This App seems more geared toward security, depending on event action (hence the name!) by recording and timestamping frames.
There doesn't seem to be a continuous "monitor" mode I have found yet, to just view "live" streaming data if there is no movement, as there is in ZM, unless you use the ffmpeg decoder section, so you need to study and tweak settings to make a "movie" it seems, in:

# Motion Detection Settings:
############################################################

# Picture frames must contain motion at least the specified number of frames
# in a row before they are detected as true motion. At the default of 1, all
# motion is detected. Valid range: 1 to thousands, recommended 1-5
minimum_motion_frames 1

AND:

############################################################
# 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 off

# 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

Comments are closed.

Post Navigation