How to easily automatically access the last n motion detected jpeg files?
Question
Thanks for motion!
What I am after is something like this: just as lastsnap.jpg is the last picture taken, it would be very useful to have something like lastmotion.jpg, lastmotion-1.jpg, lastmotion-n.jpg where n is <5. If there is a simple way of doing this, it would be much appreciated. Thanks!
Environment
Motion version: |
3.1.17 |
ffmpeg version: |
not used |
Libraries: |
curl, xmlrpc |
Server OS: |
Linux Fedora Core 3, kernel 2.6.10-1.737_FC3 |
--
TWikiGuest - 28 Jan 2005
Answer
This is a perl script that I use.
It assumes using the default filename for the saved jpegs.
jpeg_filename %v-%Y%m%d%H%M%S-%q
It keeps the last 200 jpegs. You can change it to 5 if you want.
It also creates a text file called largelist.php which is simply a list of the files in the right order.
It is then easy to load this from a PHP page and make a nice presentation. See also
KennethsWebcamPackage.
To run the script set the onsave option. Example:
onsave /usr/local/bin/camparse1.pl
And now the perl script.
#!/usr/bin/perl
chdir("/usr/local/apache2/htdocs/cam1/");
chomp (@files = `ls -t *-*.jpg`);
$count = scalar @files;
$displaynumber = 200;
$displaynumber = $count if $displaynumber > $count;
print "Matched $count files\n";
my @sortedfiles = sort { ($b =~ /-(.*)-(.*)\./)[0] . ($2=="snapshot"? "00" : $2) <=> ($a =~ /-(.*)-(.*)\./)[0] . ($2=="snapshot"? "00" : $2) } @files;
unlink @sortedfiles[$displaynumber..($count-1)] if $displaynumber < $count;
open(LISTFILE, ">largelist.php");
for ($i=0;$i < $displaynumber;$i++)
{
print LISTFILE "@sortedfiles[$i]\n";
}
close(LISTFILE);
--
KennethLavrsen - 28 Jan 2005