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 > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 22nd November 2007, 00:38   #1  |  Link
dum
Registered User
 
Join Date: Nov 2007
Posts: 27
Implement not filter, but function

Guys, tell me please, is it possible (using C++) implement not filter, but just a function, which will return not a clip, but something different: string or integer?

If it is - please tell me how: just point me, how to approach this.
dum is offline   Reply With Quote
Old 22nd November 2007, 04:25   #2  |  Link
foxyshadis
Angel of Night
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Tangled in the silks
Posts: 9,559
Return an AVSValue from the constructor instead of a PClip. A lot of conditional filters are like that, or you can look at, say, the filters in script.cpp in the avisynth source.
foxyshadis is offline   Reply With Quote
Old 22nd November 2007, 06:00   #3  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
there is no plugin example. So, dum, please tell to us when you finish
Fizick is offline   Reply With Quote
Old 23rd November 2007, 03:43   #4  |  Link
dum
Registered User
 
Join Date: Nov 2007
Posts: 27
Quote:
Originally Posted by foxyshadis View Post
Return an AVSValue from the constructor instead of a PClip. A lot of conditional filters are like that, or you can look at, say, the filters in script.cpp in the avisynth source.
What dp ypu mean as "return from the constructor"? I do not have a lot of variants, what yo return Or you mean creation function like
Code:
AVSValue __cdecl Create_Filter(AVSValue args, void* user_data, IScriptEnvironment* env)
? Where to return then?

And how "script.cpp" can help me? Can you, please, show the exact place to me?

Thank you beforehand.
dum is offline   Reply With Quote
Old 23rd November 2007, 06:35   #5  |  Link
foxyshadis
Angel of Night
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Tangled in the silks
Posts: 9,559
Here's a sample from script.cpp, edited for external use:
Code:
AVSValue Sin(AVSValue args, void* user_data, IScriptEnvironment* env) { return sin(args[0].AsFloat()); }

extern "C" __declspec(dllexport) const char* __stdcall
AvisynthPluginInit2(IScriptEnvironment* env) {
    env->AddFunction("sin", "f", Sin, 0);
    return "sin";
}
You don't even need a class/constructor, come to think of it. Include avisynth.h and that could be a whole plugin right there. (If not a terribly useful one.)
foxyshadis is offline   Reply With Quote
Old 23rd November 2007, 16:11   #6  |  Link
dum
Registered User
 
Join Date: Nov 2007
Posts: 27
Thank you.

And for each instance of AviSynth each own instance of plugin will be loaded?
The reason of this question is following - if I have to return string I need to allocate it somewhere else, except the local variable. Now I'm acting like this:

char p[200];

AVSValue Filter(AVSValue args, void* user_data, IScriptEnvironment* env)
{
...
strcpy(p,...);
return p;
}

What will be the most correct solution of such problem, which will keep me away from all probles with multiple instances etc?
dum is offline   Reply With Quote
Old 23rd November 2007, 17:09   #7  |  Link
dum
Registered User
 
Join Date: Nov 2007
Posts: 27
I'm sorry: and there is completely no documentation (I mean, full description or something) for developers, except some commented samples?
dum is offline   Reply With Quote
Old 23rd November 2007, 18:48   #8  |  Link
tsp
Registered User
 
tsp's Avatar
 
Join Date: Aug 2004
Location: Denmark
Posts: 807
http://avisynth.org/mediawiki/Filter_SDK
__________________
Get my avisynth filters @ http://www.avisynth.org/tsp/
tsp is offline   Reply With Quote
Old 23rd November 2007, 19:31   #9  |  Link
dum
Registered User
 
