View Full Version : Detection of new format
jpsdr
11th August 2016, 10:33
I want to make something working in "all" avisynth version.
By all i mean 2.6.x and almost all avs+ version (at least the r1858).
I know how to detect some kind of things, but i don't know how to detect if new formats (short, float) are implemented.
How can i detect if ComponentSize exist in avs+ ?
I don't want to call it on a avs+ version where it doesn't exist.
Chikuzen
11th August 2016, 11:37
How can i detect if ComponentSize exist in avs+ ?
I don't want to call it on a avs+ version where it doesn't exist.
Currently, vi.BytesFromPixels(1) returns the bytes of first plane's sample of all planar formats.
If a format is 16bit, it will return 2. If a format is float, it will return 4.
pinterf used this method before vi.ComponentSize() was added.
and there are some methods like this (http://forum.doom9.org/showpost.php?p=1773745&postcount=2092).
Groucho2004
11th August 2016, 11:58
How can i detect if ComponentSize exist in avs+ ?
VideoInfo::ComponentSize() will return 0 if it cannot detect the color format (CS_UNKNOWN) which should be equivalent to the function not being supported by Avisynth.
jpsdr
11th August 2016, 14:37
So, if vi.BytesFromPixels(0) return 4, and i'm not in RGB32, it means i'm with floats...
For now, i don't see any case where vi.BytesFromPixels(0) can return 2 and not being 16bit.
This can do... I will be a little tricky, but it can do...
Didn't see properly the other method, i think it will work with all avisynth version without issue also.
If you look at previous avisynth.h, VideoInfo::ComponentSize() just doesn't exist. So, i can't safely use it if it doesn't exist in the avisynth version running... (At least, i think, it will only crash, no ??).
Thanks guys for these tips.
Chikuzen
11th August 2016, 15:21
So, if vi.BytesFromPixels(0) return 4, and i'm not in RGB32, it means i'm with floats...
no.
vi.BytesFromPixels(1)
Groucho2004
11th August 2016, 15:47
If you look at previous avisynth.h, VideoInfo::ComponentSize() just doesn't exist. So, i can't safely use it if it doesn't exist in the avisynth version running... (At least, i think, it will only crash, no ??).
Huh? Of course you have to use the AVS+ header, otherwise it won't compile. And as I mentioned, if an Avisynth version is loaded that does not support the function, it will return 0.
Chikuzen
11th August 2016, 17:28
Huh? Of course you have to use the AVS+ header, otherwise it won't compile. And as I mentioned, if an Avisynth version is loaded that does not support the function, it will return 0.
avs2.6's struct VideoInfo does not have ComponentSize().
How avs2.6 return 0 without access violation?
Groucho2004
11th August 2016, 17:46
avs2.6's struct VideoInfo does not have ComponentSize().
How avs2.6 return 0 without access violation?
It just does. It doesn't even throw an exception.
Groucho2004
12th August 2016, 08:10
I want to make something working in "all" avisynth version.
By all i mean 2.6.x and almost all avs+ version (at least the r1858).
I know how to detect some kind of things, but i don't know how to detect if new formats (short, float) are implemented.
How can i detect if ComponentSize exist in avs+ ?
I don't want to call it on a avs+ version where it doesn't exist.
The way I determine the capabilities of the loaded Avisynth is rather simple. First, here is a list of internal functions in AVS+ but not in classic Avisynth:
AddAutoloadDir
AutoloadPlugins
ClearAutoloadDirs
ConvertTo16bit
ConvertTo8bit
ConvertToFloat
ConvertToY
ConvertToYUV420
ConvertToYUV422
ConvertToYUV444
InternalFunctionExists
LogMsg
Prefetch
SetFilterMTMode
SetLogParams
With "env->FunctionExists("FunctionName")" I can determine for example:
- Any of the above functions indicate AVS+
- "Prefetch" indicates a AVS+ version >= r1689 with MT support
- "ConvertTo16bit", "ConvertToFloat" indicate AVS+ 16/32 Bit support
There may be more reliable methods I have not thought of but I think the "FunctionExists" method is pretty solid.
jpsdr
12th August 2016, 08:54
Ok, thanks.
ultim
13th August 2016, 16:07
avs2.6's struct VideoInfo does not have ComponentSize().
How avs2.6 return 0 without access violation?
Due to some trickery inside the AVS_LinkCall() macro. Whenever you call a function in VideoInfo, a small stub is compiled into your code before the core's version is invoked. This stub notes the offset of the function to be called compile-time, and if it is greater than the size of the whole struct at run-time, returns 0 without actually making the call.
One of the creative coding techniques introduced for Avs 2.6 to keep compatibility with Avs 2.5.
Chikuzen
13th August 2016, 16:53
ah
# define AVS_LinkCall(arg) !AVS_linkage || offsetof(AVS_Linkage, arg) >= AVS_linkage->Size ? 0 : (this->*(AVS_linkage->arg))
I overlooked this line.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.