PDA

View Full Version : avs -> avi -> HCenc... 2 Pass Speed Boost.


mikeytown2
4th December 2007, 11:46
I made a script that will take an avs file, outputs an avi, then use that avi in HCenc. It's written in AutoIt (http://www.autoitscript.com/autoit3/), Thread for it
http://www.autoitscript.com/forum/index.php?showtopic=58691

It's far from complete, but it will take input from the gui or drag and drop files on top of the exe. It can handle multiple files or even a directory as input. Uses HC.ini for HC settings, thus it uses the same settings for all the avs files.

This in in response to my own post
http://forum.doom9.org/showthread.php?p=1072001#post1072001

squid_80
4th December 2007, 14:36
There's an even better way. Do a search for an avisynth filter called twriteavi. With some creative scripting you can make it write the avi file and do the first pass in HC at the same time, then when the HC second pass starts you can use the avi file for the source.
It sounds pretty cryptic, but is possible - I just don't have a script handy (or the time to write one out) at the moment. The advantage is you remove one instance of avi decoding by performing the encode and the first pass at the same time.

G_M_C
4th December 2007, 15:38
Why exactly dont you use the AviSynth for both passes ?

I do, and on my E6750 i get avg 50 ~55 fps on a PAL DVD encode (720x576).

Blue_MiSfit
4th December 2007, 19:14
sometimes your AviSynth script is very slow. I mean _VERY_ slow. In these cases, you actually save time by rendering out a lossless AVI ahead of time, and then using that as a source.

~Misfit

G_M_C
4th December 2007, 20:37
sometimes your AviSynth script is very slow. I mean _VERY_ slow. In these cases, you actually save time by rendering out a lossless AVI ahead of time, and then using that as a source.

~Misfit

Hmmm, i get it;

It can save you 50% time in extreme cases (need to encode the slow AVS script only once). I' ll have to remember that trick :)

mikeytown2
4th December 2007, 23:09
@squid_80 Thanks for the tip!

This thread has a lot of talk but no "real" solution
http://forum.doom9.org/showthread.php?t=121869

If we could make a script that has 2 outputs by using twriteavi, then have the script select the lossless source for pass 2. We can accomplish this by using
a try catch block
http://avisynth.org/mediawiki/Control_structures
Or Writing a temp file
http://avisynth.org/mediawiki/WriteFile
Then reading that file
http://avisynth.org/mediawiki/Import
http://avisynth.org/mediawiki/ConditionalReader

If twriteavi could accept FourCC like avs2avi does then this script could be run without user input.
In avisynth Is there a way to get the scripts own name and is there a way see if a file exists?


Another way would be to use
http://avisynth.org/mediawiki/ImageWriter
http://avisynth.org/mediawiki/ImageSource
But this would use even more space then a lossless codec.


Any Thoughts?

squid_80
5th December 2007, 08:17
If twriteavi could accept FourCC like avs2avi does then this script could be run without user input. Having twriteavi run without user input would be nice, but there needs to be some way to pass parameters to the compression codec.
In avisynth Is there a way to get the scripts own name and is there a way see if a file exists?
Exist(filename): returns TRUE or FALSE after checking if the file exists.

So you'd do something likeexist("output.avi") ? avisource("output.avi") : twriteavi("output.avi")
to have it use output.avi as the source if it already exists (second pass) or use twriteavi to write it (first pass). You'd probably want to do a bit more checking though, like making sure output.avi has the correct number of frames (also make sure HC closes and re-opens the .avs file on second pass start otherwise it won't work at all).

mikeytown2
5th December 2007, 10:38
Having twriteavi run without user input would be nice, but there needs to be some way to pass parameters to the compression codec.
Because this is a lossless codec, and its a temp avi; passing parameters to the codec IMHO is not a high priority. In my sucky AutoIt Script i didn't pass compression settings to avs2avi.

