|
Answer» Hello, everybody. I'm new here, but I try to learn a few THINGS about creating batch files. I'm trying to create a batch file in order to do some video encodes, but via CMD without a GUI. So here is an example (it doesn't fully work of course:))
Code: [Select]ECHO OFF cls color 2
:question1 ECHO Select the path where x264.exe is located. ECHO examples: C:\Program Files\megui\tools\x264 or D:\Encoding Tools ECHO. SET /p x264_path= IF errorlevel 1 goto question2 IF errorlevel 2 goto end
ECHO. :question2 ECHO Select the path and the name of the avs script. (without the .avs extension!) ECHO e.g. D:\MyMovie\avisynthscript ECHO. SET /p avs_path_filename= IF errorlevel 1 goto question3 IF errorlevel 2 goto end
ECHO. :question3 SET /p bitrate=Select the video bitrate (kb/s): IF errorlevel 2 goto question4 IF errorlevel 1 goto end
ECHO. :question4 SET /p ref_frames=Select the number of reference frames (1-16, recommended 4): IF errorlevel 2 goto question5 IF errorlevel 1 goto end
ECHO. :question5 SET deblocking_strength=Set the deblocking strength and threshold (-6:-6, default -1:-1): IF errorlevel 2 goto question6 IF errorlevel 1 goto end
ECHO. set b-adapt_mode=2 set b-frames_number=3 set subme_mode=9 set TRELLIS=2 set psy-rd=0.1:0 set ME=umh set me_range=32 set priority=BELOWNORMAL set stats_path=%avs_path_filename%.stats
cls
ECHO ON ECHO:Encoding 1st pass started on %date% - %TIME% ECHO. ECHO OFF
start "x264" /%priority% /b /wait "%x264_path%\x264.exe" --pass 1 --bitrate %bitrate% --stats "%stats_path%" --level 4.1 --keyint 240 --min-keyint 24 --ref %ref_frames% --mixed-refs --no-fast-pskip --bframes %b-frames_number% --b-adapt %b-adapt_mode% --b-pyramid --weightb --direct auto --filter %deblocking_strength% --subme %subme_mode% --trellis %trellis% --psy-rd %psy-rd% --partitions p8x8,b8x8,i4x4,i8x8 --8x8dct --vbv-bufsize 50000 --vbv-maxrate 50000 --me %ME% --merange %me_range% --threads auto --thread-input --sar 1:1 --progress --no-psnr --no-ssim --output "%avs_path_filename%_pass1.mkv" "%avs_path_filename%.avs"
ECHO ON ECHO. ECHO:Encoding 1st pass finished on %date% - %time% ECHO:============================================================================== ECHO:============================================================================== ECHO. ECHO:Encoding 2nd pass started on %date% - %time% ECHO. ECHO OFF
start "x264" /%priority% /b /wait "%x264_path%\x264.exe" --pass 2 --bitrate %bitrate% --stats "%stats_path%" --level 4.1 --keyint 240 --min-keyint 24 --ref %ref_frames% --mixed-refs --no-fast-pskip --bframes %b-frames_number% --b-adapt %b-adapt_mode% --b-pyramid --weightb --direct auto --filter %deblocking_strength% --subme %subme_mode% --trellis %trellis% --psy-rd %psy-rd% --partitions p8x8,b8x8,i4x4,i8x8 --8x8dct --vbv-bufsize 50000 --vbv-maxrate 50000 --me %ME% --merange %me_range% --threads auto --thread-input --sar 1:1 --progress --no-psnr --no-ssim --output "%avs_path_filename%_pass2.mkv" "%avs_path_filename%.avs"
ECHO ON ECHO. ECHO. ECHO:Encoding 2nd pass finished on %date% - %time% ECHO:============================================================================== ECHO:============================================================================== :end What I'd like to do is for example when asked for the desired bitrate, to accept only numbers and have a default value for all the variables. So the user can input his choice but if he wants, he could press for instance the letter D and automatically the default value would be entered. Also I'd like to contain some values. for instance in the ref frames from 1-16 etc.
Thank you in advance!
PS1. Sorry for my English. PS2. If these are answered somewhere, please point me there.You're asking for an awful lot from a language with a limited instruction set.
Quote What I'd like to do is for example when asked for the desired bitrate, to accept only numbers and have a default value for all the variables
Without a third party program, you have to check the data entry after the fact:
Code: [Select]echo off setlocal enabledelayedexpansion set numflag=y set /p bitrate=Enter bit rate: for /l %%i in (0,1,19) do ( call set bit=%%bitrate:~%%i,1%% if .%bitrate%==. set bitrate=192 & goto next if .!bit!==. goto next echo !bit! | findstr [0-9] > nul if errorlevel 1 set numflag=n ) :next if %numflag%==y echo %bitrate% is numeric if %numflag%==n echo %bitrate% not numeric
The code does not restrict alpha characters; only checks if the input is numeric; the length of the input is determined by the first space character or 20 characters, whichever comes first. The default bit rate is 192.
Setting defaults should be a little simpler:
Code: [Select]echo off set bitrate= set /p bitrate=Enter bitrate: if .%bitrate%==. set bitrate=2400 echo %bitrate%
The default value is used when the user enters no value to the prompt.
The code snippets are designed to show method. Hope it gives you some ideas for your code.
Good luck. Oh dear, chem4! Those long lines of code make this thread a scroll bar NIGHTMARE!!!
|