Log in

View Full Version : automating video processing


niv
25th January 2005, 18:01
Hay all,
The chor in hand is to take a tv show that is captured weekly at Mjpeg/MP3. clean it and 2 pass it to xvid. I am doing it because I later send it via a 128Kbit. so the file can't be to big.

Following good advise (http://forum.doom9.org/showthread.php?s=&threadid=82563&highlight=niv) from these forums I came up with a batch file and two virtualdub scripts:

Any thoughts of how to make things better?

~~~~~~~~~~~~~~~~~~~ e2.bat ~~~~~~~~~~~~~~~~~~~~
rem ******************************************************************
rem * This script will encode a mjpeg avi show recorded from the tv *
rem * it recevies %1 as the file name *
rem * if %2 is 3 it will preforme a vhs bad quality filtering *
rem ******************************************************************

if %1=="" goto error
if not exist %1 goto error

rem setting some stuff
rem set %workin_path% = "f:\"

rem -- here I need to check if the encode finished correctly when
rem it was last run.
rem The check shuold be if the output final file (%1.2.avi) is from
rem the same date as the original (%1.avi) or a day older AND it is
rem larger then 500Mb

rem ***********************************************************************
rem * muxing the audio out *
rem ***********************************************************************
echo muxing original audio out

move "%~1" f:\film.avi
"E:\Program Files\VirtualDubMod\VirtualDubMod.exe" /s"E:\Video_scripting\mux_snd_out.syl" /x
move f:\film.avi "%~1"

rem ******************************************************************
rem * Pre-process: *
rem * Now to generate an avs file which: *
rem * 1. open file *
rem * 2. 2-D clean *
rem * 3. deinterlace - Telecide() *
rem * 4. fix levels - add 20% gamma *
rem * 5. 3-D Clean *
rem ******************************************************************
echo pre-prosesing
date /T
time /T

rem chk to see that a previos run was not interupted after this stage
if exist "%~1.MJPG.avi" goto 1st_pass

rem chk that there is enogh free space on target drive
echo SetMemoryMax(40) > "%~1.pre.avs"
echo AVISource("%~1") >> "%~1.pre.avs"

rem use this if previos line fails
rem echo DirectShowSource("%~1") > "%~1.pre.avs"
rem %~1 removes the doble quote from %1

echo GuavaComb("PAL") >> "%~1.pre.avs"
echo PeachSmoother() >> "%~1.pre.avs"
echo Telecide(order=1,guide=2,post=2,vthresh=25) >> "%~1.pre.avs"
echo Levels(0,1.15,255,0,255) >> "%~1.pre.avs"

echo Convolution3D(preset = "movieLQ") >> "%~1.pre.avs"
rem e.l.s.e echo Convolution3D(0, 32, 128, 16, 64, 10, 0) >> "%~1.pre.avs"

avs2avi "%~1.pre.avs" "%~1.MJPG.avi" -c MJPG -p 0 -w
rem get audio out of "%~1"
rem if "%~1.MJPG.avi" is as big as %1 -> delete %1

if not exist "%~1.MJPG.avi" goto pre-err

:1st_pass
rem ******************************************************************
rem * first encode to establish compression ratio *
rem ******************************************************************

if exist "%~1.1.avi" goto 2nd_pass

rem chk to see the file is big enotgh lots of tilda z where removed
rem if "%1.MJPG.avi" <= %1 * 0.9 goto pre-err
rem set %size%=(%1*9/10)
rem set %mjpg%=(%1.MJPG.avi)
rem if %size% <= %mjpg go2 pre-err


echo starting first encode
date /T
time /T

echo SetMemoryMax(40) > "%~1.post.avs"
echo AVISource("%1.MJPG.avi") >> "%~1.post.avs"
rem echo DirectShowSource("%1.MJPG.avi") >> "%~1.post.avs"

regedit /s defaults.reg
regedit /s pass1.reg

avs2avi "%~1.post.avs" "%~1.1.avi" -c xvid -p 0 -w

if not exist "%~1.1.avi" goto first_err

:2nd_pass
rem ******************************************************************
rem * second encode *
rem ******************************************************************

echo second encode at
date /T
time /T

comptest "%~1.1.avi" >"%~1.pass2.reg"
if not exist "%~1.pass2.reg" goto first_err
del "%~1.1.avi"
regedit /s "%~1.pass2.reg"
avs2avi "%~1.post.avs" "%~1.2.avi" -c xvid -p 0 -w

rem -- If the file was encoded - delete the original
rem -- to know this check the date of the %1.2.avi file and that it is
rem .. above 600 Mb

rem del "%~1.pre.avs"
rem del "%~1.post.avs"
regedit /s defaults.reg

rem ***********************************************************************
rem * muxing back the audio in *
rem ***********************************************************************
echo muxing audio back in
move "%~1.2.avi" f:\film_wo_snd.avi

"E:\Program Files\lame\lame.exe" -b 96 --priority 0 -h -m m f:\audio.wav audio.mp3
"E:\Program Files\VirtualDubMod\VirtualDubMod.exe" /s"E:\Video_scripting\mux_snd_in.syl" /x

move f:\film_fin.avi "%~1.fin.avi"

goto end

:error
echo You need to enter the file name after this proram
goto end

:pre-err
goto end

:first_err
regedit /s defaults.reg
goto end

:second_err
regedit /s defaults.reg
goto end

:end
echo All done :-)
date /T
time /T

