View Full Version : AviSynth in DirectShow
If I render an AviSynth script in DirectShow it uses an "Avi/WAV File Source" which I think is un-connected with the AviSynth development ?
So, I'm confused, just where/what is AviSyth ? How does this get rendered to my DirectShow graph ?
The driving reason behind this I was kind of hoping there was a way of determining if the video rendered correctly or, if it failed, pick out the AviSynth-generated error message.
Blindly stumbling around the AviSynth source code I've found CLSID_CAVIFileSynth and IID_IAvisynthClipInfo, and the IAvisynthClipInfo structure has just the function I want - GetError().
However, how do I get this interface ? I've tried quering all the filters on the graph (only cos too lazy to specifically locate the source filter) and even quering the graph itself. Also, trying to add a CLSID_CAVIFileSynth filter to the graph simply fails.
TTFN,
Jon
TheFluff
9th May 2009, 22:24
If you want to use the Avisynth interface, use the Avisynth API, that's what it's there for. If you use DirectShow, you're going to get DirectShow error messages.
The entire point of Avisynth is to make Video for Windows think an .avs is an uncompressed AVI, and that "Avi/WAV source file" filter is (afaik) just a wrapper around the VfW AVI reader. DirectShow doesn't see Avisynth at all, which is the entire point. You can't get there (the Avisynth API) from here (DirectShow).
...I've found CLSID_CAVIFileSynth and IID_IAvisynthClipInfo, and the IAvisynthClipInfo structure
If you want to use the Avisynth interface, use the Avisynth API, that's what it's there for.
Er .. I thought I was trying to !?
If you use DirectShow, you're going to get DirectShow error messages.
Obviously, though there are no DirectShow errors if it is the original script file that contains an error. I want to (programatically) get the AVISynth error message generated when my script contains an error.
DirectShow doesn't see Avisynth at all, which is the entire point.
So, other than looking at the generated video and using OCR (which ‘aint gonna happen!), I can’t programmatically read AviSynth-generated error messages if I use DirectShow. Drats.
Wonder if the AviSynth developers might consider adding e.g. a LogFile(filename) to AviSynth which could capture this and, indeed other internally generated information such as that generated by Version or perhaps even Info(clip). That’d be useful.
TTFN,
Jon
Gavino
10th May 2009, 10:07
Wonder if the AviSynth developers might consider adding e.g. a LogFile(filename) to AviSynth which could capture this and, indeed other internally generated information such as that generated by Version or perhaps even Info(clip).
You can simulate this to some extent by putting your script in a try...catch block and using WriteFileStart, eg
try {
... # main script goes here
}
catch (err) {
BlankClip(...) # WriteFile needs a clip
WriteFileStart("logfile.txt", "VersionString()", "err")
}
(though I guess it won't work if your script contains a syntax error which prevents it even being executed).
TheFluff
10th May 2009, 16:50
Er .. I thought I was trying to!?
No, you're using the DirectShow API. If you want to use the Avisynth API, #include <avisynth.h> and call the functions therein directly. It's a very nice API, certainly a lot easier to use than dshow is, so if you don't absolutely need the dshow part I would really recommend using it instead.
I did look at using the API. However, I hit several issues.
1) Initially wouldn't compile - VS2008 chokes on the overloaded 'new' operator of one of the classes. Temporarilly commented out but longer term don't need a fix for it.
2) Whilst I found a few code snippets on the web, it seems the functions I want may be wrapped inside the "Invoke" function call, and apart from the two code snippets I can't find anything more about it.
3) Presumably, I'd have to buffer the audio and video myself and present them to the hardware all correctly timed. Not my idea of fun. Whereas, in directshow I call "RenderMediaFile" or "RederStream" and its all done for me.
4) Despite being a die-hard C/C++'er, I'm determined to write in .NET, a luxury I can only afford because DirectShowLib on SourceForge has done all the miserable interop stuff for me (_very_ big thanks to those involved!).
But I guess the answer is, well, if I use DirectShow then I don't get access to error messages so I'll have to work around it.
@Gavino : I'm trying to catch errors due to me creating an invalid script file during the development of my application, which is bound to happen since I'm still a relative newbie to AviSynth.
TTFN,
Jon
Gavino
11th May 2009, 09:33
@Gavino : I'm trying to catch errors due to me creating an invalid script file during the development of my application, which is bound to happen since I'm still a relative newbie to AviSynth.
So does my idea help or not?
You could extend it to detect syntax errors too by writing to another file at the start of the script. Your application could then test if this file has been written and know the script is syntactically valid, then check the logfile for any run-time errors.
The 'real' script could be in a separate file and included in this framework by using Import.
It's a bit elaborate but I think it should work.
Ah ha,
Now I've learned to type (that "Begin" on the end of "WriteFileBegin" is a tad important [DOH!]), yes, that exactly fits the bill.:thanks:
And yes, making the error handler a seperate script is a good idea.
If a script "builds" (for the want of a better word) initially, then what kind of errors occur only after running ? (Assuming source video files are undamaged).
TTFN,
Jon
PS: Ok, I give in, how do I generate a newline in the WriteFileBegin output ?
Gavino
11th May 2009, 15:29
If a script "builds" (for the want of a better word) initially, then what kind of errors occur only after running ? (Assuming source video files are undamaged).
Basically, there are three stages to running a script: syntax checking, script interpretation (building the filter graph) and 'run-time' (serving frames to the client application). Semantic errors such as invalid arguments to a filter are detected at the second stage (and caught by any try..catch). A genuine 'run-time' error could occur for a system exception, or some more subtle error in the use of dynamic filters like Animate or ScriptClip. One of the developers could probably be more precise about this.
Ok, I give in, how do I generate a newline in the WriteFileBegin output ?
I assume you mean WriteFileStart.
The easiest way is to use a separate call to WriteFileStart for each line (with append=true), as newlines are inserted automatically that way. But you can also use:
WriteFileStart(..., "chr(13)+chr(10)", ...)
You probably tried something with /n, but that has no special meaning in Avisynth, except as a special case within Subtitle.
Gavino
12th May 2009, 09:53
Previously, I said:
You could extend it to detect syntax errors too by writing to another file at the start of the script. Your application could then test if this file has been written and know the script is syntactically valid, then check the logfile for any run-time errors.
The 'real' script could be in a separate file and included in this framework by using Import.
It occurs to me now that the second part of this makes the first unnecessary!
If your framework script is something like:
try {
Import("realscript.avs")
}
catch (err) {
...
}
then even syntax errors in "realscript.avs" will be caught by the outer part. So it's simpler than I thought. :)
Sweet! Consider your idea well and truely stolen by me:)
TTFN,
Jon
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.