0. Make sure you have 
* A supported WebCam
* PHP (preferably compiled with GD support)
  - in php.ini use must use : register_globals=On
* Xawtv (including the command line program 'streamer')
  Make sure the streamer works. 
  Try e.g. : /usr/bin/streamer -s 320x240 -o test.jpeg
  Make sure this command works for the user you plan to run the script under.

  If you have another command line tool that captures a snapshot and saves it as a jpeg,
  just change the '$capture' accordingly.

* Mysql (optional, only for www interface)
* Apache (optional, only for www interface)

1. Unpack the downloaded files somewhere
> gunzip phpmotiondetect.tgz
> tar xfz phpmotiondetect.tar
> cd phpmotiondetect

For access to the WWW interface unpack the files somewhere, where the Apache server can see the files
and you are done with the www-setup

2. Create the MySQL database for archiving (optional)
   If you want to create a new database do 
   mysql -u usename -h hostname -p 
   mysql> CREATE DATABASE motiondetect;


   To create the tables 'log' and 'images' in the database 'motiondetect'
   issue the following command.
   mysql -u usename -h hostname -p motiondetect' < motiondetect.sql

   NB : Any database name can be used !


3. edit conf.php
conf.php contains settings that determine the behavior of phpmotiondetect
Please be careful that the user that runs the script should have read/write access
to $outdir 

3.a : SETUP MOTION
   - You can now spoecify how to call any number of moviemaking routines in conf.php.
     simply add a $movie[$i] section.
     The main thing is to get the $movie[$i]['cmd'] line correct.
     Names in CAPITAL letters will be replaced with the proper values at runtime
     converttogif=1, converts all snapshots to gif from jpeg before the movie 
     command is run (nessecary when using e.g. GifSicle)

4. Test that the script works
set '$usecron=1' and '$verbose=20' in conf.php. 
This causes the script to run only once and then exit, and write plenty of
debug information to the screen when running.

Now run the motiondetect script as :
-----
> php -q motiondetect.php
motiondetect(20) 1 : USING DB (root@127.0.0.1)
motiondetect(20) 1 : SELECTED DB -- OK (root@127.0.0.1)
motiondetect(20) 5 : Using existing old=/tmp/kontor_old.jpeg
motiondetect(20) 5 : Snapshot command (New snapshot) : /usr/bin/streamer -s 320x240 -o /tmp/kontor_new.jpeg >& /dev/null
motiondetect(20) 10 : Reading /tmp/kontor_new.jpeg.
motiondetect(20) 10 : Reading /tmp/kontor_old.jpeg.
motiondetect(20) 1 : snap=0001, New=101.5, Ref=102.4, Diff= -0.8
motiondetect(20) 5 : Insert 'log' entry into DB
<br />
<b>Warning</b>:  Unable to create '/tmp/kontor_old.jpeg':  Permission denied in <b>/var/www/html/develop/phpmotiondetect/motiondetect.php</b> on line <b>90</b><br />
motiondetect(20) 1 : Failed to copy /tmp/kontor_new.jpeg to /tmp/kontor_old.jpeg
-----

In the example above permissions were not set properly for $outdir 
This was fiex and the output now shows :


When you can run the script without any errors you are ready to start detecting motion.

5. Detect motion
You can run the motiondetect.php script in two modes :

5a : Stand alone
In this mode set '$usecron=0' in conf.php, 
Set '$verbose=1' to get some data written to the console, just to check that 
everything is working. Set '$verbose=-1' when everything is working OK.
and from the command line start the motion detection by
> php -q motiondetect.php


5b : Crontab mode
You can run the motiondetect.php script from the crontab. 
You can set crontab up to running the script down to once per minute.
Make sure the script is working properly. Then set 
$verbose=-1;
$usecron=1;
in conf.php.
Now update crontab for the user you want to run the script with something
like : (replace with proper paths)

* * * * * /usr/bin/php q /var/www/html/phpmotiondetect/motiondetect.sh

6 : WWW interface
If you untarred the tgz file where they are available using an Apache server, then simply 
go to that directory on the web server, using your favorite web browser, and you should 
be able to browse the archived snapshot.


Send you questions/remarks to thomas@lixnet.dk

