Log in

View Full Version : quick batch script question


saint-francis
30th July 2008, 23:01
Since MeGUI no longer seems to work on my PC (blame Vista) I need to find a way to write a batch script that will encode several movies in a row. I can make a batch file that will encode one video but how would I modify the script to continue on encoding two more? Maybe point me in the direction of a good reference on this topic. I have been asking google but all of the information I'm finding (while very useful and interesting) is not immediately relevant to my needs.

setarip_old
31st July 2008, 01:43
Hi!

Does the following address your needs?

http://forum.doom9.org/showpost.php?p=1164615&postcount=2

saint-francis
31st July 2008, 01:49
Hi!

Does the following address your needs?

http://forum.doom9.org/showpost.php?p=1164615&postcount=2

I'm not sure. It's the "Next" command that will start the new command after the previous one has completed?

dat720
31st July 2008, 01:55
I'm not sure. It's the "Next" command that will start the new command after the previous one has completed?

Yes, next will move to the next vob file found....

But if you already have a batch file for encoding try this:

FORFILES -s -m *.VOB -c "CMD /C XVIDEncode.bat @FILE"

This will start XVIDEncode.bat with each VOB file in that directory

saint-francis
31st July 2008, 02:10
What I'm trying to do it run multiple x264 cmd lines one after another. I almost always use the same x264 setting so it's no difficulty to make a .bat to run one. I was just wondering if I put a bunch in a .bat and separate them with a "Next" will they run sequentially? I'm sorry I don't understand the example you just gave me. Does the script you posted run the same cmd.bat for each file in a given folder, one at a time? Sounds interesting if so. So the "*.VOB" part of your script indicates that all .VOB files in the directory will be processed in order? So I would put each .avs I wanted to encode from in a folder? And the "CMD /C XVIDEncode.bat @FILE" is the encoder command line? If this is so how do you deal with the fact that the encoder command line needs to have an input and an output?

dat720
31st July 2008, 02:26
So the "*.VOB" part of your script indicates that all .VOB files in the directory will be processed in order? So I would put each .avs I wanted to encode from in a folder? And the "CMD /C XVIDEncode.bat @FILE" is the encoder command line? If this is so how do you deal with the fact that the encoder command line needs to have an input and an output?

Your on the right track there

I deal with the requirement of a output file in the batch file itself...

In my mencoder batch files i use this: -o "%~dpn1.xvid.avi"
This creates a file named nearly identical to the original file except without its original extention and .xvid appended on the end.

PS it's not a script, its a command built into Windows!

RunningSkittle
31st July 2008, 13:55
Im pretty proficient with NT bath script :)

You can use a script like this to run through subfolders and enumerate all files with extension .vob, the commented line just enumerates files in %path%. the variable "%1" is the file name that gets passed from %%a in the loop. The script will work as it is, and echo each filename that it finds. Just set "%path%" to whatever you want.


@echo off
color 0a
title x264 loop

set path="c:\dvdrips"
set mencoder="c:\mencoderpath\mencoder.exe"

for /r %path% %%a in (*.vob) do (call :loop "%%a")
::for %%a in (%path%\*.vob) do (call :loop "%%a")
goto endloop
:loop
echo %date%
echo %time%
echo %1
::other commands inside loop, for example:
::%mencoder% %1 settings
echo ----------
goto eof
:endloop

::other commands outside of the loop

pause
:eof


Of course you can do a lot more too! NT batch can do some pretty sophisticated things if you know how :)

Substitute .vob for whatever you want.

smok3
31st July 2008, 14:30
how do you deal with the fact that the encoder command line needs to have an input and an output

depends on how smart do you want to be,

if you are simple then you can just set out to be in the same folder with different name, example.bat:

@echo off
echo %~d1%~p1%~n1.mp4

so
example.bat file.avi
would return
a:\path\file.mp4

-----

say you want a different folder, but same base name for output;
example2.bat
@echo off
echo %~d2%~p2%~n1.mp4

so
example2.bat file.avi a:\path\to\my\out\
should return
a:\path\to\my\out\file.mp4

-----
faq:

Q. How do I parse a file name parameter into its' constituent parts?
A.

Parameter Description
%1 The normal parameter.
%~f1 expands %1 to a fully qualified path name.
%~d1 expands %1 to a drive letter only.
%~p1 expands %1 to a path only.
%~n1 expands %1 to a file name only (prefix)
%~x1 expands %1 to a file extension only.
%~s1 changes the meaning of n and x options to
reference the short name.

You can use these modifiers in combination:
Parameter Description
%~dp1 expands %1 to a drive letter and path only.
%~nx1 expands %1 to a file name and extension only.

Additional parameter extensions available in Win2K / XP:

%~1 - expand %1 removing any surrounding quotes (")
%~a1 - display the file attributes of %1
%~t1 - display the date/time of %1
%~z1 - display the file size of %1
%~$PATH:1 - search the PATH environment variable
and expand %1 to the fully qualified name
of the first match found.

-----

check my solution, targeted to total commander thought;
http://somestuff.org/bat/index.php?path=x264_ng_batch/ (where x264_ng_tcm.bat is the loop for x264_ng.bat)

example:
x264_ng.bat bit-480 avs-"t:\path\templateWEB.avs" fil-"0,0" met-1NG

bit = x264 bitrate
avs = path to avisynth template
fil = x264 filter parameter
met = build in method (x264 command line)

dat720
31st July 2008, 16:02
Good explanation there, that was way too much effort for me :)

%~dpn1.xvid.avi suits everything i want to do so that is what i use.

RunningSkittle
31st July 2008, 16:12
of course if you use the modifiers in a batch file you need to use %%, instead of %.

That explanation, along with documentation for all options can be found under help, or "command /?"

I suggest looking at the for command documentation

saint-francis
31st July 2008, 18:56
Whoa. OK. Thanks for the input everyone. Honestly that is over my head. I just spent about 15 minutes trying to figure all of that out and all I learned is that I need to do some homework. I'm not a programmer by any means. I'm a philosopher and a therapist! I'm probably going to end up being one by the time I get the hang of video encoding though.

Edit: I got what I wanted done BTW. I just pasted my x264 commands specifying the input and output for each and separating them with a NEXT.

RunningSkittle
31st July 2008, 20:11
well you can do that with ntbatch!

just create a .txt file with that looks like this, and rename it to .bat


x264.exe settings file1
x264.exe settings file2
x264.exe settings file3


it automatically goes to the next line when its finished.