View Full Version : Plugin toaccess multiple clips and frame varying parameters
vcmohan
14th October 2003, 05:18
I am trying to make a plugin for Avisynth which can be used for various effects including transitions. I need to access multiple clips.In the filter sdk I do not find info on how to access multiple clips. For eg. vi-> and child-> are used in the sdk. These have to be different incase of multiple clips. Will it be permissible to use clip.child-> and clip.vi-> ?
I also need to use some internally included filters but with parameters varying for each frame including resizing. Animate filter expressly prohibits using varying size.How to call these with frame as input and other parameters? still keep env, vi of original unaffected? The header files of these internal filters specify clip and not frame.
Since I am new I think that using internal functions will be faster with optimized code rather than me writing anew such code.
Si
14th October 2003, 07:12
SimpleSample 1.7 (http://forum.doom9.org/showthread.php?s=&postid=364467#post364467) shows how to access 2 clips
regards
Simon
Shubin
14th October 2003, 10:53
I have a transition plugin under construction and almost
complete now. I found out that I can just use "clip"
parameter as any "normal" parameter - assigned to PClip member
variable. So far transitions are circle : one clip is inside the circle, one is outside and line : one clip to the left, other
one to the right.
What transitions are you planning ?
tempetai
14th October 2003, 11:19
How about explode...
Shubin
14th October 2003, 12:10
Originally posted by tempetai
How about explode...
Describe it please : what's explode ?
sh0dan
14th October 2003, 12:42
Shubin: Nice examples here (http://www.cordin.com/images.html). Ok - I'll shut up now. ;)
sh0dan
14th October 2003, 13:07
Actually I won't. Anyway - regarding calling internal filters you need to look at "env->Invoke()".
Invoke will return an AVSValue with the clip resulting from the filter you pass to it. See EnvInvoke (http://www.avisynth.org/index.php?page=EnvInvoke) at avisynth.org.
An example (grabbed from MipSmooth - it uses invoke a lot):
AVSValue args[1] = { child };
PClip reduced = env->Invoke("Reduceby2",AVSValue(args,1)).AsClip();
This piece of code calls "ReduceBy2(child)", and places the result in "reduced". If you need the videoinfo (for whatever reason), you can get by requesting: VideoInfo reduced_vi = reduced->GetVideoInfo();
Another example (using a resizer) upsizerString="LanczosResize";
AVSValue up_args[3] = { child, 384, 288 };
PClip resized = env->Invoke(upsizerString, AVSValue(up_args,3)).AsClip();
In general, avoid invoking "Invoke" as much as possible. If it can be avoided, try not to do it every frame, but do it in the constructor, if the filter parameters doesn't change. Invoking on every frame usually brings down the speed of the filter to a fraction of a static filter, at it has to be created and destroyed every frame.
Edit: Just added this info to EnvInvoke.
Si
14th October 2003, 19:25
In general, avoid invoking "Invoke" as much as possible
Why is that?
regards
Simon
Bidoche
14th October 2003, 21:13
Because it costs.
Si
15th October 2003, 00:28
Well, that's clarified the situation :rolleyes: :)
I'd previously thought that a lot of Avisynth internal filters called other ones (to save duplicating code) as part of the C++ philosophy :confused:
regards
Simon
tempetai
15th October 2003, 03:29
sh0dan,
Need your help. How can I re-used the Dissolve::GetAudio function in my plugin? Basically, I wanted to work on two difference clips and have the audio of the first clip fade out, while the audio from the second clip fade-in on the overlapping frame as what Dissolve does. Instead of re-invent the wheel, I'm wondering whether I can call the existing function.
vcmohan
15th October 2003, 04:11
Originally posted by Shubin
What transitions are you planning ?
Thanks to all for the interest and helpful suggestions and material.
I am also planning a circle, rectangle as transitions. But include rotation, zoom, and flips.
The explode will be toomuch of a coding but a variant can be generated with circular or rectangular transitions.
Bidoche
15th October 2003, 11:09
@siwalters
They do call others filters, but not with Invoke, they use new Filter directly, which saves the linking step, AVSValue manipulation...
@tempetai
Invoke Dissolve with the proper parameters (you may want to generate appropriate dummy video) and only use the sound.
tempetai
15th October 2003, 11:27
Originally posted by Bidoche
@tempetai
Invoke Dissolve with the proper parameters (you may want to generate appropriate dummy video) and only use the sound.
Bidoche, thanks.
I'm going to try it tonight. Actually, each clip has video and audio on it. I wanted to use dissolve for the audio only, while I have something in mind for the overlapping videos.
sh0dan
15th October 2003, 20:50
Originally posted by siwalters
Why is that?
regards
Simon
Because there is much overhead in creating a few filter every frame. Every time you call filter = env->Invoke("SomeFilter",..).AsClip(); the following happends. (filter is a PClip)
- If filter is already a PClip, the old filter is destroyed by calling ~SomeFilter().
- Look up the proper function in the defined functions.
- Check parameters.
- Call the Creator defined in the env->AddFunction().
- Create the filter. This usually also checks parameters and creates tables, but this depends on the filter
- The returned PClip is returned as an AVSValue.
- Your filter recieves it.
You can compare the speed by timing:
SomeFilter()
and
Scripclip("SomeFilter()")
... the latter will always be much slower, because it is created and destroyed each frame. That's why:
ConditionalFilter(last, last, Somefilter(last), "Something", ">", "SomethingElse")
is also much faster than:
ScriptClip(last,"(Something > Somethingelse) ? last : Somefilter() ")
...since the former only creates SomeFilter() when the script is passed, and not at each frame.
WarpEnterprises
15th October 2003, 23:11
while you are in "comment mode/mood", could you describe how the variables (global, non-global) fit into this picture?
I still don't get that "from end to start" thing and where and when the variables are actually stored.
E.g. why there is a offset by one call if I use ScriptClip twice (the second subtitle shows the result of the first only at the next GetFrame
Version()
scriptclip("a=current_frame" + chr(13) + "subtitle(string(a)+string(b))")
scriptclip("b=current_frame" + chr(13) + "subtitle(string(a)+string(b),100)")
[edit]
Would something like an Object Model be helpful and feasible for AviSynth? I will try to make a sketch on the WiKi
vcmohan
16th October 2003, 03:43
[QUOTE]Originally posted by siwalters
SimpleSample 1.7[/URL] shows how to access 2 clips
QUOTE]
I have gone through this Simple Sample 1.7. Still I have some doubts. vi has been used without first defining it. As vi can be different for the two clips should not we call vi1=child1->GetVideoInf() and vi2 = child2->GetVideoInf() and then check if both vi have similar info eg pixel type, color space, etc? Or does Avisynth prechecks whenever multiple clips are called? In my attempt I intend to use clips which may have differing width and heights.
WarpEnterprises
16th October 2003, 08:19
"vi" and "child" are defined in the GenericVideoFilter class, so whenever you use that class vi is already defined.
from avisynth.h:
// instantiable null filter
class GenericVideoFilter : public IClip {
protected:
PClip child;
VideoInfo vi;
...
Si
16th October 2003, 10:33
@vcmohan
AFAIK plain "vi" refers to the main clip and your idea of using vi2 = child2->GetVideoInf() should let you access any sub clips (assuming your syntax is right - never tried it myself :) )
SimpleSamples are VERY simple :o
If your idea works then let me know and I'll produce V1.8 :)
@sh0dan
Miscomunication error - I thought you were saying not to use Invoke at all. :o - thanks for the clarification.
regards
Simon
Bidoche
16th October 2003, 12:35
@vcmohan
VideoInfo has a default constructor, so it don't need to be explicitly defined, it is default constructed.
should not we call vi1=child1->GetVideoInf() and vi2 = child2->GetVideoInf() and then check if both vi have similar info eg pixel type, color space, etc? Yes, you should.
vcmohan
17th October 2003, 03:57
Originally posted by sh0dan
Because there is much overhead in creating a few filter every frame.
If I understand correctly the implications, then using Animate(.FILTER..) will be much slower than changing the parameters in every frame within the FILTER itself, by initially reading the end and from values and deriving parameters for each frame. I thought I could leave it to Animate filter.
I also went through the Resizer, resampler, old version in C++ but could not fathom what really was happening. For instance what are the Pattern_chroma and Pattern_luma values for a simple linear resampling(reduction in size?). And how they are used?
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.