Loading...

Motion Capture using the WVC54GC with Linux

_See Also Part 1_: Using Linksys WVC54GC Webcam with Linux and related article How to use the WVC54GC wireless webcam with Firefox

Introduction

Motion detection and capture is a little more complex as it requires you to configure several pieces of software to run together. A widely used motion detection software Motion cannot directly use the stream from the Compact Wireless-G Internet Video Camera WVC54GC, so its necessary to re-stream it using ffserver, part of the ffmpeg suite, into a format understood by motion, which is multipart JPEG (or mjpeg)

Setting up ffserver restreaming

Ffserver, is part of the ffmpeg sweat, and is a streaming server for both audio and video files. It can stream both live video as well as video from a file, likewise it can but a time delay on a live video stream. To set up restreaming, it is necessary to set up both the streaming server and the inbound stream from the WVC54GC Wireless webcam.

Configuring and running ffserver

Below is a sample ffserver configuration which sets up a stream ready for the WVC54GC. Its location depends on your Linux distribution. I use Gentoo Linux, so its found at: /etc/ffserver.conf

# Port on which the server is listening. You must select a different<  
# port from your standard HTTP web server if it is running on the same  
# computer.  
Port 8090  

# Address on which the server is bound. Only useful if you have  
# several network interfaces.  
BindAddress 0.0.0.0  

# Number of simultaneous requests that can be handled. Since FFServer  
# is very fast, it is more likely that you will want to leave this high  
# and use MaxBandwidth, below.  
MaxClients 1000  

# This the maximum amount of kbit/sec that you are prepared to  
# consume when streaming to clients.  
MaxBandwidth 10000  

# Access log file (uses standard Apache log file format)  
# '-' is the standard output.  
CustomLog -  

# Suppress that if you want to launch ffserver as a daemon.  
NoDaemon  

##################################################################  
# Definition of the live feeds. Each live feed contains one video  
# and/or audio sequence coming from an ffmpeg encoder or another  
# ffserver. This sequence may be encoded simultaneously with several  
# codecs at several resolutions.  

  

# You must use 'ffmpeg' to send a live feed to ffserver. In this  
# example, you can type:  
#  
# ffmpeg http://localhost:8090/feed1.ffm  

# Only allow connections from localhost to the feed.  
ACL allow 127.0.0.1  

  

# Multipart JPEG  

  
Feed feed1.ffm  
Format mpjpeg  
VideoFrameRate 4  
VideoIntraOnly  
VideoSize 320x240  
VideoBitRate 900  
NoAudio  
Strict -1  
  

  
Format status  

# Only allow local people to get the status  
ACL allow localhost  
#My Local network – change this to yours  
ACL allow 10.0.0.0 10.0.255.255  

Once you have saved the configuration file, you will need to start both the streaming server, and a copy ffmpeg which actually streams the content into the streaming server.

1) Start the ffmpeg server, from the bash command shell type:

**ffserver**

This will start the server. Typically the server can run as a daemon, running in the backgournd. However using the above configuration, it will stay in the foreground making debugging rather easier. Later when you have everything working you can change the “NoDaemon” setting in the file /etc/ffserver.conf

2) Since this command doesn’t return, you will have to use another bash command shell window

ffmpeg -an -i http://yourwebcam.up/img/video.asf http://localhost:8090/feed1.ffm

This will take the output from the WVC54GC and stream it into the streaming server.

Configuring Motion to use ffserver stream

The motion software has a huge number of configuration possibilities, most of which you can leave as default – and all of which are well documented in the motion’s sample config file and documentation. It even has the possibility of running more than one webcam, each detecting motion on different threads.

Below is a **fragment **of a motion configuration file showing the settings specific to the camera, most of the other settings about how to encode, where to save the files and so on are not included here; I recommended you take a look at the motion website for a full description of the configuration options.

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

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

# Maximum number of frames to be captured per second.  
# Valid range: 2-100\. Default: 100 (almost no limit).  
framerate 2  

# URL to use if you are using a network camera, size will be autodetected (incl http://)  
# Must be a URL that returns single jpeg pictures or a raw mjpeg stream. Default: Not defined  
netcam_url http://localhost:8090/test1.mjpeg  

# Let motion regulate the brightness of a video device (default: off).  
# The auto_brightness feature uses the brightness option as its target value.  
# If brightness is zero auto_brightness will adjust to average brightness value 128.  
# Only recommended for cameras without auto brightness  
auto_brightness off  

# Set the initial brightness of a video device.  
# If auto_brightness is enabled, this value defines the average brightness level  
# which Motion will try and adjust to.  
# Valid range 0-255, default 0 = disabled  
brightness 32  

# Set the contrast of a video device.  
# Valid range 0-255, default 0 = disabled  
contrast 0  

# Set the saturation of a video device.  
# Valid range 0-255, default 0 = disabled  
saturation 0  

# Set the hue of a video device (NTSC feature).  
# Valid range 0-255, default 0 = disabled  
hue 0  

############################################################  
# Live Webcam Server  
############################################################  

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

# Quality of the jpeg 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 off  

# 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

One of the key settings is http://localhost:8090/test1.mjpeg, make sure you change this to point to your ffmpeg server. This is not, then, the URL of the webcam, but the URL of the restreamed video data.

_See Also Part 1_: Using Linksys WVC54GC Webcam with Linux and related article How to use the WVC54GC wireless webcam with Firefox