~~~~~~~~~~~~~ end of e2.bat ~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~ mux_snd_out.syl ~~~~~~~~~~~~~~~
VirtualDub.Open("F:\\test.avi","",0);
VirtualDub.RemoveInputStreams();
//Add a stream coming form the currently opened file. iStreamType indicates the kind of stream you want to add (0x73647561 - 'sdua' - for audio, 0x73747874 - 'stxt' - for text), and iIndex its index (starting from 0) for this type of stream
VirtualDub.stream[0].SetSource(0x73647561,0,0);
VirtualDub.stream[0].DeleteComments(1);
VirtualDub.stream[0].AdjustChapters(1);
VirtualDub.stream[0].SetMode(0);
VirtualDub.stream[0].SetInterleave(1,500,1,0,0);
VirtualDub.stream[0].SetClipMode(1,1);
VirtualDub.stream[0].SetConversion(0,0,0,0,0);
//would be nice 2 chk out getvolume()
VirtualDub.stream[0].SetVolume();
VirtualDub.stream[0].SetCompression();
VirtualDub.stream[0].EnableFilterGraph(0);
VirtualDub.stream[0].filters.Clear();
VirtualDub.video.AdjustChapters(1);
VirtualDub.video.SetDepth(24,24);
VirtualDub.video.SetMode(0);
VirtualDub.video.SetFrameRate(0,1);
VirtualDub.video.SetRange(0,0);
VirtualDub.video.filters.Clear();
VirtualDub.stream[0].SaveWAV("F:\\audio_test.mp3");
VirtualDub.Close();
~~~~~~~~~~~ end of mux_snd_out.syl ~~~~~~~~

~~~~~~~~~~~ mux_snd_in.syl ~~~~~~~~~~~
VirtualDub.Open("F:\\test_pre2.avi","",0);
VirtualDub.RemoveInputStreams();
VirtualDub.stream[0].SetSource("F:\\audio_test.mp3",0x00000202,0);
VirtualDub.stream[0].DeleteComments(1);
VirtualDub.stream[0].AdjustChapters(1);
VirtualDub.stream[0].SetMode(0);
VirtualDub.stream[0].SetInterleave(1,500,1,0,0);
VirtualDub.stream[0].SetClipMode(1,1);
VirtualDub.stream[0].SetConversion(0,0,0,0,0);
VirtualDub.stream[0].SetVolume();
VirtualDub.stream[0].SetCompression();
VirtualDub.stream[0].EnableFilterGraph(0);
VirtualDub.stream[0].filters.Clear();
VirtualDub.video.DeleteComments(1);
VirtualDub.video.AdjustChapters(1);
VirtualDub.video.SetDepth(24,24);
VirtualDub.video.SetMode(0);
VirtualDub.video.SetFrameRate(0,1);
VirtualDub.video.SetIVTC(0,0,-1,0);
VirtualDub.video.SetRange(0,0);
// y th hel would I need this as I setmode to 0? VirtualDub.video.SetCompression(0x67706a6d,0,10000,0);
//VirtualDub.video.SetCompData(24,"EgAAAAoAAAAMAAAAAQAAAAAAAAABAAAA");
VirtualDub.video.filters.Clear();
//VirtualDub.subset.Clear();
//VirtualDub.subset.AddRange(0,6326);
VirtualDub.SaveAVI("F:\\test_pre3.avi");
VirtualDub.Close();
~~~~~~~~~~~ end of mux_snd_in.syl ~~~~~~~~~~~~

len0x
25th January 2005, 18:43
What does this have to do with GK/AGK?

niv
26th January 2005, 10:57
automate video prosessing.
Nevermind..

len0x
26th January 2005, 11:58
Well, its about GK, not about the process.
I can move it to some other forum though...