Archive for January 2008 / Video category
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.
<Feed feed1.ffm>
# 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
</Feed>
# Multipart JPEG
<Stream test1.mjpeg>
Feed feed1.ffm
Format mpjpeg
VideoFrameRate 4
VideoIntraOnly
VideoSize 320x240
VideoBitRate 900
NoAudio
Strict -1
</Stream>
<Stream stat.html>
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
</Stream>
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
See Also: Part 2: Motion Capture using the WVC54GC Wireless Webcam with Linux and related article How to use the WVC54GC wireless webcam with Firefox
Introduction
The Linksys Compact Wireless-G Internet Video Camera WVC54GC is a linux based wireless webcam with its own streaming web server built in. Windows users can view the video stream through their browser without the need to install any extra software other than allowing the supplied Active-X control to run. Strangely, while the product itself appears to be linux based, and its firmware is open source which you can download from the Linksys website, there isn't much in the documentation about using this camera with Linux.
Installation (setting up the network connection)
The setup tool that comes with it is a windows tool. This is the easiest way to configure the WVC54GC, and of course doesn't prevent you from using the camera from Linux. This was my case, as I have a Windows computer and a Linux computer, and I set the WVC54GC up from Windows, though I tend to use it from Linux. Anyway – if you want to do it from Linux, you can use the following method:
- Plug the camera in to your regular network hub, and remove everything else appart from the Linux computer you will be using to configure the Webcam. Temporarily set the IP address of your computer on this interface to 192.168.1.1. The camera should be either at 192.168.1.115.
- Point your browser to the camera's IP address and go to administrator interface - the default username is admin with password admin
- Configure the network, wireless, and image settings, and change the password.
- You can set either an IP address compatible with your network (in the same range) or if you are using a DHCP server (many ADSL routers have one built in and enabled by default) you can select that instead. I actually use a DHCP server which runs on my Linux machine (see the next section).
- Change your computers IP address back to normal, unplug the webcam, and plug everything else back in, disconnecting the power to the WVC54GC and then reconnecting it having removed the ethernet cable should be enough to get the camera to start up in wireless mode.
Tip:Use DHCP and DNS
I have one linux computer, used as a server, which is switched on pretty much all of the time, and I run dnsmasq on that. Dnsmasq, which will be the subject of another post, is a combined DHCP and dns server. This works quite well with network devices such as the WVC54GC, since you can set a name, and configure it to request and IP address via DHCP, this name will then resolve correctly on your network. So thats tip 1 really, not necessary to actually use the video camera on your home network (you can always set up the IP address manually), but its certainly a comfortable way of managing the configuration.
Viewing Video
The raw video stream itself is actually available at http://yourwebcamera/img/video.asf. ASF is a Microsoft format – but plenty of Linux software can use it. Its a digital video container format sometimes known as 'Advanced Streaming Format'. The actually encoding of the video is MPEG-4 – a widely used standard. So, while you cannot run the active X control under Linux, you have plenty of choices of software you can use to view the video stream, provided you know where it is. Software you can use include the popular Mplayer, Xine and VLC.
Video Applications
Thats all very well for viewing video, but what about real applications such Video Capture or Motion detection. The Linksys WVC54GC actually has some of this capability built in. It can be configured to detect motion, and email a video fragment to a predefined email address.
Video Still Capture
While the Linksys WVC54GC is first and foremost a video camera, you may want to save snapshots from it from under linux. The video viewing software Mplayer also comes with some tools which allow you to capture video and stills, once you have installed Mplayer, you can issue a command like:
mplayer http://10.0.0.26/img/video.asf -frames 1 -vo jpeg
Obviously, subsitute 10.0.0.26 for the IP or the DNS name of your WVC54GC web camera. Mplayer will save a file 000000001.jpg with a snapshot. Mplayer uses ffmpeg to do the conversion, so you will certainly need that installed too. The best quality image will be achieved if you have set high quality in the Wifi webcams on-line setup page.
Video Capture
Video Capture is just as easy as capturing stills. This can be done with 'ffmpeg' which will have been installed when you installed mplayer, as mplayer has ffmpeg as a dependency. Issue a command like:
ffmpeg -i http://10.0.0.26/img/video.asf -vcodec mjpeg -b 900k test.mjpeg
Press Q to stop recording. The '-b' option governs the quality (or bitrate) reduce the number to reduce the size of the files that are recorded, however you will see a corresponding decrease in video quality.
See Also: Part 2: Motion Capture using the WVC54GC Wireless Webcam with Linux and related article How to use the WVC54GC wireless webcam with Firefox