Post subject: How do I use scripts used for encoding?
Joined: 3/20/2010
Posts: 126
I've been following the encoding guide up until the Encoding section of it. Now it said... ]quote]Regardless of whether you are using an .avi or an .avs as your input, the following command line (with some minor tweaks as noted afterwards) will initiate the video encoding process:[/quote] x264 --sar <PAR> --crf 20 --keyint <keyint> --ref 16 --no-fast-pskip --bframes 16 --b-adapt 2 --direct auto --me umh --merange 64 --subme 10 --trellis 2 --partitions all --input-range pc --range pc --rc-lookahead 250 --no-dct-decimate --tcfile-in times.txt -o video.mp4 in.avi So, I opened up a word document, copied and pasted this in, and altered it according to the instructions so that it looked like this... x264 --sar <7> --crf 0 --keyint <keyint> --ref 16 --no-fast-pskip --bframes 16 --b-adapt 2 --direct auto --me umh --merange 64 --subme 10 --trellis 2 --partitions all --input-range pc --range pc --rc-lookahead 250 --no-dct-decimate --tcfile-in times.txt -o video.mp4 in.avi Seeing that x264 was similar to AVISynth in that it wasn't it's own seperate program so much as it was something that gave your Notepad to do way more than it otherwise could, I opened up Virtualdub and chose the "Run Script" to run the script above that I had saved. But when I tried that, it told me this... Error during execution at line 1, column 5: Variable 'x264' not found x264<!> -- sar <7> --crf 0 --keyint <keyint> --ref 16 -- So what I'm wondering is, am I doing it right, and something's just not set up the way it's supposed to be? Or am I missing something? If so, what is it?
Post subject: Re: How do I use scripts used for encoding?
Editor, Player (67)
Joined: 6/22/2005
Posts: 1041
FionordeQuester wrote:
x264 --sar <PAR> --crf 20 --keyint <keyint> --ref 16 --no-fast-pskip --bframes 16 --b-adapt 2 --direct auto --me umh --merange 64 --subme 10 --trellis 2 --partitions all --input-range pc --range pc --rc-lookahead 250 --no-dct-decimate --tcfile-in times.txt -o video.mp4 in.avi
Assuming you're using Windows, you need to run that in a Command Prompt window. To bring up the Command Prompt, go to Start -> Run and enter cmd.exe. Alternately, press WinKey + R and enter cmd.exe. BTW, those <PAR> and <keyint> arguments that you entered are wrong. Which system are you trying to encode?
Current Projects: TAS: Wizards & Warriors III.
Joined: 3/20/2010
Posts: 126
I'm trying to encode the NES. Thanks for the help!
Editor, Player (67)
Joined: 6/22/2005
Posts: 1041
Like the Encoding Guide explains, you want a PAR of 7:6 for NTSC or 5:4 for PAL. It also tells you how to calculate the keyint value in the section about x264 command-line options.
Current Projects: TAS: Wizards & Warriors III.
Post subject: Re: How do I use scripts used for encoding?
creaothceann
He/Him
Editor
Joined: 4/7/2005
Posts: 1874
Location: Germany
FionordeQuester wrote:
Seeing that x264 was similar to AVISynth in that it wasn't it's own seperate program
It is a separate program, unlike Avisynth (which is a DLL) - it just has no graphical user interface. A command-line interpreter like cmd.exe is ideal for passing parameters when starting programs, and observing their text output.
FionordeQuester wrote:
[...] so much as it was something that gave your Notepad to do way more than it otherwise could
Notepad isn't involved in that, it's just an editor for text files.
FionordeQuester wrote:
I opened up Virtualdub and chose the "Run Script" to run the script above that I had saved.
VirtualDub's scripts are not the same thing as Avisynth's scripts.
Joined: 3/20/2010
Posts: 126
It also tells you how to calculate the keyint value in the section about x264 command-line options.
Alright, well, I've taken another look at that section. So, am I supposed to put into the <keyint> section this exact line? ( (number of lines) - 1) * 10000 / (last timecode)
Editor, Player (67)
Joined: 6/22/2005
Posts: 1041
You would actually have to calculate what that number comes out to based on the contents of times.txt. It would be easier to write a little program that does the calculation for you. If you make a batch file with this code, it should work for Windows:
@echo off
setlocal
setlocal EnableExtensions
setlocal EnableDelayedExpansion