Join Date: Nov 2007
Posts: 27
Thanks, I got, concerning strings, but, nevertheless is it true that for each instance of AviSynth each own instance of plugin will be loaded? So can I leave data in the variable and rely that it will save it till next call?
dum is offline   Reply With Quote
Old 23rd November 2007, 22:24   #10  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,167
Code:
return env->SaveString(p);
See also Start->Programs->"Avisynth 2.5"->"FilterSDK Information" (it's an optional install with Avisynth).
IanB is offline   Reply With Quote
Old 25th November 2007, 04:57   #11  |  Link
stickboy
AviSynth Enthusiast
 
Join Date: Jul 2002
Location: California, U.S.
Posts: 1,267
http://forum.doom9.org/showthread.php?t=130383

Anyway, a number of my plug-ins have functions that don't return clips, so you can use them as examples.
stickboy is offline   Reply With Quote
Old 25th November 2007, 12:22   #12  |  Link
Fizick
AviSynth plugger
 
Fizick's Avatar
 
Join Date: Nov 2003
Location: Russia
Posts: 2,183
to FilterSDK

I made several attempts to write non-clip plugin function without success. So, I created tutorial how to write non-clip function and placed it to FilterSDK.
http://avisynth.org/mediawiki/Filter...on-clip_sample

He who can, does. He who cannot, teaches.
George Bernard Shaw, Man and Superman (1903) "Maxims for Revolutionists" http://www.quotationspage.com/quote/290.html
Fizick is offline   Reply With Quote
Old 24th July 2015, 16:58   #13  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,496
An 8 year bump, but this seemed to be the most appropriate place to ask.

The example given in this thread is of a plugin that returns a float value, although the actual return type of the function is declared as AVSValue. Does this mean, then, that any variable declared in an AviSynth script is, fundamentally, an AVSValue?

Is there any way with env->AddFunction to create a function that takes an AVSValue (regardless of whether it may really be a string, int, float, or clip) as an input parameter? I can think of scenarios where this would be useful.

Secondly, is a string stored as an AVSValue a null-terminated one?
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 24th July 2015, 19:51   #14  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by davidhorman View Post
Does this mean, then, that any variable declared in an AviSynth script is, fundamentally, an AVSValue?
Yes, that's right.

Quote:
Is there any way with env->AddFunction to create a function that takes an AVSValue (regardless of whether it may really be a string, int, float, or clip) as an input parameter?
Use "." as the parameter character (instead of "s", "i", "f" or "c").
It will then accept an AVSValue of any underlying type.

Quote:
is a string stored as an AVSValue a null-terminated one?
A string passed as a parameter from a script is an AVSValue.
Use AsString() to get a pointer to the contained null-terminated string.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 24th July 2015, 22:15   #15  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,496
Thanks Gavino!

Quote:
Originally Posted by Gavino View Post
A string passed as a parameter from a script is an AVSValue.
Use AsString() to get a pointer to the contained null-terminated string.
What I meant was, could I make an AVSValue out of a non-null-terminated string (like, I think, a C++ String, as opposed to a C string?) - my plan is to pass arbitrary data around as AVSValue strings, but I'd need to be able to create strings which include 0 bytes.

For example, say I have a pointer (void*) to a block of data (could be floats, ints, anything - my code will know what to do with it later), and I know the number of bytes. Can I turn that into a single AVSValue that can be returned by a plugin function and assigned to an in-script variable, either as a string (in which case I'd still need to get it back as a block of data plus number of bytes later) or in some other fashion?
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 25th July 2015, 00:04   #16  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
In principle, you could get away with it by passing your void* pointer to the AVSValue(const char*) constructor.
But things would go horribly wrong if anything in the script tried to treat the thing as a string, as it would be expecting it to be null-terminated.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 25th July 2015, 00:22   #17  |  Link
TheFluff
Excessively jovial fellow
 
Join Date: Jun 2004
Location: rude
Posts: 1,100
Quote:
Originally Posted by davidhorman View Post
What I meant was, could I make an AVSValue out of a non-null-terminated string (like, I think, a C++ String, as opposed to a C string?) - my plan is to pass arbitrary data around as AVSValue strings, but I'd need to be able to create strings which include 0 bytes.

For example, say I have a pointer (void*) to a block of data (could be floats, ints, anything - my code will know what to do with it later), and I know the number of bytes. Can I turn that into a single AVSValue that can be returned by a plugin function and assigned to an in-script variable, either as a string (in which case I'd still need to get it back as a block of data plus number of bytes later) or in some other fashion?
just do what everyone else does and treat NewVideoFrame as if it was malloc and put your arbitrary data there

or don't, and use a frameserver that actually supports passing arbitrary data around instead of insisting on using a tool that makes every problem look like a nail
TheFluff is offline   Reply With Quote
Old 25th July 2015, 14:51   #18  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
David, some RT funcs where using video frame as storage (as suggested by TheFluff above).

Code:
*****************************************************
******************* WEIRD FUNCTIONS *****************
*****************************************************

RT_FloatAsRGBA(float)
 Given a float arg, returns an int formatted as for use as a color to eg BlankClip.
 Can later be recovered from that clip using RT_RGB32AsFloat().

***
***
***

RT_RGB32AsFloat(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0)
 Compile/Runtime clip function.
 Given an RGB32 clip that had a pixel value created via RT_FloatAsRGBA(), gets that pixel and returns as the
 original float given to RT_FloatAsRGBA. By creating single pixel clips and stacking them horizontally/vertically,
 you can use a frame as a two dimensional array of float, perhaps use the frame number for a third dimension.

***
***
***

RT_RGB32AsInt(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0)
 Compile/Runtime clip function.
 Given an RGB32 clip that had a pixel value created from an Int, gets that pixel and returns as the
 original Int. By creating single pixel clips and stacking them horizontally/vertically,
 you can use a frame as a two dimensional array of Int, perhaps use the frame number for a third dimension.
Rip out from source if of use.

Alternatively, you could perhaps use RT array (or DBase) for storage, it has type BIN (8 bit unsigned char [EDIT: returned as int 0-255]) and array size
can be up to about 2GB single dimension array of BIN.
Or, write your own file based data storage that could be accessed via self written run time funcs and also much faster for use in some kind of
frame processing CPP func.

EDIT: You would want some kind of header to ID as your own format BIN data, and offset via header size to access BIN data.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 25th July 2015 at 18:32.
StainlessS is offline   Reply With Quote
Old 25th July 2015, 23:17   #19  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,496
Thanks StainlessS.

Actually I am currently using clips as storage (with header IDs ) but I find it a little unsatisfactory as it seems unnecessarily abstract and open to accidental corruption.

I will experiment with AVSValues (which will give me their own headaches, I'm sure) with Gavino's information and see what can be achieved.
__________________
My AviSynth filters / I'm the Doctor

Last edited by wonkey_monkey; 25th July 2015 at 23:21.
wonkey_monkey is offline   Reply With Quote
Old 26th July 2015, 17:43   #20  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
See also here (two page thread):- http://forum.doom9.org/showthread.ph...ta+AddFunction
(EDIT: mainly 2nd page)

I've never actually used user_data for anything, could be used to allocate mem before AddFunction and pass as arg a pointer to your memblock,
would need to use the Avisynth AtExit function to release mem when Avisynth closes down.

Here the AddFunction used to add script function to Avisynth, user_data in blue:
Code:
 env->AddFunction("RT_TimerHP","",RT_TimerHP, 0);
Code:
AVSValue __cdecl RT_TimerHP(AVSValue args, void* user_data, IScriptEnvironment* env) {
    return RT_TimerHP_Lo();                                                  // Implicit type conversion to AVSValue float
}
Some links:
user_data
http://forum.doom9.org/showthread.ph...ta+AddFunction

AtExit
http://avisynth.nl/index.php/Filter_SDK/Non-clip_sample

I am yet to see any good example that uses user_data, if you do choose to try out then post as would be fairly unique example for others and wiki.

#############

env->SaveString:- http://avisynth.nl/index.php/Filter_SDK/Env_SaveString

is written somewhere (in docs) that memory returned as string from plugin could be used by coder as general storage so long as
you do not overrun allocated size, so could eg assign buffer to static pointer, and use other functions to access same pointer to
edit/return contents, a bit dodgy looking but would work.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 26th July 2015 at 17:52.
StainlessS is offline   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 02:47.


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