View Full Version : Loading AVS Scripts in .NET
MysteryX
18th June 2020, 01:21
Has anyone written a .NET library to load AVS scripts? If not, any pointer as to what needs to be done?
I wrote such an API for VapourSynth; might as well support both at the same time if it's not too hard in the VapourSynth Multi-Viewer.
stax76
18th June 2020, 02:08
There is the VFW/avifile API, used by staxrip until 6 months ago, now staxrip accesses avisynth and vapoursynth via C++ wrapper, megui uses a C wrapper. The advantage of the staxrip wrapper is that it also supports vapoursynth with the same COM based interface.
I think nobody has tried using avisynth directly from .NET, avisynth generally has a C API and a couple of tools are using the C API, I think ffmpeg and x264 for instance, most tools use the C++ API.
real.finder
18th June 2020, 02:12
what about this https://forum.doom9.org/showthread.php?t=173640 ?
stax76
18th June 2020, 02:24
what about this https://forum.doom9.org/showthread.php?t=173640 ?
It uses the megui wrapper written in C/C++.
MysteryX
18th June 2020, 03:23
For VapourSynth, I'm doing direct P/Invoke into the DLL and it's working just fine.
So... which of these approaches would you recommend? Where can I see the staxrip wrapper
Ah. Com-based interface, so you get a common interface to handle both and use COM library instead of P/Invokes. Sounds like a better idea.
stax76
18th June 2020, 10:49
For VapourSynth, I'm doing direct P/Invoke into the DLL and it's working just fine.
Yes, I know your work, I looked at it while writing the wrapper. In staxrip there is a similar feature at:
Tools > Advanced > Video Comparison
All drawing in staxrip happens using Direct2D, most other .NET tools use GDI based System.Drawing which has horrible performance.
So... which of these approaches would you recommend? Where can I see the staxrip wrapper
So far there were zero issues with the wrapper, the code is relatively simple, especially the vapoursynth and the .NET part.
You can find the wrapper here:
https://github.com/staxrip/staxrip/tree/master/FrameServer
The .NET part is unlike a lot of other old staxrip code mostly properly decoupled.
https://github.com/staxrip/staxrip/blob/master/General/FrameServer.vb
I decided to use COM and C++, I guess you can do pretty much the same in plain C, would have also been a good exercise for me.
For translation from VB to C# I usually use converter.telerik.com or the dotpeek decompiler.
When I wrote the wrapper I didn't know much about the avisynth C interface, otherwise I might have tried a direct approach.
Would be interesting to know if accessing avisynth directly from .NET is possible and what the code would look like. Are you going to try?
MysteryX
18th June 2020, 19:25
Would be interesting to know if accessing avisynth directly from .NET is possible and what the code would look like. Are you going to try?
That was exactly my question. So you're saying.. you don't know?
stax76
18th June 2020, 21:26
I've not tried accessing avisynth directly from .NET and I'm not aware that anybody has ever tried it.
MysteryX
18th June 2020, 21:33
Avisynth works with plain C interface, so I see no reason why it couldn't be easily P/Invoked from .NET.
How do other apps do to execute/render Avisynth scripts? Just need to find the right C API. Should be pretty simple, no?
stax76
18th June 2020, 21:56
Most apps use the C++ interface, for instance using the exception type AvisynthError.
Sources for the C interface:
https://github.com/mirror/x264/blob/master/input/avs.c
https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/avisynth.c
MysteryX
18th June 2020, 22:10
uh doesn't look so simple. Perhaps just because I don't understand it.
It loads the function
AVSC_DECLARE_FUNC( avs_clip_get_error );
Where is avs_clip_get_error variable defined, and where are method parameters defined?
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.