Log in

View Full Version : Color adjustments in RGB colorspace supporting ConditionalReader?


Stereodude
14th May 2018, 15:40
Is there any color adjusting plugin that works in RGB colorspace that supports ConditionalReader (or a similar way to vary parameters on a frame by frame basis) and high bit depth (>8-bit)?

Basically I'm looking for a RGB equivalent to the built in AVIsynth filter ColorYUV. RGBAdjust is similar and built in, but doesn't have a conditional argument.

My quick search for such a filter didn't find anything even ignoring my desire to work in >8-bit RGB color.

raffriff42
14th May 2018, 22:37
You can use RGBAdjust inside ScriptClip, something like this (not tested)ScriptClip("""
RGBAdjust(r=xyx_r, rg=xyx_rg)
""")
ConditionalReader("r.txt", "xyx_r", false)
ConditionalReader("rg.txt", "xyx_rg", false)
Edit - remember the variables are global, so give them names that are unique within the script (and any Imported scripts too)

Stereodude
14th May 2018, 23:53
You can use RGBAdjust inside ScriptClip, something like this (not tested)ScriptClip("""
RGBAdjust(r=xyx_r, rg=xyx_rg)
""")
ConditionalReader("r.txt", "xyx_r", false)
ConditionalReader("rg.txt", "xyx_rg", false)
Edit - remember the variables are global, so give them names that are unique within the script (and any Imported scripts too)
Thanks. The idea works. I think you have too many "" though. This is what I got to work.
ScriptClip(clip, "
RGBAdjust(rb=(xyx_rb), gb=(xyx_gb), bb=(xyx_bb))
")
ConditionalReader("r_levels_t2.txt", "xyx_rb", false)
ConditionalReader("b_levels_t2.txt", "xyx_gb", false)
ConditionalReader("g_levels_t2.txt", "xyx_bb", false)

StainlessS
15th May 2018, 00:09
The idea works. I think you have too many "" though.

As provided by RaffRiff42, triple quotes allows for use of single quoted strings within Scriptclip, otherwise not allowed.
Raff was just making it a bit more bullet proof for you.

Stereodude
15th May 2018, 00:13
As provided by RaffRiff42, triple quotes allows for use of single quoted strings within Scriptclip, otherwise not allowed.
Raff was just making it a bit more bullet proof for you.
I couldn't get it to work as he wrote it with the triple quotes. However, after being prompted by your post to take another look at it I see the triple quotes are messing with MP_Pipeline, which nests the entire script inside of triple quotes.

raffriff42
15th May 2018, 00:13
Cool, glad it worked. The triple quotes (""") are legit actually. They are for nested quotations. Example:ScriptClip("""
Subtitle("Current frame = " + String(current_frame),
\ align=5)
""")

StainlessS
15th May 2018, 00:18
Avisynth does not support eg 5 pairs of quotes (so as to be able to enclose both triple and single quotes), which can make things awkward.
(Other languages eg BASIC allow for 5 pairs [EDIT: and maybe 7 pairs of double] quotes [methinks]).


SSS="""
Subtitle("Current frame = " + String(current_frame), align=5)
"""
Scriptclip(SSS)


So can use as above, for use with your MP_Pipeline thing.

EDIT: Not sure how you use the mp_pipeline thing, maybe something like so

SSS="""
Subtitle("Current frame = " + String(current_frame), align=5)
"""
mp_pipeline("Scriptclip(SSS)")


EDIT: I sometimes use the Multi-Instance template model developed by Gavino and Martin53, to get around the missing 5 pairs of double quotes thing.

EDIT: And the SSS= """ ... """ thing is nothing to do with the 'ssS' on the end of my username, I usually use to signify a triple quoted string,
although some times as 'main source string' where S used for a substring of it.

wonkey_monkey
15th May 2018, 20:39
Does Avisynth need an <<<EOF type delimiter (heredoc)?

raffriff42
16th May 2018, 01:53
I dunno, it might be nicer to work with (triple quotes mess with my editor's syntax highlighting) but unless the strings can be nested, you will have the same problem.

TheFluff
16th May 2018, 10:44
Most modern languages provide facilities for both line breaks and various quote characters inside string literals, and usually some form of variable interpolation as well. Heredocs provide the first in languages such as Perl (and in Perl also the third), but what Avisynth script really lacks is an escape character (e.g. backslash) to provide the second. In languages that don’t have heredocs, multi-line string literals are sometimes provided via some special quote character (c.f. JavaScript, which uses `backticks` for this). The triple quote serves the same purpose in Avisynth script, but you can’t escape it.

Stereodude
4th June 2018, 10:23
Does using Scriptclip + RGBAdjust leak memory for anyone else? Both 32-bit and 64-bit Avisynth+ leak memory for me when used on 16-bit RGB. With DVD res (720x480) by about 10,000 frames in it has grown to about 4GB. In 32-bit it either crashes or simply stops adjusting the levels passing the video through unaffected. In 64-bit it just keeps growing.

I'm out of town and only discovered this as I was packing so I didn't have a lot of time to troubleshoot it or try to make a simple script showing the issue. I'm pretty sure it is the Scriptclip + RGB adjust portion that's the problem as the same script with ColorYUV (using conditional processing) doesn't have the issue.

pinterf
4th June 2018, 10:54
Good catch, I could reproduce the leak. It's there even at 8 bits but the internal lookup table for 16 bit is 128k, so it eats your memory faster.
EDIT: leak stopped
EDIT: conditional=true supported, like in colorYUV
EDIT: works now with 32 bit float (but no 'dither', and no 'analyze')
EDIT: check Avs+ r2700 test build

Stereodude
5th June 2018, 06:55
Good catch, I could reproduce the leak. It's there even at 8 bits but the internal lookup table for 16 bit is 128k, so it eats your memory faster.
EDIT: leak stopped
EDIT: conditional=true supported, like in colorYUV
EDIT: works now with 32 bit float (but no 'dither', and no 'analyze')
EDIT: check Avs+ r2700 test build
Very cool, thanks!

I'll check it out when I'm back in town, but that won't be a few days.

Stereodude
9th June 2018, 21:26
Good catch, I could reproduce the leak. It's there even at 8 bits but the internal lookup table for 16 bit is 128k, so it eats your memory faster.
EDIT: leak stopped
EDIT: conditional=true supported, like in colorYUV
EDIT: works now with 32 bit float (but no 'dither', and no 'analyze')
EDIT: check Avs+ r2700 test build
I confirm the leak is fixed.

IMHO, RGBAdjust is still missing at least one argument. Some sort of bit depth or scaling argument that can be used to scale the values in the file for the bias values. The ability to apply a formula would be useful too.

When using ScriptClip I can do this:

ScriptClip(source, "
RGBAdjust(rb=(xyx_b*256), gb=(xyx_b*256), bb=(xyx_b*256), r=(1-xyx_b/256), g=(1-xyx_b/256), b=(1-xyx_b/256))
")
ConditionalReader("levels_t.txt", "xyx_b", false)

Even using the new conditional = true argument there's no way to do something equivalent like:
RGBAdjust(source, conditional=true
ConditionalReader(("levels_t.txt"*256), "rgbadjust_rb", false)
ConditionalReader(("levels_t.txt"*256), "rgbadjust_gb", false)
ConditionalReader(("levels_t.txt"*256), "rgbadjust_bb", false)
ConditionalReader((1-"levels_t.txt"/256), "rgbadjust_r", false)
ConditionalReader((1-"levels_t.txt"/256), "rgbadjust_g", false)
ConditionalReader((1-"levels_t.txt"/256), "rgbadjust_b", false)