Sweet looks like most of the stuff i need is in here
http://avisynth.org/mediawiki/Internal_functions/Boolean_functions
http://avisynth.org/mediawiki/Operators
http://avisynth.org/mediawiki/Clip_properties
http://avisynth.org/mediawiki/Block_statements

A delete file function might be useful? In any case i think i got this working

Global LFileName = "TempLossless.avi"
Global SourceFile = AVISource("OrginalInput.avi")

exist(LFileName) ? ChkLosslessFile(LFileName) : RunScriptAndOutputLosslessFile(SourceFile)


function ChkLosslessFile(string f)
{
LossLessFile = AVISource(f)
(Framecount(SourceFile) == Framecount(LossLessFile)) ? UseLosslessFile(LossLessFile) : RunScriptAndOutputLosslessFile(SourceFile)
}

function UseLosslessFile(clip s)
{
s = Spline36Resize(s,320,240)
return s
}

#Put your normal script functions in this function
function RunScriptAndOutputLosslessFile(clip c)
{
c = Spline36Resize(c,720,480).TWriteAvi(fname=LFileName, overwrite=true, showAll=true)
Return c
}

TWriteAvi DLL I used
http://bengal.missouri.edu/~kes25c/TWriteAvi.zip

mikeytown2
6th December 2007, 04:59
k i was looking into the source code for TWriteAvi. Seems like all thats needed is to add a new variable to the public class declaration and TWriteAvi function call (const char* _userFourCC) . After this we change this code

// select compressor and fill COMPVARS cvar info
cvar.cbSize = sizeof(COMPVARS);
if (showAll)
{
if(!ICCompressorChoose(NULL, ICMF_CHOOSE_ALLCOMPRESSORS | ICMF_CHOOSE_DATARATE |
ICMF_CHOOSE_KEYFRAME | ICMF_CHOOSE_PREVIEW, &bih, NULL, &cvar, (LPSTR)fname))
env->ThrowError("TWriteAvi: ICCompressorChoose failed!");
}
else
{
if(!ICCompressorChoose(NULL, ICMF_CHOOSE_DATARATE | ICMF_CHOOSE_KEYFRAME | ICMF_CHOOSE_PREVIEW,
&bih, NULL, &cvar, (LPSTR)fname)) env->ThrowError("TWriteAvi: ICCompressorChoose failed!");
}

to something like this

// select compressor and fill COMPVARS cvar info
cvar.cbSize = sizeof(COMPVARS);
if (_userFourCC)
{
cvar.fccHandler = *(DWORD*)_userFourCC;
}
else if (showAll)
{
if(!ICCompressorChoose(NULL, ICMF_CHOOSE_ALLCOMPRESSORS | ICMF_CHOOSE_DATARATE |
ICMF_CHOOSE_KEYFRAME | ICMF_CHOOSE_PREVIEW, &bih, NULL, &cvar, (LPSTR)fname))
env->ThrowError("TWriteAvi: ICCompressorChoose failed!");
}
else
{
if(!ICCompressorChoose(NULL, ICMF_CHOOSE_DATARATE | ICMF_CHOOSE_KEYFRAME | ICMF_CHOOSE_PREVIEW,
&bih, NULL, &cvar, (LPSTR)fname)) env->ThrowError("TWriteAvi: ICCompressorChoose failed!");
}

Any idea if this would work? Anyone want to try and compile this? I found this code in avs2avi... looks like we might need it.
http://www.avs2avi.org/

void ChooseOneCompressorOnFourCC(const char* FourCC, COMPVARS *cvar)
{
ZeroMemory(cvar, sizeof(COMPVARS));
cvar->cbSize = sizeof(COMPVARS);
cvar->dwFlags = ICMF_COMPVARS_VALID;
cvar->fccType = ICTYPE_VIDEO;
if (stricmp(FourCC, "null") == 0) {
// No Recompression
cvar->fccHandler = FCC_NULL;
cvar->hic = NULL;
}
else {
cvar->fccHandler = *(DWORD*)FourCC;
cvar->hic = ICOpen(cvar->fccType, cvar->fccHandler, ICMODE_COMPRESS);
if(cvar->hic == NULL) {
ShowErrorAndExit("There is no codec with FourCC \"%s\"!", FourCC);
}
}
cvar->lKey = 15;
cvar->lQ = ICQUALITY_DEFAULT;
}

