My experiments with Flash using SWFTools
Mar 16, 2010
Detect motion, change videos
I had a student who wanted to design a kiosk, which ran an "idle" video,
which changed when a person approached.
The first step is to use the "motion" package (in Linux/BSD) to implement
a webcam, and use the config script:
------contents of /etc/default/motion
# very short delay time to sense when the viewing area is static
gap 2
# create a pipe at /var/www/body
on_event_start echo "body=yes" > /var/www/body
on_event_end echo "body=no" > /var/www/body
# by default, this directory will fill up with .jpg files; just throw them away
on_picture_save rm /tmp/motion/*
This pumps one of two phrases into the pipe-file. One at motion-detect,
and the other one at motion-stop.
Next, create a pipe to handle the transfer of information:
mkfifo /var/www/body
To get this information through the web server, create a helper script
-------contents of /var/www/getfifo.php
This little script just opens the fifo, reads the whole thing
(whenever the data is ready), and sends it back to the browser that
asked for it.
Now we can start making web pages. I am using "swfc" to compile .sc
files into .swf files, which a browser can load. Here's the demo:
.flash filename="over.swf" bbox=900x400 version=8
txtvar = "help";
.swf movie2 jet.swf
.swf movie1 sing.swf
.box b1 600 300 fill=white
.font font1 "/usr/share/fonts/truetype/msttcorefonts/timesbd.ttf"
.edittext txt text="little" variable=txtvar font=font1 color=green size=40%
width=1200 height=200
.action:
var c = 1;
var req = "getfifo.php";
var ext = new LoadVars();
var dat = "abc";
// this routine will exec when the data has been downloaded, before parsing
ext.onData = function(dat) {
// delete this line after debugging
txtvar = "result " + c + ": " + dat + " (" + dat.length + " bytes)";
c += 1;
if (dat.indexOf("body=yes")==0)
playMovie1();
else
playMovie2();
// trigger another load
ext.load(req);
};
// trigger a load
ext.load(req);
movie2.Stop();
function playMovie1() {
movie1.Play();
movie1._visible = true;
movie2.Stop();
movie2._visible = false;
}
function playMovie2() {
movie1.Stop();
movie1._visible = false;
movie2.Play();
movie2._visible = true;
}
.end
.put b1 0 0
.put movie1 100 100
.put movie2 100 100
.put txt 00 00
.end