WarpEnterprises
23rd March 2004, 22:21
I still don't understand fully how AviSynth works internally between script parsing and delivering frames. This gets very pronounces when using (or programming) conditional filters (functions that modify variables at runtime and/or call a script in the GetFrame).
So I asked sh0dan a question...and he gave some explanation - which is well suited for the public too BUT was not fully covered IMO.
Q
Why exactly do you temp. save "last" in ScriptClip?
I noticed I have to make the same code in my Write, else there is a heap overflow due to recursive calls, but only when using implicit last. What is different between "last" and an explicit variable?
A
To avoid strangeness. If a filter should request frames when they are constructed, a conditional filter could mess up the implicit last.
--> well, this I understand, I think.
Q
I now found the way to put the codec name and the frametype in AviSource.
As we have no per-frame properties I simply use SetVar in AviSource::GetFrame to return a string "current_frametype" I create there.
So far it works ok, if I use e.g.
AviSource("droppedframes.avi")
ScriptClip(""" subtitle(current_frametype) """)
BUT when I use:
AviSource("droppedframes.avi")
ScriptClip(""" subtitle(" " + current_frametype) """)
the display lags one frame behind. Why that? Why does Subtitle alone work, but if I use ANY function it lags?
A
ok - When the filter runs, this happends:
- ScriptClip gets asked to deliver a frame.
- ScriptClip Evaluates the subtitle string.
- A PClip is returned with the newly created subtitle filter.
*
- Subtitle is asked to deliver a frame.
- AviSource delivers a frame to Subtitle.
- Subtitle returns the frame to ScriptClip after processing.
* This is where the funny stuff happends. Since the subtitle is created before AviSource is called, the variable will not have been updated yet.
It could be changed, by also requesting a frame before evaluating, but it will make inconsistencies, since the filter above will be called twice (give and take a cache hit). But in principle it could make it work.
--> OK, this explains the general "lag" - but why is there no lag when I use a pure Subtitle (inside ScriptClip of course) WITHOUT an extra function?
So I asked sh0dan a question...and he gave some explanation - which is well suited for the public too BUT was not fully covered IMO.
Q
Why exactly do you temp. save "last" in ScriptClip?
I noticed I have to make the same code in my Write, else there is a heap overflow due to recursive calls, but only when using implicit last. What is different between "last" and an explicit variable?
A
To avoid strangeness. If a filter should request frames when they are constructed, a conditional filter could mess up the implicit last.
--> well, this I understand, I think.
Q
I now found the way to put the codec name and the frametype in AviSource.
As we have no per-frame properties I simply use SetVar in AviSource::GetFrame to return a string "current_frametype" I create there.
So far it works ok, if I use e.g.
AviSource("droppedframes.avi")
ScriptClip(""" subtitle(current_frametype) """)
BUT when I use:
AviSource("droppedframes.avi")
ScriptClip(""" subtitle(" " + current_frametype) """)
the display lags one frame behind. Why that? Why does Subtitle alone work, but if I use ANY function it lags?
A
ok - When the filter runs, this happends:
- ScriptClip gets asked to deliver a frame.
- ScriptClip Evaluates the subtitle string.
- A PClip is returned with the newly created subtitle filter.
*
- Subtitle is asked to deliver a frame.
- AviSource delivers a frame to Subtitle.
- Subtitle returns the frame to ScriptClip after processing.
* This is where the funny stuff happends. Since the subtitle is created before AviSource is called, the variable will not have been updated yet.
It could be changed, by also requesting a frame before evaluating, but it will make inconsistencies, since the filter above will be called twice (give and take a cache hit). But in principle it could make it work.
--> OK, this explains the general "lag" - but why is there no lag when I use a pure Subtitle (inside ScriptClip of course) WITHOUT an extra function?