squid_80
6th December 2007, 06:54
The avs2avi code is nearly perfect, except it sets lKey to 15 for some odd reason. Better to set it to 0 to let the codec decide. MSDN is typically vague when if you look up the COMPVARS structure; it says the lpbiOut member must be filled out, but setting it to NULL is acceptable.
Code would need to be added to make sure the codec returned by ICOpen actually accepts the input format (bih). This could be done with a call to ICCompressQuery.

If nobody else is up to it, I'll be able to do these changes in a few hours time.

LigH
6th December 2007, 10:25
katjarella reported in the german board (http://forum.gleitz.info/showthread.php?t=36249):

She gets a temporary result which is 2 frames longer than the original.
__

P.S.:

Also she reports that AVS2AVI reliably crashes when she uses an AviSynth script as source which only contains

AviSource("lossless.avi")

so she can only use VirtualDubMod (and the joblist) to automate 2 passes.

mikeytown2
6th December 2007, 13:05
@LigH: Thanks for the info! AVS2AVI has given me problems as well, but mainly when i use SoundOut(output="AC3"...). As for the issues, what codec is being used, and what are the codec settings? AviSynth version?

Using the google language translator i was able to understand
http://translate.google.com/translate?u=http%3A%2F%2Fforum.gleitz.info%2Fshowthread.php%3Ft%3D36249&langpair=de%7Cen&hl=en&ie=UTF-8
I wonder if this AVS2AVI bug has anything to do with the color space of the video? What if they pass the video as a clip variable using
AVISource("S01E00.avs").TWriteAvi("TempLossless.avi",overwrite=true,showAll=true)

Also does the error still show up if you put TWriteAvi at the end of S01E00.avs? If S01E00.avs uses DirectShowSource(), this could be causing the problem.


@squid_80: I've never made an AviSynth dll, so if you have some spare time, and you're up to the challenge, go for it!


@Moderator: I'm not sure, but this thread is starting to look like it might need to go into one of the Avisynth ones.

katjarella
6th December 2007, 13:41
@mikeytown2
AVISynth Version: 2.57, Build:Dec 31 2006 [13:16:28]

Sorry not 2 frames longer, 1 frames longer.

source.avs: BlankClip(width=512,height=368,fps=25,length=800,pixel_type="YUY2")
ShowFrameNumber(x=40,y=40,size=32)


source_P1.avs: LoadPlugin("***path***\TWriteAvi\TWriteAvi.dll")
AVISource("source.avs",false).TWriteAvi("TempLossless.avi",overwrite=true,showAll=true)


VDubJop: VirtualDub.Open("source_P1.avs","",0);
VirtualDub.RemoveInputStreams();
VirtualDub.video.DeleteComments(1);
VirtualDub.video.AdjustChapters(1);
VirtualDub.video.SetDepth(24,24);
VirtualDub.video.SetMode(1);
VirtualDub.video.SetFrameRate(0,1);
VirtualDub.video.SetIVTC(0,0,-1,0);
VirtualDub.video.SetCompression(0x75796668,0,10000,0);
VirtualDub.video.filters.Clear();
VirtualDub.SaveAVI("final.avi");
VirtualDub.Close();

Codec Settings is HFYU or Lagarith

The source.avs has 0-799 == 800Frames OK
The source_P1.avs has 0-799 == 800Frames OK
The source_P1.avs has 0-799 == 800Frames OK
The final.avi has 0-799 == 800Frames OK
The TempLossless.avi has 0-799,0 == 801Frames Fail

LigH
6th December 2007, 13:59
"0-799,0" reads like the first frame is added again while "rewinding" the video?
__

P.S.: Instead of AviSource("*.avs"), may Import("*.avs") work too? Of course, respecting the possible side effects.

squid_80
6th December 2007, 14:34
I think one of the modifications I made to twriteavi was to make sure each frame of the original video is only written out to the avi once. Otherwise it writes a frame every time the host app pulls one from the script, which is probably what is happening here.
There's also the issue of frames being pulled out of order, I made the idxname option for that to be used with stickboy's remapframes when loading the temp avi back in.

(see this thread (http://forum.doom9.org/showthread.php?t=121869) or direct download (http://members.optusnet.com.au/squid_80/twriteavi.zip). This isn't the new "auto fourcc" version, just the original one modified slightly.)

squid_80
6th December 2007, 18:26
OK I've made some changes: http://members.optusnet.com.au/squid_80/twriteavi.zip

- New parameter called fourcc, to specify a codec without user intervention
- Moved the index file creation so it's not created if compression can't be started
- Once all frames have been written out, close the avi file and index. This stops programs which re-open the script before they close it from complaining (I'm talking about you, virtualdub). Only works if all frames have been processed!

Here's the script I'm using:# loadplugin("blah\blah\blah\twriteavi.dll")
# loadplugin("blah\blah\blah\remapframes.dll")

function CachedFile(clip c, string filename, string "_fourcc") {
_fourcc = default(_fourcc, "")
s = (exist(filename) ? ChkLosslessFile(c, filename): NOP())
IsClip(s) ? s \
: twriteavi(c, filename, overwrite=true, idxname=filename+".idx", fourcc=_fourcc)
}

function ChkLosslessFile(clip c, string filename) {
LossLessFile = avisource(filename)
c.framecount == LossLessFile.framecount ? LossLessFile.RemapFrames(filename+".idx") \
: NOP()
}

### START OF MAIN SCRIPT

avisource("fixed.avi")
trim(0, -2000)

### END OF MAIN SCRIPT

CachedFile("test.avi", "hfyu") #huffyuv

katjarella
6th December 2007, 21:37
@mikeytown2 and squid_80
My first tests, function wonderful (inc Batch). BIG Thanks.

avs2avi source_TMP.avs final.avi -P 2 -p 0 -w -l DIVX2P.cfg

AVS2AVI v1.40 (c) 2002-2006:
Christophe Paris, David Leatherdale, int21h, Moitah
Modified by Argos, http://www.sasteam66.org/
http://www.avs2avi.org/

Source:
* Filename: "***\TWriteAvi\source_TMP.avs"
* FourCC: YUY2
* Frames: 2000
* Resolution: 512x368
* Frame rate: 25.000 FPS
Compressor:
* Name: DivX« 6.8 Codec (2 Logical CPUs)
* FourCC: divx
Destination:
* Filename: "***\TWriteAvi\final.avi"
* Pass 1/2: Finished in 00:04:07.589 (8.08 FPS)
* Pass 2/2: Finished in 00:01:20.385 (24.88 FPS)
* Frames: 2000 (49 keyframes)
* Size: 11.49 MB

mikeytown2
6th December 2007, 23:50
Sweet!!! Thanks squid_80, your script and dll work great! Also thanks to everyone else for their time and effort!

remapframes
http://avisynth.org/stickboy/

Redid my AutoIt post. Made it into a very simple batch encoder
http://www.autoitscript.com/forum/index.php?showtopic=58691&view=findpost&p=444330

squid_80
7th December 2007, 10:17
Hmm I left something very minor out of my script...
function ChkLosslessFile(clip c, string filename) {
LossLessFile = avisource(filename)
c.framecount == LossLessFile.framecount ? LossLessFile.RemapFrames(filename+".idx").audiodubex(c) \
: NOP()
}

EasyStart
8th December 2007, 05:36
I don't know what I've done wrong. Dowloaded mikeytown2's hc_batch.exe and squid_80's script. When I try to run HC to do a 2 pass encoding job from hc_batch.exe, my second pass is only 2 seonds faster than the first pass. My pc is an overclocked Core2Quad Q6600 with 2gb ram running win xp pro.

Easystart

mikeytown2
8th December 2007, 06:29
I don't know what I've done wrong. Dowloaded mikeytown2's hc_batch.exe and squid_80's script. When I try to run HC to do a 2 pass encoding job from hc_batch.exe, my second pass is only 2 seonds faster than the first pass. My pc is an overclocked Core2Quad Q6600 with 2gb ram running win xp pro.
How slow is it on the first pass? This is only useful for VERY slow avs scrips. In HCgui, under the settings 3 tab, "Reload Aviscript" has to be checked, then save HC.ini. Or if you edit HC.ini this line should be in there
*AVSRELOAD

My hc_batch.exe is just a very simple batch program because i was fed up with
http://forum.videohelp.com/topic337887.html
http://www.twilite.nl/hceasy/
I wanted a very very simple program. hc_batch.exe is not required at all in order to get a 2 pass speed boost.

EasyStart
9th December 2007, 23:18
Thanks mikeytown2. My second pass now runs a lot faster. I am using hc_batch.exe to load HC. If I execute hc directly, it will not encode. HC throughs an error.

Easystart.

mikeytown2
10th April 2008, 04:04
Updated hc_batch.exe
http://img255.imageshack.us/img255/968/screenshotto9.th.png (http://img255.imageshack.us/my.php?image=screenshotto9.png)
Get it here
http://www.autoitscript.com/forum/index.php?showtopic=58691&st=0&p=503684&#entry503684

Made on top an option
Destination Folder Can Now Be set
Slight Change of code for add files button

@Immersion ur using xp?

45tripp
10th April 2008, 04:24
didn't know there was a thread here,
wasn't going to join another forum just to mention a few things :)

yes i'm using xp sp2

that was quick
it all works fine now as far as i can see.


thanks

halsboss
27th April 2008, 15:57
Here's the script I'm using: <snip>

Thanks for the method and DLL ! I'm quite confused :confused: about applying the method to my script (outlined below) and wonder if you can help.

In particular, I'm wondering why the code between "### START" and "### END" won't get processed in the 2nd pass ?

# http://forum.doom9.org/showthread.php?p=1073371#post1073371
# http://forum.doom9.org/showthread.php?p=1073868#post1073868
# in HC, *AVSRELOAD must be in the .ini so as to force "Reload Aviscript"
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\twriteavi.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\remapframes.dll")
# other LoadPlugin's loaded prior to this code ...

function TwoPassProcessCachedFile(clip c, string filename, string "_fourcc") {
_fourcc = default(_fourcc, "hfyu")
s = (exist(filename) ? TwoPassCheckLosslessFile(c, filename) : NOP())
IsClip(s) ? s : twriteavi(c, filename, overwrite=true, idxname=filename+".idx", fourcc=_fourcc)
}
function TwoPassCheckLosslessFile(clip c, string filename) {
LossLessFile = avisource(filename)
c.framecount == LossLessFile.framecount ? LossLessFile.RemapFrames(filename+".idx") : NOP()
}
### START OF MAIN SCRIPT
MPEG2Source("G:\HDTV\q1-HD.d2v",cpu=6) # cpu=6: DEBLOCK_Y_H, DEBLOCK_Y_V, DEBLOCK_C_H, DEBLOCK_C_V, DERING_Y, DERING_C
AssumeFPS(25)
AssumeTFF() ### THIS IS VERY IMPORTANT TO SET CORRECTLY
FRAMERATE=25
WIDTH=704
HEIGHT=576
LastW=LAST.width()
LastH=LAST.height()
# 1080i -> 576i, achieves about 3-4 fps, so not doing 2 passes would be nice
bicubicresize(704,LastH)
tdeint(mode=1,order=1) # mode=0=same rate output mode=1=double rate output (bobbing) order=0=BFF order=1=TFF
bicubicresize(704,576)
separatefields()
selectevery(4,0,3)
weave()
Converttoyv12(interlaced=true)
### END OF MAIN SCRIPT
TwoPassProcessCachedFile("D:\HDTV\q1-HD-2pass.AVI","hfyu") #huffyuv
SetPlanarLegacyAlignment(True)
:thanks:

halsboss
27th April 2008, 16:10
Well, tried it out and it threw error
Evaluate System exception - Access Violation
Any ideas on what to fix ?

Edit: Opening the .avs in Vdub reports that the error occurs in this line
IsClip(s) ? s : twriteavi(c, filename, overwrite=true, idxname=filename+".idx", fourcc=_fourcc) which was downloaded from http://members.optusnet.com.au/squid_80/twriteavi.zip per a post above

Actual code:
SetMemoryMax(512)
LoadPlugin("C:\SOFTWARE\DGindex\DGDecode.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\TDeint.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\EEDI2.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\Yadifmod.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\NNEDI.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\DePan.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\AGC.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\Cnr2.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\dctfilter.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\fft3dfilter.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\degrainmedian.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\Convolution3d.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\despot.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\WarpSharp.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\aWarpSharp.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\mvtools.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\Unfilter.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\AddgrainC.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\hqdn3d.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\mt_masktools.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\RemoveGrainSSE2.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\RepairSSE2.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\RemoveDirtSSE2.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\twriteavi.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins-dcw\remapframes.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins2.0\LoadPluginEx.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins2.0\DustV5.dll")
Import("C:\Program Files\AviSynth 2.5\LimitedSharpenFaster.avsi")
Import("C:\Program Files\AviSynth 2.5\dcwresize.avsi")
Import("C:\Program Files\AviSynth 2.5\Deblock_QED_MT2.avs")
#
function TwoPassProcessCachedFile(clip c, string filename, string "_fourcc") {
_fourcc = default(_fourcc, "hfyu")
s = (exist(filename) ? TwoPassCheckLosslessFile(c, filename) : NOP())
IsClip(s) ? s : twriteavi(c, filename, overwrite=true, idxname=filename+".idx", fourcc=_fourcc)
}
function TwoPassCheckLosslessFile(clip c, string filename) {
LossLessFile = avisource(filename)
c.framecount == LossLessFile.framecount ? LossLessFile.RemapFrames(filename+".idx") : NOP()
## c.framecount == LossLessFile.framecount ? LossLessFile.RemapFrames(filename+".idx").audiodubex(c) : NOP()
}
#
MPEG2Source("G:\HDTV\q1-HD.d2v",cpu=6) # cpu=6: DEBLOCK_Y_H, DEBLOCK_Y_V, DEBLOCK_C_H, DEBLOCK_C_V, DERING_Y, DERING_C
AssumeFPS(25)
AssumeTFF() ### THIS IS VERY IMPORTANT TO SET CORRECTLY
TRIM(0,-50)
FRAMERATE=25
WIDTH=704
HEIGHT=576
LastW=LAST.width()
LastH=LAST.height()
bicubicresize(704,LastH)
tdeint(mode=1,order=1) # mode=0=same rate output mode=1=double rate output (bobbing) order=0=BFF order=1=TFF
bicubicresize(704,576)
separatefields()
selectevery(4,0,3)
weave()
Converttoyv12(interlaced=true)
TwoPassProcessCachedFile("D:\HDTV\q1-HD-2pass.AVI","hfyu") #huffyuv
SetPlanarLegacyAlignment(True)

squid_80
27th April 2008, 16:19
It's hard to explain in writing without being able to point... but start from the bottom of the script and work backwards.
Basically TwoPassProcessCachedFile checks if the cache file already exists, and uses it as the source if it has the expected number of frames.
To put it slightly different: in the second pass TwoPassProcessCachedFile acts like a "source" filter, while in the first pass it works like a simple passthrough filter.

squid_80
27th April 2008, 16:43
You'll probably need to simplify it to work out what's wrong. It could be a problem with huffyuv (is it installed/working correctly?) or maybe a problem with the output file (insufficient space, read-only destination drive/directory). Check to see if the output file exists and if it does, delete it.
Then get rid of all those other plugins/scripts because you're not using anything besides dgdecode, tdeint, twriteavi and remapframes.

halsboss
27th April 2008, 17:05
OK. Thanks. Yes disk writeable, plenty of disk space etc. Used the same script opened in Vdub only with the #TwoPassProcessCachedFile commented out and it works saving huffy to a file in the same place OK. Will tinker removing stuff and see how it goes, like you say.

On the "how it works" query - so the last line opens the .AVI if it exists and uses that as LAST... and I guess does that mean that since it's the last line in the code AVIsynth works backward and detects the rest of the code isn't used or affects that last "LAST" so it ignores the code from the top mpeg2source downwards ?

squid_80
27th April 2008, 17:25
Avisynth always works backwards. Think of the filters being chained together (i.e. imagine a physical chain between them). When a frame is pulled from a script it's like pulling on the chain of the very last filter. If that filter requires a frame from another filter, it pulls that filter's chain. In the second pass, TwoPassProcessCachedFile doesn't pull any frames from the earlier filters but takes them from the cache file instead. The earlier filters aren't completely ignored, the framecount must match for the cached file to be used (also width and height in my version here, since I had problems with that).

halsboss
28th April 2008, 06:17
Avisynth always works backwards. Think of the filters being chained together (i.e. imagine a physical chain between them). When a frame is pulled from a script it's like pulling on the chain of the very last filter. If that filter requires a frame from another filter, it pulls that filter's chain. In the second pass ...The earlier filters aren't completely ignored, the framecount must match for the cached file to be used.

Ah, that makes sense. :thanks:

Now all I have to do is diagnose why I get the access violation :)

halsboss
28th April 2008, 15:53
Seem to have located the error causing "Evaluate System exception - Access Violation"...

Per the script I posted above http://forum.doom9.org/showthread.php?p=1129515#post1129515
If the colourspace is set to something not expected by Huffy, say YV12 by a "Converttoyv12(interlaced=true)" just before the call to "TwoPassProcessCachedFile" ... a crash occurs.

If I convert to YUY2 before (for huffy to work with) and then after (for HC to work with), like this
ConvertToYUY2(interlaced=true)
TwoPassProcessCachedFile("D:\HDTV\test\TEST-100-frames.avi-2pass.AVI","hfyu") #huffyuv
Converttoyv12(interlaced=true)
then the error goes away.

OK, given my incoming clip is from HDTV/DGIndex/MPEG2Source and I guess it to be YV12, what comparable-to-Huffy lossless (but nicely compressing and speedy) codec should I use instead of Huffy for the TFF interlaced YV12 clip, so as to avoid outgoing and incoming colourspace conversions to/from the temporary file ?

:thanks:

Boulder
4th May 2008, 14:39
This might be a dumb question, but why not use the lossless file option included in HC022.1?

mikeytown2
4th May 2008, 20:16
This might be a dumb question, but why not use the lossless file option included in HC022.1?

Look at the date's posted in the HC forum.
http://forum.doom9.org/showthread.php?p=1072001#post1072001
http://forum.doom9.org/showthread.php?p=1101661#post1101661
The response I got was to not have it be part of HC, so i made my own program. Squid_80 then made the changes to twriteavi and wrote the final script. Hank incorporated that option after we made it possible. He doesn't use what we did AFAIK, but once hank saw the benefit he programed it in to HC.

Boulder
4th May 2008, 20:21
Actually I was answering to halsboss, he was looking for a solution to his problem with the method. (Yes, I should have quoted a part of his text :) )

halsboss
7th May 2008, 15:54
Oh, Thanks Boulder ! Didn't realize it existed, so will have to check that out immediately.

Bitburners appears to be only hosting 22.0 ? Is this the link ? http://forum.doom9.org/showthread.php?p=1101978#post1101978 And is the frame mismatch thingy better now ?

Boulder
7th May 2008, 17:20
Yes, that is the latest version at the moment. The mismatches do not occur when using the lossless file mode.