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
Thanks for the post. Very useful!
Thanks for all this information.
While I think my problem is related to some sort of wrong ffmpeg/ffserver configuration I just wanted to ask you if you run into a similar problem. In ffmpeg mailing lists a similar problem has not been answered for long time now (http://thread.gmane.org/gmane.comp.video.ffmpeg.user/15132)
Basically ffserver (FFserver version r11872+debian_3:0.svn20080206-12ubuntu3, Copyright (c) 2000-2008 Fabrice Bellard, et al.) starts OK with the proposed configuration, in my case using ffserver -f /home/nurquiza/ffserver.conf
After running (protocol omitted since no more than one URL is allowed to be posted) ffmpeg -an -i yourwebcam.up/img/video.asf localhost:8090/feed1.ffm I get this from ffmpeg:
...
Press [q] to stop encoding
[mjpeg @ 0xb7e252f0]rc buffer underflow
[mpeg4 @ 0xb7e252f0]slice end not reached but screenspace end (12 left 7FF000, score= -3)
[mpeg4 @ 0xb7e252f0]concealing 300 DC, 300 AC, 300 MV errors
[mpeg4 @ 0xb7e252f0]slice end not reached but screenspace end (2 left 400000, score= -2)
[mpeg4 @ 0xb7e252f0]concealing 300 DC, 300 AC, 300 MV errors
... and this from ffserver:
127.0.0.1 - - [Sun Nov 30 07:47:31 2008] "GET /feed1.ffm HTTP/1.1" 200 36917
ffmpeg keeps on going outputing lines like:
[asf @ 0xb7fa8388]freeing incomplete packet size 3948, new 558293.8kbits/s
When I try to get the stream from ffserver (localhost:8090/test1.mjpeg) mplayer shows a snapshot and crashes.
If I start motion and request localhost:8081 (I left original port 8081 since I am not using it) I just get "Connection with camera lost since <time motion daemon was started>"
If I try from a browser localhost:8090/test1.mjpeg then I get the below error from ffmpeg:
[mpeg4 @ 0xb7e252f0]hmm, seems the headers are not complete, trying to guess time_increment_bits
[mpeg4 @ 0xb7e252f0]my guess is 2 bits ;)
[mpeg4 @ 0xb7e252f0]ac-tex damaged at 0 0
[mpeg4 @ 0xb7e252f0]Error at MB: 0
[mpeg4 @ 0xb7e252f0]concealing 300 DC, 300 AC, 300 MV errors
[mpeg4 @ 0xb7e252f0]hmm, seems the headers are not complete, trying to guess time_increment_bits
[mpeg4 @ 0xb7e252f0]my guess is 1 bits ;)
[mpeg4 @ 0xb7e252f0]Error, header damaged or not MPEG4 header (qscale=0)/s
[mpeg4 @ 0xb7e252f0]header damaged
Error while decoding stream #0.0
[mpeg4 @ 0xb7e252f0]ac-tex damaged at 5 2
[mpeg4 @ 0xb7e252f0]Error at MB: 47
[mpeg4 @ 0xb7e252f0]concealing 300 DC, 300 AC, 300 MV errors
[mpeg4 @ 0xb7e252f0]Error, header damaged or not MPEG4 header (qscale=0)
[mpeg4 @ 0xb7e252f0]header damaged
Error while decoding stream #0.0
[mpeg4 @ 0xb7e252f0]hmm, seems the headers are not complete, trying to guess time_increment_bits
[mpeg4 @ 0xb7e252f0]my guess is 5 bits ;)
[asf @ 0xb7fa8388]freeing incomplete packet size 5924, new 317887.1kbits/s
[asf @ 0xb7fa8388]freeing incomplete packet size 5930, new 354487.7kbits/s
and from ffserver:
127.0.0.1 - - [Sun Nov 30 08:04:18 2008] "GET /test1.mjpeg HTTP/1.0" 200 107
Segmentation fault
Just as a side note in regards to your other useful posts for the linksys camera I have found ffmpeg crashing after some random capturing time. I put it in a script that respawns everytime it exists just to find that sometimes it wont keep on capturing and it will not exit. Since I did not find any way of solve the problem just from ffmpeg I decided to capture the whole stream (available through img/mjpeg.cgi) with wget which allows me to control read errors and connection timing. Of course it also means that I am getting huge files with pretty much nothing in them since I cannot get motion detection to work:
wget --read-timeout=3 -t 3 "<your-user>:<your-password>@<your-ip>/img/mjpeg.cgi" -O "/home/nurquiza/`date +%Y%m%d%H%M%S`.mjpeg" -o "/home/nurquiza/`date +%Y%m%d%H%M%S`.log"