View Full Version : How to disable AviSynth's internal buffering
jollye
14th November 2007, 15:22
Hi all,
I want to try to develop an AviSynth filter that has a GUI. I've looked at some examples. As AviSynth is internally buffering the video I was wondering if it would be possible to force it to flush its internal video cache within the filter's code.
If the answer to my previous question is yes, I would also know if it is possible to force AviSynth to refresh the displayed frame.
This way, the user would be able to change some filters'parameters using the GUI and see the result instantly even if he stopped the video.
Thanks for your answers
Leak
14th November 2007, 18:10
As AviSynth is internally buffering the video I was wondering if it would be possible to force it to flush its internal video cache within the filter's code.
Last time I checked the answer was "no", and even if you manage to flush AviSynth's internal caches there's no way to make the filters further down the road also drop/flush/forget their internal state, which would be needed here...
np: Alter Ego - Jolly Joker (Why Not?!)
tsp
14th November 2007, 20:20
If the answer to my previous question is yes, I would also know if it is possible to force AviSynth to refresh the displayed frame.
No it is the application that loads avisynth.dll that controls this.
This way, the user would be able to change some filters'parameters using the GUI and see the result instantly even if he stopped the video.
The best way to solve it would be to display the output frame from your filter in the GUI in your filter's constructor if you intend to change colorspace/framecount/framesize/fps as this is only "legal" in the constructor else you could put the code inside the GetFrame function.
We might help you more if you could describe what the filter should do and what you want the user to adjust (and why can't he use avsp instead?)
jollye
15th November 2007, 08:44
...if you intend to change colorspace/framecount/framesize/fps as this is only "legal" in the constructor ...
Actually I don't want to change the characteristics of the video but its content. Like for example its brightness.
We might help you more if you could describe what the filter should do and what you want the user to adjust (and why can't he use avsp instead?)
It's more a general question. I would like to know the method if it exists. I can think to a brightness filter for example. The user would use a slider to adjust the brightness like in any graphic editor and would immediately see the effect in VirtualDub even if VirtualDub is stopped (I mean stopped at one image of the video, not closed). About avsp, it's an extra editor that has very nice features but if what I'm asking for exists, it's a different application (according to your answers, it's unfortunately not the case). Any user that has AviSynth installed would be able to adjust the brightness of the video without having to install any extra software and learn how it's working (avsp).
Leak
15th November 2007, 10:14
The user would use a slider to adjust the brightness like in any graphic editor and would immediately see the effect in VirtualDub even if VirtualDub is stopped (I mean stopped at one image of the video, not closed).
Sorry, but no can do - VfW is pull, not push. You won't get an updated image in any program unless said program explicitly (re-)requests a frame; the codec can't notify the program that there's a shiny new updated image waiting for it.
It might be possible in DirectShow (which AviSynth doesn't support), but only if the graph isn't paused (which it most probably is in an editing application), and don't get me started on the general seeking inaccuracies making DirectShow Teh Horror(TM) for frame-exact editing (and thus relatively useless for apps like VirtualDub)...
jollye
15th November 2007, 11:20
OK, thanks for the detailed explanation.
IanB
15th November 2007, 13:34
As Leak and TSP have explained, Avisynth implements a PULL model. This is implemented thru the GetFrame chain created as your script is compiled.
If you wanted to launch a GUI element associated with your filter from the constructor and from it call the GetFrame method of your filter object then I don't see any real problems.
Of course without lots of extra trickery you would only have access to the graph upto your filter i.e. not the complete graph. Also as you are accessing your filter object directly you would not have access to the cache object that follows your filter, so every access would recalculate the result (which is what you wanted). Your filter would have a cache between it and the next filter object in the graph but this would only be a problem if you chain several of these dynamically configurable filters (once you fetch a frame it would become cached at that point in the graph).
jollye
15th November 2007, 14:29
If you wanted to launch a GUI element associated with your filter from the constructor and from it call the GetFrame method of your filter object then I don't see any real problems.
Just to be sure I've understood your answer fully could you confirm that you mean the GUI would be in charge of displaying the video in its own window?
Thanks for answering
IanB
15th November 2007, 23:17
Well yes, your GUI would need to adjust whatever parameters, then do a GetFrame call to your filter and then display the returned frame.
To do the GetFrame call you will need to be a bit naughty and "remember" the original IScriptEnvironment pointer passed in (I normally do not recommend ever saving env). Also you will need to deal with any thread interlocking issues (and any API threading conditions that may be imposed in 2.6+).
The model suggested by TSP where you simply do your GUI during the constructor call, set your parameters, then close the GUI at the end of construction, would have the least problems.
The partial child PClip graph you are suppplied will be fully functional, and you could env->Invoke temporary extra filter objects like ConvertToRGB() and ...Resize() to ease the display processing in your GUI. Just keep the pointers and delete the extra objects when finished.
sh0dan
16th November 2007, 09:00
@jollye: If you do all filter construction inside your own app, there is nothing holding you back from destroying and re-creating parts of the chain.
Or to be more precise, if you use Env->Invoke to create filters and store each PClip you get returned, you can destroy the bottom part of the filter and re-create filters with different parameters.
Take the following chain creation:
PClip source = env->Invoke (avisource or source)
PClip filt1 = env->Invoke (source, converttoyv12)
PClip filt2 = env->Invoke (filt2, coloryuv(gain_y=10)
PClip filt3 = env->Invoke (filt3, converttorgb)
You can of course request frames freely from any parts of the filterchain.
You can also re-create parts, as:
PClip filt2 = env->Invoke (filt2, coloryuv(gain_y=100)
but you must also re-create filt3, even though it hasn't changed (but its input may have). You completely control insertion of caches, since none are inserted in the case above.
squid_80
17th November 2007, 06:30
I'm pretty sure support for using avisynth plugins directly in virtualdub is going to happen in the near future.
jollye
19th November 2007, 11:42
@sh0dan:
My plans are not to do the filter construction inside my app. I will use an avs script and VirtualDub(Mod) for vizualization of the result. I plan to add a GUI in order to adjust the parameters of the last filter of the chain.
@all
Now, I think I have understood how I can do it. I thank you all for your help.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.