Log in

View Full Version : Question: AVISynth Bug when "chaining" AVS-files ?


Darksoul71
3rd September 2003, 15:37
Hi,

I often use "multiple" (read: mostly two) AVISynth files
refering at each other. Typically I crop, trim and denoise
in the first AVISynth file with my tool VCF2AVS.

Afterwards I resize and add borders in a second file.

My experiences:
Sometimes both VDub and CCE fail to open the second
AVS-file i.e. crashing. If I put all arguments into the first file, everything
works fine. Sometimes opening the second file results in an "all black"-Movie.

Is this problem plug-in related ? Is this an AVISynth bug ?
Has anyone experienced the same problem ?

From my point of view AVISynth should be able to "chain" as much
AVISynth scripts via AVISource as I like. This sometimes helps you
when you code AVISynth GUIs.

-D$

WarpEnterprises
3rd September 2003, 22:40
1) Can you give definite examples?
2) Why don't you use Import() ?

2a) I wonder myself what the differences are or can be between
- putting all in one script
- using Import
- using AviSource("xxxx.avs")

Bidoche, it would be so great if your knowledge could be made browseable :)

Bidoche
3rd September 2003, 23:17
1) Can you give definite examples?That would help :)

I wonder myself what the differences are or can be betweenPutting all in one script and importing should be more or less the same.
The original script is itself parsed by invoking Import.

Using Avisource is different, it will try opening the script using VFW (and cie) where avisynth will kick in again to create another filter chain. (But the dll is not loaded a 2nd time)
Then, since avisynth was not really conceived to render multiple clips at once, problems may occur (multithread issues, bad memory sharing...)

Bidoche, it would be so great if your knowledge could be made browseableYou are welcome to put my answers on the web ;p

stickboy
4th September 2003, 04:21
Originally posted by WarpEnterprises
2a) I wonder myself what the differences are or can be between
- putting all in one script
- using Import
- using AviSource("xxxx.avs")There shouldn't be any difference between all-in-one-script and using Import. Using AviSource, however, would give the scripts different scopes and would prevent namespace collisions.

I would prefer to use AviSource when possible so I could treat other scripts as black boxes.

Darksoul71
4th September 2003, 17:27
Hi,

thanks for all your answers:

@WarpEnterprises:

1) Can you give definite examples?
There you go:
I normally use one script to crop, de-interlace &
fade.

#Script1.avs
#Generated by VCF2AVS
LoadPlugin("C:\Winapp\VCF2AVS\Plugins\Decomb.dll")
AVISource("K:\motu20002.avi")
Trim(673,33657)
FieldDeinterlace(blend=false)
Crop(12,8,696,560)
Reverse.FadeOut(50).Reverse.FadeOut2(50)


Then I use a second script generated by FitDVD for
resizing and letterboxing my video (Normally for Half-D1).

#Script2.avs
#Generated by FitDVD
LoadPlugin("C:\Winapp\FitDVD 1.5\PlugIns\MPEG2DEC.dll")
AVISource("K:\script1.avs")
LanczosResize(336,541)
AddBorders(8,18,8,17)
TemporalSmoother(6,4)


2) Why don't you use Import() ?
Honestly I never thought about Import(). From my
way of thinking I like to treat things as "module"
or blackbox if you like.

I first didnīt add examples because:
1) The results/errors are mostly not reproducable.
If I reboot or re-open the script it mostly works.
Seems to me that the AVISynth.dll sometimes has
"hick-ups" :)
2) Those errors occured with various sources. Iīve
used AVS-file as source generated from GKnot as
well as AVS-files generated by VCF2AVS.

@Bidoche:


Using Avisource is different, it will try opening the script using VFW (and cie) where
avisynth will kick in again to create another filter chain. (But the dll is not loaded a 2nd
time)
Then, since avisynth was not really conceived to render multiple clips at once,
problems may occur (multithread issues, bad memory sharing...)


Now thatīs interesting. That is what Iīve assumed. AVISynth offen shows access violations
when using "chaining". Isnīt there a way to force AVISynth DLL to be loaded
multiple times ? I never experienced problems running two different AVS-files not refering to each other.

Example: Doing a DVD->DivX with GKnot and encoding a AVI via AVISynth using
CCE. Strange.....

IMHO itīs a bug if AVISynth isnīt stable in "multiple clip rendering".

Iīve now changed my utility FitDVD and it now just adds the last few lines
to the source script if the source is an AVS-file. This should "solve" all my problems,
but I still have some bad feeling about this.
Look at AVIUtil or VDub. Youīre able to chain as much as you like.
Honestly Iīve never looked at the source code of AVISynth and have a very deep respect
of all you guys that either do filters or develop directly in the AVISynth DLL, but from my
experiences with DLL programing itīs often possible to do a "thread safe" variant of a DLL.
Example: Create a OOP-based DLL and spawn a new object for every call of the DLL.

May be Shodan can tell us more ?

-D$

Bidoche
4th September 2003, 23:34
The dll is compiled as multithreaded, but AFAIK there isn't a single line of multithread code in it.
This was simply not an issue when designed in 1998 and so was overlooked.

And as forcing multiple loads, it doubt it possible.
Avisynth is a COM server, and it is it who is in charge of loading/unloading it

Example: Create a OOP-based DLL and spawn a new object for every call of the DLL.It is already doing that, but there is static code which is not synchronized (at least the VideoFrame and VideoFrameBuffer recycle bin, maybe more).


When opening an avs, the following happens :
- somehow, it finds in the registry the REF_CID of an IAVIFile COM/VFW object to handle that.
- COM get asked a factory object able of creating one
- if not loaded, avisynth is loaded by COM
- COM gets an IFactory object from the dll
- it uses it to create an IAVIFile object
- cast to it IPersistFile and use the appropriate method to read from disk
- Import gets Invoked on an ISCriptEnvironment member with the script text
- script is parsed... and a filter chain is created
- render done through IAVIFile methods