set currdir=%cd%\
for /f %%a in ('find /v /c "" ^<%currdir%%1') do set /a lines=%%a - 1
for /f "skip=%lines%" %%b in (%currdir%%1) do set lasttc=%%b
for /f "tokens=1 delims=." %%c in ("%lasttc%") do set /a lasttc=%%c + 1
set /a keyint=10000 * %lines% / %lasttc%
echo %keyint%
endlocal
To use the batch file, put it into the same directory as times.txt, and run it with times.txt as the only argument:
batchname.bat times.txt
There are some limitations to what this code can do. They arise from the fact that cmd.exe only works with 32-bit signed integers for calculations. First, this means that the times.txt file can have a maximum of 2,147,483,647 lines, which wouldn't be a problem if not for the multiplication by 10,000 later. That multiplication effectively limits the file to 214,748 lines. At 60 fps, this allows a total encode time of at least 59:39.13, with the time increasing as the number of duplicated frames increases. Most of the movies on our site aren't that long, but this is a rough time limit to keep in mind if the code doesn't work. Second, this means that the maximum value of the last timecode is 2,147,483,647. Since the timecodes are in milliseconds, you are limited to a total encode time of just over 596.5 hours. I think that should cover anything on the site except Desert Bus. Sorry, Desert Bus. Third, this means that the denominator does not correspond to the exact last timecode. The third for loop in the code takes the integral part of the last timecode and adds 1. I added that 1 ms to the denominator in order to guarantee that the keyint value calculated by the code will always be less than the exact value. Since we're dealing with the total encode time, and the logo itself should be around 2 seconds long, this is an error of less than 0.05%, and it gets smaller as the movie gets longer.
Current Projects: TAS: Wizards & Warriors III.
Joined: 3/20/2010
Posts: 126
Cool. And where do I find times.txt?
Editor, Player (67)
Joined: 6/22/2005
Posts: 1041
It's generated during the Pre-encoding step.
Current Projects: TAS: Wizards & Warriors III.
Joined: 3/20/2010
Posts: 126
Well, I downloaded all the plugins it told me to download for AVISynth (DeDup-0.17 and msvc_dlls, right?), opened up the Command Prompt window, and tried to execute the first command in the sample script, which I assumed was "DeDup.dll". It told me this... "This file does not have a program associated with it for performing this action. Create an association in the "Set Associations" control panel" So, after I used the search feature to try to find it, glanced very briefly at my User Control Panel, and did a google search, I couldn't find a clear solution. Even though I found the said control panel through "Default Programs", I still don't exactly what to associate the DeDup.dll to. Am I on the wrong track? Or do I have the right idea? I thank each and every one of you for having the patience to continue answering my questions, as I really want to make the best quality videos I can. They aren't going to be tool assisted runs, but they will be ones I'll be working hard on nonetheless.
Editor, Player (67)
Joined: 6/22/2005
Posts: 1041
FionordeQuester wrote:
Well, I downloaded all the plugins it told me to download for AVISynth (DeDup-0.17 and msvc_dlls, right?), opened up the Command Prompt window, and tried to execute the first command in the sample script, which I assumed was "DeDup.dll"
What exactly did you type into the Command Prompt? Just "DeDup.dll"?
Current Projects: TAS: Wizards & Warriors III.
Joined: 3/20/2010
Posts: 126
Yes.
Editor, Player (67)
Joined: 6/22/2005
Posts: 1041
I see. You're actually supposed to copy the provided text for those scripts and paste them into text files that you save as script1.avs and script2.avs, or any other names you want to use. Change movie.avi, logo.png, and the subtitle lines as needed for the files you're working with. Then you open those avs files with VirtualDub or pass them as parameters to x264 for the different parts of the encoding process.
Current Projects: TAS: Wizards & Warriors III.
Joined: 3/20/2010
Posts: 126
I see. Should I get rid of the green text, or anything else before trying it?
Editor, Player (67)
Joined: 6/22/2005
Posts: 1041
No. The number sign (#) at the beginning indicates that it's a comment, so the programs will just ignore those lines.
Current Projects: TAS: Wizards & Warriors III.
Joined: 3/20/2010
Posts: 126
So, when I run that sample script, what should happen? It's telling me that 'LoadPlugin', '#Open', 'a', 'b', '#Adds', 'c', 'd', '#Adds' (yes, it's listed there twice in the program), 'last', '#Below', 'is', 'how', 'Subtitle', 'Subtitle', "#Converts', 'Convert to YV24', 'YV12', and '#This' (also listed twice) are, quote, "is not recognized as an internal, external, operable program, or batch note". In addition to all of that is some other sentences above these error marks, including a line that says "C:\Users\Owner>DupMC<log="duptxt") that are not getting these error messages. I know it's all very confusing, but when I tried to take a snapshot of my results, all it did was type in ^V in the command prompt script. So, this is the best way I know how to describe it.
creaothceann
He/Him
Editor
Joined: 4/7/2005
Posts: 1874
Location: Germany
Open the scripts just like a normal video file, not via VirtualDub's scripts loader. (VirtualDub scripts are not Avisynth scripts.)
Joined: 3/20/2010
Posts: 126
Actually, I used a "cmd.exe" command line to try to open the example script in the Encoding Guide.