View Full Version : Using OpenGL in an Avisynth plugin - how?
wonkey_monkey
15th March 2025, 20:59
I've written some code to use OpenGL Compute shaders which works fine by itself, but now I'm trying to put it in an Avisynth plugin, and it's not playing nice with GUIs.
My filter's constructor creates an instance of a separate class I've made like this:
remapper = new TPSRemapperGL(vi, resampler);
OutputDebugString("Created"); // for debugging
env->ThrowError("zzz"); // for debugging
and the TPSRemapperGL class does this:
OutputDebugString("A");
if (!glfwInit()) throw std::runtime_error("Failed to initialize GLFW");
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
window = glfwCreateWindow(100, 100, "", nullptr, nullptr);
return;
if (!window) {
throw std::runtime_error("Failed to create GLFW window");
glfwTerminate();
}
OutputDebugString("B");
return;
When I process the script with AVSMeter, I see all the debug strings in DebugView++, and I see the thrown error ("zzz") written to the console, which is what I'd expect.
But when I try to open my script with VirtualDub2, instead of popping up the error, it crashes with an out-of-bounds memory access. When I try in my own wxWidgets GUI, it just silently closes, but not without writing a few of the following to debug output:
'GetWindowRect' failed with error 0x00000578 (Invalid window handle.)
AvsPmod is the only one that opens it, showing the "zzz" exception as red text in a black clip.
My only guess is that there is something to do with my DLL opening a window which causes the host application to freak out. Is there some way - cross-platform, preferably, not that I'm going to try to testing this in Linux - to open the window but keep it completely hidden from the host application?
DTL
15th March 2025, 21:49
May be system can not create any windows from window-less process (threads) ? If it will be possible - we can have some windows-filter with finally warnings and lot of other usefull logs data output. At least in Windows builds of AVS. But no one exist because no windows creation possible ? And if you try to init something with window from a plugin it finally fail because Windows OS can not create a window (why ?).
To use opengl compute may be you need to find some way to operate data without any windows creation (even 'virtual' ?). At least DirectX interfaces to DX12 for DirectCompute (in Win10 and later) can work from AVS plugin to use hardware accelerator services - see how DX12-ME feature implemented in the MAnalyse in mvtools2. But they do now attempt to create any windows - everything is started via creation of software 'DirectX device'. And using an interfaces from it.
Init of DX12 from AVS plugin is srtating from https://github.com/DTL2020/mvtools/blob/9eedb9d0850f638fc43212fb515cf048f9b9a58f/Sources/MVAnalyse.cpp#L1704
wonkey_monkey
15th March 2025, 22:06
May be system can not create any windows from window-less process (threads) ? If it will be possible
I think it's definitely possible, and in fact it seems to work fine in AvsPmod either because it gets Avisynth to handle its own exceptions or because the way it's coded allows it to ignore the hidden window. VirtualDub also seems to open the file okay if I take out my deliberate exceptions, but of course the fact that exceptions cause a crash instead of being reported is not great. My wxWidgets app still crashes though.
StainlessS
16th March 2025, 12:43
AutoOverlay has some kind of window thingy (EDITOR window), but requires .NET stuff [dont know if required for the window].
There is at least one other avs dll that shows a window, but cant for the life of me remember what it is/was, from long ago.
Maybe an audio plugin.
[EDIT: Some kind of 'monitor' window, to monitor progress/goodness of the dll functionality.]
[EDIT: maybe a tritical plug {tritical = Tom Barry, I think, maybe}]
Maybe somebody else remembers it.
EDIT: AutoOverlay: auto-alignment and color matching:- https://forum.doom9.org/showthread.php?t=175247
EDIT: New version of AutoOverlay posted today in above linked thread.
EDIT: Tritical stuff. [Link UPDATED to a later archive]
https://web.archive.org/web/20151125175557/http://bengal.missouri.edu/~kes25c/
TMonitor - 11/16/2005 v0.9.4 (Released)
TMonitor is a filter very similar to AVSMon. It enables monitoring of an Avisynth clip via previewing the video, viewing clip information (such as video width, height, colorspace, number of frames, audio samples, sample rate, number of audio channels, and more), and adjusting the audio delay. It also supports multiple instances per script, allowing viewing of differences between different parts of a processing chain.
EDIT: Another from the Tritical link.
TUnsharp - 05/24/2005 v0.9.3 (Released)
TUnsharp is a basic sharpening filter that uses a couple different variations of unsharpmasking and allows for controlled sharpening based on edge magnitude and min/max neighborhood value clipping. It also supports the XSharpen sharpening method. The real reason for its existence is that it sports a gui with real time updating preview.
Tritical TMonitor available with source from above linked tritical page on Archive.org.
AvsMon seems to no longer be available.
Tried to find "AviSynth Filter Collection – Warpenterprises", but no longer on-line, and link on Avisynth.nl main page points to 404 page.
EDIT: AvsMon seems only to have been released as dll (so far as I can find,and all those links broken).
Here Tritical thread: Proof of Concept Filter and a Couple Questions
where he muses about GUI based on avsMon idea.
https://forum.doom9.org/showthread.php?p=564215
EDIT: tritical archive page updated to (I think) latest version.
Screenshot for TMonitor
https://i.postimg.cc/tspZM5nT/tmon1.png (https://postimg.cc/tspZM5nT)
another one
https://i.postimg.cc/yDLdrzzQ/tmon2.png (https://postimg.cc/yDLdrzzQ)
Wilbert
16th March 2025, 20:42
Tried to find "AviSynth Filter Collection – Warpenterprises", but no longer on-line, and link on Avisynth.nl main page points to 404 page.
EDIT: AvsMon seems only to have been released as dll (so far as I can find,and all those links broken).
I restored the link in the wiki. Note that the 2.5 filenames are messed up. Use
http://www.avisynth.nl/users/warpenterprises/files/avsmon25a_5F25_dll_20030125.zip
instead of
http://www.avisynth.nl/users/warpenterprises/files/avsmon25a_25_dll_20030125.zip
When i have time i will fix the links. The source of avsmon25a should be there.
StainlessS
16th March 2025, 20:46
Thanks Wilbert, have downed the "avsmon25a_5F25_dll_20030125.zip" file ok.
EDIT: Renamed to "avsmon25a_25_dll_20030125.zip"
wonkey_monkey
17th March 2025, 00:39
With some help from Reddit, the solution is to spawn a separate worker/listener thread which keeps all the OpenGL stuff to itself. That way nothing clashes with the host application.
Stay tuned for many WonkeyGL shenanigans.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.