View Full Version : IF/ElSE Batch file help
rack04
4th February 2009, 20:37
I'm trying to automate and simplify the batch file that I use for my Blu-ray/HD DVD encodes. I'm hoping someone can help write an IF/ELSE statement that will allow the batch file to automatically use the correct DGAVCIndex/DGVC1Index/DGIndex based on the file extension. For example:
@SET DGAVCIndexNV_PATH=C:\Program Files\DGAVCIndexNV\DGAVCIndexNV.exe
@SET DGVC1IndexNV_PATH=C:\Program Files\DGVC1IndexNV\DGVC1IndexNV.exe
@SET DGIndex_PATH=C:\Program Files\DGIndex\DGIndex.exe
@SET INPUT_VIDEO=
@SET INPUT_VIDEO_TYPE=
@SET WORKING_DIRECTORY=
@SET OUTPUT_FILENAME=
Line A "%DGAVCIndexNV_PATH%" -i "%INPUT_VIDEO%" -o "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.dga" -f 2 -e -h
Line B "%DGVC1IndexNV_PATH%" -i "%INPUT_VIDEO%" -o "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.dgv" -f 2 -e -h
Line C "%DGIndex_PATH%" -AIF=[%INPUT_VIDEO%] -OF=[%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output] -exit -hide -OM=0
What would the IF/ELSE statement be if I wanted:
Line A to be selected if the %INPUT_VIDEO_TYPE% is "h264"
Line B to be selected if the %INPUT_VIDEO_TYPE% is "vc1"
Line C to be selected if the %INPUT_VIDEO_TYPE% is "m2v"
I don't know the syntax but here is my lame attempt using =IF(statement,value if true,value if false) syntax to hopefully help explain:
=IF(%INPUT_VIDEO_TYPE%="h264",A,IF(%INPUT_VIDEO_TYPE%="vc1",B,C))
RunningSkittle
4th February 2009, 20:48
Can you please provide a sample of what your directory tree looks like? This will help immensely!
rack04
4th February 2009, 21:23
Can you please provide a sample of what your directory tree looks like? This will help immensely!
How would I go about doing that? :p
rack04
4th February 2009, 22:57
I tried this and it did not work:
IF %INPUT_VIDEO_TYPE% == h264
GOTO LINEA
IF %INPUT_VIDEO_TYPE% == vc1
GOTO LINEB
IF %INPUT_VIDEO_TYPE% == m2v
GOTO LINEC
GOTO END
:LINEA
"%DGAVCIndexNV_PATH%" -i "%INPUT_VIDEO%" -o "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.dga" -f 2 -e -h
GOTO END
:LINEB
"%DGVC1IndexNV_PATH%" -i "%INPUT_VIDEO%" -o "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.dgv" -f 2 -e -h
GOTO END
:LINEC
"%DGIndex_PATH%" -AIF=[%INPUT_VIDEO%] -OF=[%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output] -exit -hide -OM=0
GOTO END
JohnnyMalaria
5th February 2009, 00:32
When you say it doesn't work, what exactly happens? (Pipe the batch file output to a text file and post it here)
Have you considered a VBScript to do this - it's much easier.
rack04
5th February 2009, 01:13
When you say it doesn't work, what exactly happens? (Pipe the batch file output to a text file and post it here)
Have you considered a VBScript to do this - it's much easier.
It immediately closes. How do I "pipe the batch file output to a text file"?
JohnnyMalaria
5th February 2009, 01:40
If your batch file is called foo.bat then at the command prompt type "foo.bat >someoutput.txt" without the quotes. Anything that the batch file writes to the screen will end up in the file specified instead. For example "dir >list.txt" creates a directory listing a text file.
You may want to add some echo statements so you can see how far the batch file gets and/or print some info such as what the variables are actually set to. Also, try adding the word echo to the lines that call your program. That way you can see if your logic is correct without actually invoking the program which may be where things are falling down.
rack04
5th February 2009, 01:50
Here is my complete .bat file:
@SET DGAVCIndex_PATH=C:\Program Files\DGAVCIndex\DGAVCIndex.exe
@SET x264_PATH=C:\Program Files\MeGUI\tools\x264\x264.exe
@SET mkvmerge_PATH=C:\Program Files\MKVtoolnix\mkvmerge.exe
@SET eac3to_PATH=C:\Program Files\eac3to\eac3to.exe
@SET INPUT_VIDEO=C:\Personal\Videos\fastandfurious-sbspot_h720p_track1.h264
@SET INPUT_AUDIO=C:\Personal\Videos\fastandfurious-sbspot_h720p_track2.aac
@SET INPUT_VIDEO_TYPE=h264
@SET WORKING_DIRECTORY=C:\Personal\Videos
@SET OUTPUT_DIRECTORY=C:\Personal\Videos
@SET OUTPUT_FILENAME=Fast and Furious
@SET DESIRED_BITRATE=4161
@SET DIMENSIONS=1280x532
@Echo off
Echo.[ %OUTPUT_FILENAME% ] [ %TIME% ] Creating Index of Raw Video Stream ...
Echo.
Echo.
IF %INPUT_VIDEO_TYPE% == h264
GOTO LINEA
IF %INPUT_VIDEO_TYPE% == vc1
GOTO LINEB
IF %INPUT_VIDEO_TYPE% == m2v
GOTO LINEC
GOTO END
:LINEA
"%DGAVCIndex_PATH%" -i "%INPUT_VIDEO%" -o "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.dga" -f 2 -e -h
GOTO LINED
:LINEB
"%DGVC1IndexNV_PATH%" -i "%INPUT_VIDEO%" -o "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.dgv" -f 2 -e -h
GOTO LINED
:LINEC
"%DGIndex_PATH%" -AIF=[%INPUT_VIDEO%] -OF=[%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output] -exit -hide -OM=0
GOTO LINED
:LINED
Pause
Echo.
Echo.[ %OUTPUT_FILENAME% ] [ %TIME% ] Encoding Pass 1 ...
Echo.
Echo.
Echo.
"%x264_PATH%" --pass 1 --bitrate %DESIRED_BITRATE% --stats "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%.stats" --level 4.1 --keyint 24 --min-keyint 1 --bframes 3 --b-adapt 2 --b-pyramid --weightb --direct auto --deblock -1:-1 --subme 2 --partitions none --vbv-bufsize 30000 --vbv-maxrate 24000 --qcomp 0.5 --me dia --merange 24 --threads auto --thread-input --sar 1:1 --aud --progress --no-psnr --no-ssim --output NUL "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.avs" --mvrange 511 --nal-hrd
Echo.
Echo.
Echo.
Echo.[ %OUTPUT_FILENAME% ] [ %TIME% ] Encoding Pass 2 ...
Echo.
Echo.
Echo.
"%x264_PATH%" --pass 2 --bitrate %DESIRED_BITRATE% --stats "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%.stats" --level 4.1 --keyint 24 --min-keyint 1 --ref 3 --mixed-refs --bframes 3 --b-adapt 2 --b-pyramid --weightb --direct auto --deblock -1:-1 --subme 7 --trellis 2 --partitions all --8x8dct --vbv-bufsize 30000 --vbv-maxrate 24000 --qcomp 0.5 --me umh --merange 24 --threads auto --thread-input --sar 1:1 --aud --progress --no-psnr --no-ssim --output "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.h264" "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.avs" --mvrange 511 --nal-hrd
Echo.
Echo.
Echo.
Echo.[ %OUTPUT_FILENAME% ] [ %TIME% ] Muxing Encoded Video Stream to MKV ...
Echo.
Echo.
Echo.
"%eac3to_PATH%" "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.h264" "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.mkv"
Echo.
Echo.
Echo.
Echo.[ %OUTPUT_FILENAME% ] [ %TIME% ] Muxing Raw Audio Stream and Chapters to MKV ...
Echo.
Echo.
Echo.
"%mkvmerge_PATH%" -o "%OUTPUT_DIRECTORY%\%OUTPUT_FILENAME%-muxed.mkv" --language 1:eng --display-dimensions 1:%DIMENSIONS% -d 1 -A -S "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.mkv" --language 0:eng -a 0 -D -S "%INPUT_AUDIO%" --track-order 0:1,1:0 --chapter-language eng --chapters "%INPUT_CHAPTER%"
Echo.
Echo.
Echo.
Echo.[ %OUTPUT_FILENAME% ] [ %TIME% ] Deleting Temporary Files ...
Echo.
Echo.
Echo.
DEL "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.dga"
DEL "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.dgv"
DEL "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.d2v"
DEL "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.avs"
DEL "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%.stats"
DEL "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.h264"
DEL "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output.mkv"
DEL "%WORKING_DIRECTORY%\%OUTPUT_FILENAME%-output - Log.txt"
:END
Echo.
Echo.
Echo.
Echo.[ %OUTPUT_FILENAME% ] [ %TIME% ] Finised !
Echo.
Echo.
Echo.
Pause
I tried the txt file output but it didn't make it past the first line.
RunningSkittle
5th February 2009, 02:02
What are the file extensions of the videos you intend to index?
ie what extension do your h264 files have? vc1 files? mpeg 2 files?
RunningSkittle
5th February 2009, 02:16
In any case, this should help you get started.
In this example, i have a folder (c:\videos) with files
videoh264.h264
videovc1.vc1
videompeg2.m2v
My batch file looks like this:
@echo off
::-----::
set avc="C:\Program Files\DGAVCIndexNV\DGAVCIndexNV.exe"
set vc1="C:\Program Files\DGVC1IndexNV\DGVC1IndexNV.exe"
set mpg="C:\Program Files\DGIndex\DGIndex.exe"
set directory="c:\videos"
::-----::
::for /r %directory% %%a in (*) do (call :loop "%%a" "%%~xa" %%~na)
::the above line can be used instead to recurse through all child directories in the directory tree
for %%a in (%directory%\*) do (call :loop "%%a" "%%~xa" %%~na)
goto endloop
:loop
if %2 == ".h264" echo %avc% %1 "%3.dga"
if %2 == ".vc1" echo %vc1% %1 "%3.dgv"
if %2 == ".m2v" echo %mpg% %1 "%3.d2v"
::Obviously delete the echo command and fill in your commands and switches
echo -----
goto eof
:endloop
pause
echo Done
:eof
My console output looks like this:
"C:\Program Files\DGAVCIndexNV\DGAVCIndexNV.exe" "c:\videos\videoh264.h264" "videoh264.dga"
-----
"C:\Program Files\DGIndex\DGIndex.exe" "c:\videos\videompeg2.m2v" "videompeg2.d2v"
-----
"C:\Program Files\DGVC1IndexNV\DGVC1IndexNV.exe" "c:\videos\videovc1.vc1" "videovc1.dgv"
-----
Press any key to continue . . .
henryho_hk
9th March 2009, 17:28
IF /i "%INPUT_VIDEO_TYPE%"=="h264" GOTO LINEA
IF /i "%INPUT_VIDEO_TYPE%"=="vc1" GOTO LINEB
IF /i "%INPUT_VIDEO_TYPE%"=="m2v" GOTO LINEC
"/i" means case insensitive comparison.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.