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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 11th February 2024, 14:17   #1  |  Link
eac3to_mod
Guest
 
Posts: n/a
How to invoke() an external filter?

Can someone please explain how to invoke() an external filter? All the examples I have seen for invoke() are for internal filters. Also, I need this for the version 3 plugin API. A code snippet would be greatly appreciated. Thank you.

Last edited by eac3to_mod; 11th February 2024 at 14:55.
  Reply With Quote
Old 11th February 2024, 14:55   #2  |  Link
WolframRhodium
Registered User
 
Join Date: Jan 2016
Posts: 162
"Reverse URL" refers to the first argument you passed to "configFunc", which is an unique ID for each plugin (generally a DLL).

Code:
void filterCreate(...) {
  // first calls getPluginByID / getPluginByNS to query the plugin instance  
  auto plugin = vsapi->getPluginById(...);

  // creates a new map
  auto args = vsapi->createMap(...);

  // and sets arguments to external function
  auto clip = vsapi->propGetNode(in, ...);
  vsapi->propSetNode(args, "clip", clip, ...);

  // other arguments
  // vsapi->propSetInt(args, "radius", 0, ...);

  // invoke the external function
  // in case functions are calling functions in the same plugin, you don't even need to use the "reverse url":
  // https://github.com/WolframRhodium/VapourSynth-BM3DCUDA/blob/8ab2b6f64cbafc7151f5271e00d1c70c8fa71070/source/source.cpp#L945
  auto ret = vsapi->invoke(plugin, "function_name", args);

  // vsapi->getError(ret);

  // get the return value
  auto ret_clip = vsapi->propGetNode(ret, "clip", ...);

  // set as return value
  vsapi->propSetNode(out, "clip", ret_clip, ...);
}
Some error checking and object destructions are omitted.

Last edited by WolframRhodium; 11th February 2024 at 15:10.
WolframRhodium is offline   Reply With Quote
Old 11th February 2024, 15:32   #3  |  Link
eac3to_mod
Guest
 
Posts: n/a
Thank you, sir, I will try it straight away.
  Reply With Quote
Old 11th February 2024, 15:53   #4  |  Link
eac3to_mod
Guest
 
Posts: n/a
This is what I have so far. It compiles and runs but doesn't invoke the filter.

Code:
...
vsapi->createFilter(in, out, "DGSource", VSVideoSource::Init, VSVideoSource::GetFrame, VSVideoSource::Free, fmUnordered, nfMakeLinear, vs, core);

auto plugin = vsapi->getPluginById("com.vapoursynth.dgdecodenv", core);
auto args = vsapi->createMap();
auto clip = vsapi->propGetNode(out, "clip", 0, NULL);
vsapi->propSetNode(args, "clip", clip, paReplace);
auto ret = vsapi->invoke(plugin, "Filter", args);
auto ret_clip = vsapi->propGetNode(args, "clip", 0, NULL);
vsapi->propSetNode(out, "clip", ret_clip, paReplace);
Note that I don't need any arguments to the filter.

Does Vapoursynth insert a cache between them?

Last edited by eac3to_mod; 11th February 2024 at 17:30.
  Reply With Quote
Old 11th February 2024, 17:11   #5  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,556
Quote:
Originally Posted by eac3to_mod View Post
It's crashing at the first propGetNode(). This is what I have so far:

Code:
...
vsapi->createFilter(in, out, "DGSource", VSVideoSource::Init, VSVideoSource::GetFrame, VSVideoSource::Free, fmUnordered, nfMakeLinear, vs, core);

auto plugin = vsapi->getPluginById("com.vapoursynth.dgdecodenv", core);
auto args = vsapi->createMap();
auto clip = vsapi->propGetNode(in, "clip", 0, NULL); // crashes here
vsapi->propSetNode(args, "clip", clip, paReplace);
auto ret = vsapi->invoke(plugin, "Filter", args);
auto ret_clip = vsapi->propGetNode(ret, "clip", 0, NULL);
vsapi->propSetNode(out, "clip", ret_clip, paReplace);
I just guessed on what to put where you showed ... What am I doing wrong please? I don't need any arguments to the filter.

Does Vapoursynth insert a cache between them?
Code:
auto clip = vsapi->propGetNode(in, "clip", 0, NULL); // crashes here <= in should probably be out here
If the out map already contains what you need (a single clip I guess?) you can pass it directly instead of copying to a new map.

Caches are automatically inserted between filters if running under API4. You can manually add the Cache filter (no op in API4 since it does things differently) if you really need a cache when running under API3 as well.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is online now   Reply With Quote
Old 11th February 2024, 18:40   #6  |  Link
eac3to_mod
Guest
 
Posts: n/a
Thank you. I had already changed the in to out and it runs but the filter does not get invoked. Please see the revised code in my first post. After the invoke is working I'll worry about the cache. I'm with API 3. I need a cache because Filter is a temporal filter talking to a source filter that doesn't want to receive out of order requests.

Feel free to just give me the code as I'm a stooge when it comes to Vapoursynth maps and nodes and all that. All of that is not explained anywhere that I can find. So I'm just groping around not knowing the underlying reasons for things. So I'd really appreciate some help. Thank you.

Last edited by eac3to_mod; 11th February 2024 at 19:17.
  Reply With Quote
Old 11th February 2024, 20:31   #7  |  Link
Myrsloik
Professional Code Monkey
 
Myrsloik's Avatar
 
Join Date: Jun 2003
Location: Kinnarps Chair
Posts: 2,556
Call getError() on the map returned from vsapi->invoke(). It should give you a proper error message if anything went wrong.
__________________
VapourSynth - proving that scripting languages and video processing isn't dead yet
Myrsloik is online now   Reply With Quote
Old 11th February 2024, 23:26   #8  |  Link
eac3to_mod
Guest
 
Posts: n/a
Thank you, that's got me moving again.
  Reply With Quote
Old 12th February 2024, 06:51   #9  |  Link
HolyWu
Registered User
 
Join Date: Aug 2006
Location: Taiwan
Posts: 392
Quote:
Originally Posted by eac3to_mod View Post
This is what I have so far. It compiles and runs but doesn't invoke the filter.

Code:
...
vsapi->createFilter(in, out, "DGSource", VSVideoSource::Init, VSVideoSource::GetFrame, VSVideoSource::Free, fmUnordered, nfMakeLinear, vs, core);

auto plugin = vsapi->getPluginById("com.vapoursynth.dgdecodenv", core);
auto args = vsapi->createMap();
auto clip = vsapi->propGetNode(out, "clip", 0, NULL);
vsapi->propSetNode(args, "clip", clip, paReplace);
auto ret = vsapi->invoke(plugin, "Filter", args);
auto ret_clip = vsapi->propGetNode(args, "clip", 0, NULL);
vsapi->propSetNode(out, "clip", ret_clip, paReplace);
Note that I don't need any arguments to the filter.
Code:
auto ret_clip = vsapi->propGetNode(ret, "clip", 0, NULL);
HolyWu is offline   Reply With Quote
Old 12th February 2024, 14:22   #10  |  Link
eac3to_mod
Guest
 
Posts: n/a
Thank you, sir.
  Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 20:50.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.