Post subject: Encoding Tools
Player (65)
Joined: 4/21/2011
Posts: 232
These are some tools I put together when I was hacking around at encoding final fantasy viii. I'm sharing in case someone else might find them useful, or someone can give me some tips on my usage. (Thanks to Dark Kobold for making the TAS) 1. PSXjin outputs files at several resolutions. In order to join the files in Avisynth they need to have the same resolution/colorspace/framerate. So I made a source function to crop/pad them to match.
function customsource(string X){
    avisource(X).converttorgb32
    w=width
    h=height
    (w==368) ? crop(8,0,0,0) : nop()
    (w==320) ? addborders(20,0,20,0) : nop()
    (h==224) ? addborders(0,8,0,8) : \
        (h==216) ? addborders(0,12,0,12) : spline36resize(360,240)
}
2. Most of the game is 240p, but the disc change scenes are 480i. Square seemed to intentionally mess up the interlacing here, but I think it looks awful, so I matched the same intensity fields.
avisource("M:\ff8_avi4\000_disc4-640x480.avi")
crop(31,38,580,406)
separatefields

#2 fields of Bright, 6 of medium, 4 of dim
#e e e e e e
#B;;.;.;B.;.;
#      BB;;..
#      0769A5
selectevery(12, 0,7, 6,9, 10,5)
#pattern is always the same, but it doesn't always start on the same frame

weave
interleave(last,last)
#double frames to get back to 60Hz
#deleteframe/duplicateframe to match original frame count
3. PSXjin outputs A LOT of files. 178 avis for Disc 1. Avisynth can't usually open that many files at once, and typing them all in would be painful anyway. So I made a batch file that would take the name of a directory and splice together the avis into more managable pieces.
@ECHO OFF
SET maxsources=25
SET customsource="C:\Program Files (x86)\anrichan3.3\cs.avs"
SET counter=0
SET counterB=0

CD %~1

IF EXIST "spliced\" (
    ECHO Spliced files already exist. OVERWRITING?!?
    PAUSE
)
MKDIR "spliced\"

SETLOCAL EnableDelayedExpansion
FOR %%G IN ("*.avi") DO (
    IF !counter! EQU 0 (
        ECHO import^(%customsource%^) > "spliced\!counterB!.avs"
    ) ELSE (
        ECHO \++\ >> "spliced\!counterB!.avs"
    )
    ECHO customsource^("%%~fG"^) >> "spliced\!counterB!.avs"
    SET /A counter += 1
    ECHO !counterB!.!counter! %%~fG
    IF !counter! EQU %maxsources% (
        SET /A counter = 0
        SET /A counterB += 1
    )
)

ECHO Encode Files?
PAUSE
CD "spliced"

SET vdub="C:\Program Files (x86)\anrichan3.3\VirtualDub-1.9.7\vdub.exe"
SET vcf="C:\Program Files (x86)\anrichan3.3\spliced.vcf"
FOR %%G IN ("*.avs") DO (
    %vdub% "%%G" /i %vcf% "%%~nG.avi"
)
PAUSE
GOTO:EOF
Make the .vcf file in virtualdub, setup your encode setting, choose "Save processing settings... Crtl+S" from the file menu and add this line to the bottom.
VirtualDub.SaveAVI(VirtualDub.params[0]);
4. PSXjin outputs at a nonstandard framerate. (59.997?) I want to up this to 60, then resample the audio to keep it in synch.
avisource("0.avi")
\++\
avisource("1.avi")
\++\
avisource("2.avi")
\++\
avisource("3.avi")
\++\
avisource("4.avi")
vid=assumefps(60)

wavsource("M:\ff8_avi2\000_disc2.wav")
ResampleAudio(4409787,100)
aud=AssumeSampleRate(44100)

audiodub(vid,aud)
Post subject: Re: Encoding Tools
Editor, Emulator Coder, Site Developer
Joined: 5/11/2011
Posts: 1108
Location: Murka
nanogyth wrote:
Square seemed to intentionally mess up the interlacing here, but I think it looks awful, so I matched the same intensity fields.
Have you checked real console output? I'd bet a million dollars that it's the emulator's fault.
nanogyth wrote:
Avisynth can't usually open that many files at once
Could you elaborate a bit on this? Is there actually an open files limit for the scripting environment?
Post subject: Re: Encoding Tools
Editor, Player (67)
Joined: 6/22/2005
Posts: 1041
natt wrote:
nanogyth wrote:
Avisynth can't usually open that many files at once
Could you elaborate a bit on this? Is there actually an open files limit for the scripting environment?
The Avisynth wiki points to this thread for more information. It appears to be an OS limit due to how Avisynth uses DLLs.
Current Projects: TAS: Wizards & Warriors III.