Log in

View Full Version : Problem opening AVS scripts (2.51) in Delphi


dvd2svcd
19th March 2003, 10:19
Before you all jump on me and tell me that the problem is because I use Delphi6, please read it all.

When I use the VFW unit in Delphi and open an avs (avisynth 2.51) looking like this:
LoadPlugin("C:\tmp\MPEG2Dec3.dll")
mpeg2source("C:\tmp\preview.d2v")
BilinearResize(480,576)
Trim(2,2)
ConvertToRGB()


Everything works fine. But if I open an avs looking like this:
LoadPlugin("C:\tmp\MPEG2Dec3.dll")
mpeg2source("C:\tmp\preview.d2v")
BilinearResize(688,544,2,4,718,568)
AddBorders(16,16,16,16)
Trim(2,2)
ConvertToRGB()


It fails. Now, the really strange part is that if I open the avs script that fails in all other programs (like VirtualDUB and Mediaplayer), there's no problems. I know that this looks like I'm doing something wrong so I've made a simple sample which can be downloaded. As you can see from the source in UNIT1.PAS all that is done between the one that fails and working is switching between the good.avs and bad.avs

When I open the bad.avs the VideoInfo struct tells me that there's 240 frames and the width and height 260*56 which tells me that something went wrong. For you that don't have a delphi compiler, I've included the compiled program too, besides the unit1.pas is so simple that it would take maybe 5 minutes to port it to C++. In the attached avs files I use BlankClip() instead of a vob/d2v file.

http://www.dvd2svcd.org/AVSFails.zip

sh0dan
19th March 2003, 14:10
The error is probably because of a missing emms (because the filter chain crashes). What is the 'i' value that is returned on the good and the bad sample?

dvd2svcd
19th March 2003, 14:32
i is always 0 (no errors). (except where I use it to chec the RefCnt of the avi calls).

"missing emms", what is that and is it something I can fix?

sh0dan
19th March 2003, 15:01
It is used to reset the MMX-state of the processor. EMMS is the instruction used for that. I checked the conversion routines and they all contain the necessary instructions.

I tried ending all calls with an emms instruction, but nothing seems to change. What are the exact values of the psi.dwRate and psi.dwScale? Could you possibly print out the entire psi struct?

But it does seem like the filter ends prematurely.

dvd2svcd
19th March 2003, 15:08
Here are two window dumps of both good and bad:

Good (http://www.dvd2svcd.org/good.avs.jpg)
Bad (http://www.dvd2svcd.org/bad.avs.jpg)

sh0dan
19th March 2003, 15:09
The crash actually occurs in AviSynth.dll

(GetResamplingPatternRGB: (double total3 = total2 + func->f((start_pos+k - pos) * filter_step) / total; if anyone is interested).

I'll investigate further - this is quite strange!!

sh0dan
19th March 2003, 15:13
The crash occurs because the cropping is invalid. The input image is only 640x480. Why it DOESN'T crash in VDub is a mystery yet to be solved.

sh0dan
19th March 2003, 15:20
ok - a fairly wild shot - is it possible that vdub modifies the float precision, or sets a flag for the processor not to throw float div by zero exceptions?

In either case I cannot see why it isn't caught by DelayInit, so an error message can be thrown. Back to the testing board.

dvd2svcd
19th March 2003, 15:21
Well, it fails with an input size of 720*576 the same way. I just used the blankclip() command to avoid any copyright laws (I have a sample here with a vob and d2v that fails using the exact same BilinearResize command but with a 720*576 input size).

Edit: Remember Media player 6.4 also plays the AVS without problems.

sh0dan
19th March 2003, 15:45
Have you tried calling Create or GetInfo before actually requesting the stream? Are have you checked what's returned by GetStream()? This is where I get the actual crash.

Anyway - the problem is as such - it seems like the float unit is left in a non-working stage, and has to be reset - otherwise the first float or mmx instruction will crash it. I'm currently looking for information on how to recover such a situation.

sh0dan
19th March 2003, 15:57
Seems like it IS a mode you can set on the CPU. So basicly, you tell the CPU on which kinds of float point exceptions is should throw an exception. (Getting closer!)

dvd2svcd
19th March 2003, 16:26
Calling GetInfo is the same as when I call AVIStreamInfo. The call to Getstream always returns 0.

sh0dan
19th March 2003, 16:33
Got it!!

Ok - here is the deal. Apparently you can set different flags on the processor to indicate which exceptions should be thrown by the processor. The problem is, that these flags were set differently, when calling from a C-program compared to a Delphi program.

The second problem, after manually forcing the vdub settings to be default, was that the app. STILL got a float point exception. So I found out that the exception registers in the FP unit remains active - so I found out there was an instruction to clear them.

Phew - that was a tricky one!

Just got some things to clean up, then I'll make a CVS release. This will probably also fix many unexplained things!

Edit: Binary up on CVS bin site. Thanks a lot for answering all my questions for squashing this!

dvd2svcd
19th March 2003, 16:47
Glad I could be of some meager help :)