Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
13th June 2021, 03:16 | #1 | Link |
Soul Architect
Join Date: Apr 2014
Posts: 2,559
|
Writing Common Avisynth/VapourSynth Code
I'm taking a quick look at converting Avisynth code to VapourSynth. As I'm looking at the code structure, I want to have a Common folder with the shared code, and wrapper/registration code for Avisynth and VapourSynth.
At first glance, Init, GetFrame and Free functions must be rewritten for each platform. OK. Perhaps most complex code inside can be shared. A deeper problem: IScriptEnvironment is used everywhere. How can shared code be written without relying on IScriptEnvironment? I'm looking at standard functions I had imported for custom needs, merge_plane relies on env to get CPU flags. MergeChroma::GetFrame uses "env" everywhere, hard to re-use the code without entirely duplicating it. Do I have to copy/rewrite most of the code, or what's the strategies to share code? ... Creating a IScriptEnvironment wrapper could be an option. But then would also have to create a wrapper for PVideoFrame. And what's the equivalent of env->GetCPUFlags in VapourSynth?
__________________
FrameRateConverter | AvisynthShader | AvsFilterNet | Natural Grounding Player with Yin Media Encoder, 432hz Player, Powerliminals Player and Audio Video Muxer Last edited by MysteryX; 13th June 2021 at 04:42. |
13th June 2021, 04:53 | #2 | Link |
Registered User
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,587
|
see if this help you https://github.com/HomeOfAviSynthPlu...lude/dualsynth
__________________
See My Avisynth Stuff |
13th June 2021, 05:44 | #3 | Link | |||
Soul Architect
Join Date: Apr 2014
Posts: 2,559
|
Interesting approach. Another approach I'm exploring right now is to write common code against a base abstract class.
IVideoFrame.h Quote:
Quote:
Quote:
__________________
FrameRateConverter | AvisynthShader | AvsFilterNet | Natural Grounding Player with Yin Media Encoder, 432hz Player, Powerliminals Player and Audio Video Muxer Last edited by MysteryX; 13th June 2021 at 06:18. |
|||
13th June 2021, 06:36 | #4 | Link |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
the structure of a vaporsynth filter is very simple. you can register any callable object as a vaporsynth plugin function
Code:
PluginInstantiator::RegisterFunction("ShowMessage(msg: string?)", [](auto Arguments, auto Core) { if (Arguments["msg"].Exists()) Core.Print(static_cast<std::string>(Arguments["msg"])); else Core.Print("hello world"); }); then in python core.???.ShowMessage('the eagle has landed') #prints the eagle has landed core.???.ShowMessage() #prints hello world Code:
PluginInstantiator::RegisterFilter<FilterType>(); as you can see there isn't much bureaucratic boilerplate code needed to define the skeleton of a filter, you can simply define a separate function which does the actual work, and call that function in your filter skeleton. the function can be shared by both avisynth and vaporsynth Last edited by feisty2; 13th June 2021 at 06:50. |
13th June 2021, 07:19 | #5 | Link | |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
Quote:
|
|
13th June 2021, 14:33 | #6 | Link | |
Soul Architect
Join Date: Apr 2014
Posts: 2,559
|
Quote:
|
|
13th June 2021, 15:43 | #7 | Link |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
if you're not in a rush to write new plugins, support for the latest version of MSVC should be soon available, there's only one C++20 core language feature (requires expressions) that MSVC currently lacks. I'll add support for MSVC asap when it fills in the final missing piece of C++20.
field is simply a macro that makes indentation prettier in a struct, it declares a field (a non-static data member) with a default initialization, the exact definition is here |
13th June 2021, 23:58 | #8 | Link | |
Soul Architect
Join Date: Apr 2014
Posts: 2,559
|
I managed to trim down a simple filter class Avisynth-only code to this
Quote:
Thus, I'm creating ICommonEnvironment, ICommonVideo and ICommonFrame, with Avisynth and VapourSynth derived implementations. ContinuousMaskCommon has no reference to either Avisynth nor VapourSynth. |
|
15th June 2021, 04:04 | #9 | Link |
Soul Architect
Join Date: Apr 2014
Posts: 2,559
|
Using my approach is working pretty well so far. Rewrote several Avisynth plugins where most of the code has no reference to Avisynth at all.
Up until I try to re-use the base class in VapourSynth. VapourSynth doesn't initialize classes, but rather calls static classes and stores everything in "void* instanceData" feisty, how did you get it to work with classes? ... or maybe create the class, send the pointers to its functions, and store the class pointer itself in instanceData? Ugly, but I guess that could work actually... |
15th June 2021, 10:48 | #10 | Link |
I'm Siri
Join Date: Oct 2012
Location: void
Posts: 2,633
|
I strongly dislike java style OOP (inheritance, hard coded interface, etc.) and I don't use "class" or "design patterns" or whatsoever to reason with the complexity of the program. I am more of a functional programmer (minus the hostility towards side effects) and I program at a rather "meta" level, I create types, then I write metaprograms that directly manipulate C++'s type system to reflect type morphisms.
a base class is generally a very bad idea because it "pollutes" any type inheriting it, and makes it harder to reason with type relationships. like the problem you mentioned above, a type cannot be constructed because a dependency of its base class cannot be satisfied, even if that dependency may be useless to the type itself. the correct way to implement subtype polymorphism is thru the use of an existential type |
15th June 2021, 19:50 | #11 | Link | |
Soul Architect
Join Date: Apr 2014
Posts: 2,559
|
When it comes to writing cross-platform code, are there differences in the in-memory data representation between VapourSynth and Avisynth?
Doc about BytesPerSample says: Quote:
|
|
Thread Tools | Search this Thread |
Display Modes | |
|
|