Thursday, March 27, 2008

How to grab images off an Axis camera and save them in a time lapse format

I have two Axis Cameras which I want to grab an image from every 10 seconds and store offsite.
My Firewall is configured to pass traffic on ports 1081 and 1080 to the two Axis cameras.

Below is a batch file to accomplish this. It relies upon WGET and SLEEP which is free to download if you search.

:top
wget -O1081.jpg http://user:password@yourdnsname:1081/jpg/1/image.jpg
wget -O1080.jpg http://user:password@yourdnsname:1080/jpg/1/image.jpg
ren 1081.jpg 1081-%DATE:/=%%TIME::=%.jpg
ren 1080.jpg 1080-%DATE:/=%%TIME::=%.jpg
move 1081*.jpg 1081\.
move 1080*.jpg 1080\.
sleep 10
goto top

Store that in a batch file in an empty directory along with WGET. Create two directories named 1080 and 1081.

Launch the batch file -- it will loop forever, storing your images in these directories.

Now, turn them into a time lapse film using mplayer..

Download mplayer (Search Google) and extract mencoder from the zip file. Place that in this directory..

Create another batch file with these contents;
c:
cd \yourdir\1080
mencoder mf://*.jpg -mf fps=5:type=jpg -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf -vf scale=720:576,harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=1800:vbitrate=500:keyint=15:vstrict=0:acodec=ac3:abitrate=64:aspect=4/3 -ofps 25 -o c:\yourdir\1080.mpg

cd \yourdir\1081
mencoder mf://*.jpg -mf fps=5:type=jpg -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd:tsaf -vf scale=720:576,harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=1800:vbitrate=500:keyint=15:vstrict=0:acodec=ac3:abitrate=64:aspect=4/3 -ofps 25 -o c:\yourdir\1081.mpg


Of course replace c:\yourdir with the proper location. This will generate an mpg video of all these JPG's, and it will remove any duplicate images. Change fps from 25 to 5 for a slower view. Change maxrate and bitrate higher to get better quality.

If you have problems playing the mpg, you can use mplayer to play it or download VLC Videolan and play it through that. I use VLC because it can also stream directly from the AXIS camera and has it's own recording options.. But that's a different post.

No comments: