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
Register FAQ Calendar Today's Posts Search

Reply
 
Thread Tools Search this Thread Display Modes
Old 9th February 2024, 03:15   #1  |  Link
eac3to_mod
Guest
 
Posts: n/a
Question on Invoke() from a source filter

I want to have a source filter DGSource() invoke another filter as if it was invoked after DGSource() in the script. I put this at the end of Create_DecodeSource():

Code:
	DGSource* dec = new DGSource(
		(char*)args[0].AsString(""),
[etc.]
		args[25].AsString("pq"),
		args[26].AsInt(0),
		(float)args[27].AsFloat(0.15f),
		(float)args[28].AsFloat(0.0f),
		args[29].AsString("high"),
		NULL, NULL, env);

#if 1
	PClip clip = env->Invoke("Filter", dec).AsClip();
	return clip;
#else
	return dec;
#endif
If the #if is 0 it runs as usual. If the #if is 1 it runs slow and jerkily. I determined that DGSource() is not receiving frame requests in order.

For #if 0 I get the expected sequence of requests to DGSource(): 0,1,2,3,4,5,...

For #if 1 I get the expected sequence of requests to Filter(): 0,1,2,3,4,5,...
but DGSource() is receiving from Filter(): 0,1,0,2,2,1,3,3,2,4,4,3,...

This obviously messes up DGSource(), causing her to repeat frames and go into random access to go backwards.

Filter() is a temporal filter requesting the previous, current, and next frames from Avisynth. I'm sure that is the reason for the behavior. Just wondering if there is any way to mitigate this so DGSource() is happy. If I put Filter() as a standalone filter in the script, rather than invoking it, things are fine. That makes me believe there should be a solution.

Is there a cache between DGSource() and Filter()? Seems to me that if there was this would not happen. I know about SetCacheHints() but don't know whether to put it in DGSource() or Filter(), in both, and how to do it. The documentation I have seen is confusing and I don't even know how valid it all is for the latest Avisynth+.

Hehe, I'm good with filters and not so good with Avisynth internals, so any help to resolve this would be awesomely appreciated. Thank you.

Last edited by eac3to_mod; 9th February 2024 at 04:20.
  Reply With Quote
Old 9th February 2024, 13:09   #2  |  Link
eac3to_mod
Guest
 
Posts: n/a
Found the solution here:

http://avisynth.nl/index.php/Filter_SDK/Env_Invoke
  Reply With Quote
Old 9th February 2024, 13:28   #3  |  Link
eac3to_mod
Guest
 
Posts: n/a
Hmm, this does not work:

Code:
PClip myclip = env->Invoke("Filter", dec).AsClip();
try {
	AVSValue up_args[1] = { myclip };
	myclip = env->Invoke("InternalCache", AVSValue(up_args, 1)).AsClip();
} catch (IScriptEnvironment::NotFound) {
}
return myclip;
Is InternalCache() implemented and working in Avisynth+?
  Reply With Quote
Old 9th February 2024, 13:41   #4  |  Link
eac3to_mod
Guest
 
Posts: n/a
Inserting the cache before the invoked filter works:

Code:
try {
	AVSValue up_args[1] = { dec };
	PClip myclip = env->Invoke("InternalCache", AVSValue(up_args, 1)).AsClip();
	myclip = env->Invoke("Filter", myclip).AsClip();
	return myclip;
} catch (IScriptEnvironment::NotFound) {
}
I would still appreciate confirmation that I am doing this correctly. Thank you.
  Reply With Quote
Old 9th February 2024, 14:12   #5  |  Link
pinterf
Registered User
 
Join Date: Jan 2014
Posts: 2,314
Seems to be good. Example in Avisynth:
https://github.com/AviSynth/AviSynth...bits.cpp#L1320

(Cache and InternalCache are doing the very same thing.)

EDIT:
There was a long discussion - and many days of reverse engineering and debugging on my side - about the topic;
first: why is serious slowdown is experienced (source filter probably re-decodes 0-99 frames again if it gets a request for N-1 (e.g. #98) after having decoded Nth frame (#99)
second: what is the reason of the out-of-seqence requests (because at specific timing conditions consumer process can request some frames sooner than it was requested (and thus put in the cache) by the prefetch mechanism.

Out-of-order requests on source filter heavily degrade performance.
https://forum.doom9.org/showthread.p...63#post1944163
and
https://forum.doom9.org/showthread.p...19#post1944219
and
https://forum.doom9.org/showthread.p...24#post1944724

Last edited by pinterf; 9th February 2024 at 14:31.
pinterf is offline   Reply With Quote
Old 9th February 2024, 16:01   #6  |  Link
eac3to_mod
Guest
 
Posts: n/a
Thank you, sir! I will read your links with great interest.

One more question please. Is it worth setting cache hints for a smaller radius? And how would I do that?

Last edited by eac3to_mod; 9th February 2024 at 18:37.
  Reply With Quote
Old 9th February 2024, 16:27   #7  |  Link
pinterf
Registered User
 
Join Date: Jan 2014
Posts: 2,314
Quote:
Originally Posted by eac3to_mod View Post
Thank you, sir! I will read your links with great interest.

One more question please. Is it worth setting cache hits for a smaller radius? And how would I do that?
Actual cache size is auto-tuned in Avisynth+, but I found this line in the code:
https://github.com/AviSynth/AviSynth.../main.cpp#L718
It might be worth experimenting with.

(However I have at least to two issues to investigate where the cache size is just growing and growing at certain frame access patterns.
https://github.com/AviSynth/AviSynthPlus/issues/379 and #279)
pinterf is offline   Reply With Quote
Old 9th February 2024, 18:23   #8  |  Link
eac3to_mod
Guest
 
Posts: n/a
Thank you sir. I'll leave it to Avisynth+ to figure it out for now.

Last edited by eac3to_mod; 9th February 2024 at 18:37.
  Reply With Quote
Reply


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 05:20.


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