Log in

View Full Version : Clip Properties vs Frame Properties


MysteryX
4th July 2021, 01:17
I want to read a frame property during initialization to determine which filters to invoke in the chain.

I read "_ColorRange", which alter the further calls.


if (Input && !Skip)
{
int RangeMin = (255 - Range) / 2;
int RangeMax = Range + RangeMin;
api->clearMap(Args);
api->propSetNode(Args, "clip", Input, paReplace);
api->propSetFloat(Args, "gamma", 1 / 2.2, paReplace);
api->propSetFloat(Args, "min_in", SrcFullRange ? 0 : 16, paReplace);
api->propSetFloat(Args, "max_in", SrcFullRange ? 255 : 235, paReplace);
api->propSetFloat(Args, "min_out", RangeMin, paReplace);
api->propSetFloat(Args, "max_out", RangeMax, paReplace);
Input = Env.InvokeClip("std", "Levels", Args, Input);
}


I thought that frame properties would show as cliip properties but apparently not (unless I'm missing something). Reading frame properties requires a frame, which I don't have during initialization. So, how do I get _ColorRange during initialization?

Related to the same question -- also how to read it from Python scripts?

I want to ensure "_FieldBased" is not set in the Python script or throw an error. As for "_ColorRange", it could be a good idea to recalculate it for every frame in the case that different frames have it different. Is it possible to change invocation parameters on every frame?

feisty2
4th July 2021, 08:02
you read the property from the first frame.

auto ColorRange = static_cast<int>(Clip[0]["_ColorRange"]); (https://github.com/IFeelBloated/vapoursynth-plusplus/blob/master/include/Node.vxx#L65)

MysteryX
4th July 2021, 08:27
What happens if _ColorRange isn't the same for all frames?

btw you're too smart for me, I don't understand half of the keywords in your code :P Let alone how they fit together.

feisty2
4th July 2021, 09:06
What happens if _ColorRange isn't the same for all frames?

then you cannot handle this kind of situation during initialization. you can, however, assume that all frames have the same _ColorRange and check if that assumption actually holds in the getframe function, and raise a runtime error when the assumption fails to comply with the fact (https://github.com/IFeelBloated/vapoursynth-plusplus/blob/master/Examples/Rec601ToRGB.hxx#L28).

feisty2
4th July 2021, 09:24
btw you're too smart for me, I don't understand half of the keywords in your code :P Let alone how they fit together.

you don't need to know every last C++ feature if you're not a library author. I would however suggest that you take a look at C++ concepts (https://en.cppreference.com/w/cpp/language/constraints) and every usage of "auto" (https://en.cppreference.com/w/cpp/language/auto) if you want to better understand my code.

MysteryX
4th July 2021, 10:35
I suppose in VapourSynth you could take a PC-range clip and merge it with a TV-range clip. Is that supposed to be a supported scenario? I guess most plugins would fail to handle it.

Properties varying per frame are more for things like stats?

ChaosKing
4th July 2021, 10:41
Source filters use frame props to set a interlaced flag. So not just for "stats".

MysteryX
4th July 2021, 20:22
Source filters use frame props to set a interlaced flag. So not just for "stats".
I mean, Interlaced flag is generally fixed throughout the video. Is VapourSynth supposed to support this flag varying from frame to frame? As a plugin developer, should I aim to support that or not?

ChaosKing
4th July 2021, 21:13
I think you should support it ( if the frame prop makes sense). For example ffms2/lsmas also sets the pic_type props (I, P, B frame type). I saw multiple scripts that use that prop to do stuff with it / improve quality etc. The plugin dev just enables possibilities the rest is up to the user.

StainlessS
4th July 2021, 21:27
UK PAL TV [especially from maybe 80's], had portions in both progressive and interlaced.
One example, BBC, [5 or 6 episode] "Private Schulz", progressive Black & White [WW2 sections], and also outdoors sections, indoors Interlaced.

Here a script [does not uses properties] that I posted, and used on that series [originally did singleRate deint, then re-done as doubleRate]:- https://forum.doom9.org/showthread.php?p=1923123#post1923123
EDIT: Also allows for selective SpotLess use, on both Interlaced and Progressive sections.

EDIT: I'm also using same script [with recently added TFM(pp=0)] for Babylon5 [110 eps], @ DoubleRate

AssumeTFF
# Uncomment below if has any Perverse Telecine [eg Babylon5].
TFM(pp=0)
# and a bit of color tweaking, PRE-MC stuff (else VERY SLOW), : Added to linked script
O=Last
AutoAdjust(Auto_Gain=true).Merge(O,0.6) # un-comment if wished

PAL Bab5 has interlaced/Progressive and Perverse Telecine sections [Perverse, not too common, but I process the lot].

EDIT: To below, yes I guess, sort of. :)

ChaosKing
4th July 2021, 21:46
You could say IsCombedTIVTC is just an old school way of using "frame properties".

MysteryX
5th July 2021, 01:42
UK PAL TV [especially from maybe 80's], had portions in both progressive and interlaced.
One example, BBC, [5 or 6 episode] "Private Schulz", progressive Black & White [WW2 sections], and also outdoors sections, indoors Interlaced.
Some video formats even support that?

In that case, I'm invoking Levels before my plugin, how can I make the parameters dynamic?

StainlessS
5th July 2021, 02:07
Some video formats even support that?
Both mentioned sets of clips were DVD VOB.

In that case, I'm invoking Levels before my plugin, how can I make the parameters dynamic?
AutoAdjust aint bad, but really does need the Merge I used to ensure it does not overdo it.

AutoLevels, sometimes better that AutoAdjust, but I guess I botched that a bit, sometimes way overcompensates producing flashes, needs re-think.

EDIT:- I think AutoAdjust uses default temporal radius 20, whereas AutoLevels 7 [might have been 5 originally], I think, probably makes quite a difference.
(Also better scene change detect required in AutoLevels, fires with flickering candle and similar).

MysteryX
5th July 2021, 06:01
AutoAdjust and AutoLevels adjust based on frame content. I just need to make sure that TV-scale and PC-scale frames are treated accordingly, for the min_in and max_in parameters of Levels.

WolframRhodium
5th July 2021, 07:20
The most efficient approach is to leverage akarin.Expr's (https://github.com/AkarinVS/vapoursynth-plugin) ability to read frame properties at runtime and implement the "Levels()" function yourself. Another way is to combine std.Levels() with std.FrameEval().

vcmohan
6th July 2021, 14:03
Aren"t All case naming is for plugin function names and camel case for parameters" ColorRange is all case. Thought violative of convention.