Friday, May 16, 2008

How to grab still images off AXIS cameras and generate time lapse movies from them.

This depends on several free programs. mencoder which comes with mplayer2, sleep from Microsoft resource kit, and Irfanview 4.10 or better.

The first batch file grabs the images and looks like this;
e:
cd \
md xvid
cd\xvid
md 8080
md 8081

:top
wget -O8081.jpg --tries=1 --timeout=5 "http://user:pwd@domain.dyndns.org:8081/jpg/1/image.jpg"
wget -O8080.jpg --tries=1 --timeout=5 "http://user:pwd@domain.dyndns.org:8080/axis-cgi/jpg/image.cgi?camera=1&resolution=1024x800&compression=50"

rem If you want an e-mail of the image, use this;
rem E:\Blat250\Blat250\full\blat.exe - -body "8081" -serversmtp gmail-smtp-in.l.google.com -f fromuser@domain.com -subject "8081" -to user@gmail.com -attach 8081.jpg -noh2 -alttext Camera


setlocal

call :GETDATEPARTS "%date%"
call :GETTIMEPARTS


ren 8081.jpg "8081-%yy%%mm%%dd%_%h%%m%%RANDOM%.jpg"
ren 8080.jpg "8080-%yy%%mm%%dd%_%h%%m%%RANDOM%.jpg"

move 8081*.jpg 8081\.
move 8080*.jpg 8080\.
sleep 10
goto top

:GETTIMEPARTS

for /f "tokens=1-3 delims=:." %%a in ('echo %time%') do call :SETTIMEPART h %%a&call :SETTIMEPART m %%b&call :SETTIMEPART s %%c

goto :EOF

:SETTIMEPART

set %1=%2

if 1%2 LSS 100 set %1=0%2

goto :EOF

REM ***************************************************

:GETDATEPARTS

set dt=%~1
set tok=1-3

if "%dt:~0,1%" GTR "9" set tok=2-4

set yyyy=

for /f "tokens=%tok% delims=.:/-, " %%a in ('echo %~1') do (
 for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do set %%x=%%a&set %%y=%%b&set %%z=%%c
)

if not "%yyyy%"=="" set yy=%yyyy%

if 1%yy% LSS 1000 (if %yy% LSS 70 (set yy=20%yy%) else (set yy=19%yy%))
if 1%mm% LSS 100 set mm=0%mm%
if 1%dd% LSS 100 set dd=0%dd%

goto :EOF



==== That is the end of the first batch file. It will grab an image from two cameras and save them with a date and time stamp in separate directories. Obviously you must change this as is appropriate for your hard drive and LAN.

The next batch file is below;



md e:\xvid\8080\old2
md e:\xvid\8080\old3
md e:\xvid\8081\old2
md e:\xvid\8081\old3
del e:\xvid\8081\old3\*.jpg /q/s
del e:\xvid\8080\old3\*.jpg /q/s

e:
cd\xvid
cd 8080
move *.jpg old2\.
cd old2

rem cd "C:\Program Files\IrfanView"
rem c:
rem fails
rem start /wait i_view32.exe "e:\xvid\8080\old2\*.jpg" /resize=(600,480) /resample /bpp=24 /aspectratio /jpgq=99 /convert="e:\xvid\8080\old3\*.jpg" /silent

dir /b *.jpg > proc.txt
@for /f "delims=| tokens=1,2,3,4,5,6,7,8,9,10" %%i in (proc.txt) do (
@echo %%i
@echo %%j
@C:\zentemp\unsecure\screenc\i_view32 "e:\xvid\8080\old2\%%i" /resample /bpp=24 /aspectratio /jpgq=99 /convert="e:\xvid\8080\old3\%%i" /silent
)
cd "C:\Program Files\IrfanView"
c:
@start /wait i_view32.exe "e:\xvid\8080\old3\*.jpg" /resize=(600,480) /resample /aspectratio /convert="e:\xvid\8080\old3\*.jpg" /silent

@e:

@e:
@cd e:\xvid\8080\old3

@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:\temp\8080-%DATE:/=%%TIME::=%.mpg"
rem remove ,harddup from the line above to make this remove
rem duplicate frames.  Resulting file is MUCH smaller, however quality does suffer.


:try2
@rem o now cam 8081

e:
cd\xvid
cd 8081
move *.jpg old2\.
cd old2

dir /b *.jpg > proc.txt
@for /f "delims=| tokens=1,2,3,4,5,6,7,8,9,10" %%i in (proc.txt) do (
@echo %%i
@echo %%j

@C:\zentemp\unsecure\screenc\i_view32 "e:\xvid\8081\old2\%%i" /resample /bpp=24 /aspectratio /jpgq=99 /convert="e:\xvid\8081\old3\%%i" /silent
)
@cd "C:\Program Files\IrfanView"
@c:
@start /wait i_view32.exe "e:\xvid\8081\old3\*.jpg" /resize=(600,480) /resample /aspectratio /convert="e:\xvid\8081\old3\*.jpg" /silent



@e:
@cd e:\xvid\8081\old3

@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:\temp\8081-%DATE:/=%%TIME::=%.mpg"



That's a pretty big batch file. What it does is take all of the JPG's and normalizes them using Irfan view. Irfan view has some bugs, so we can't batch convert except for the resize. AXIS sometimes returns back color images, sometimes black and white. The encoding changes. If we don't specify the size on the wget, then sometimes the size can change. mencoder doesn't like any of this. To make a movie, the images must all be the same. Irfanview fills this role.

The mencoder settings are set for high quality, not much compression. You can adjust as needed. This file plays very well in VideoLan (VLC player) if you have problems with codec's in your default media player.

No comments: