Log in

View Full Version : Colormatrix clamp option


hello_hello
3rd January 2012, 00:54
I've read several times in this forum a recommendation to use clamp=0 to prevent clipping (or maybe it's to allow it), but I've been wondering if that's really what it does. From the help files of version 2.5:

clamp:

Specifies whether pre/post clipping with limiter to 16-235/16-240 should be used. Possible settings:
0 - no clipping
1 - pre clipping (clip input to ColorMatrix)
2 - post clipping (clip output from ColorMatrix)
3 - pre and post clipping

3 is what previous (v1.x) versions of ColorMatrix used.

default - 3 (int)


Without the clamp option, does anyone know if colormatrix prevents clipping by default? Looking at the help files it seems ambiguous enough to me to wonder if it doesn't do exactly the opposite.

For example the default of 3, "pre and post clipping" seems to allow clipping when read out of context, but looking at the description of the options the default of 3 could be taken to mean "pre/post clipping with limiter to 16-235/16-240", which would mean clamp=3 is the option which prevents clipping.

Also from the help file:
"3 is what previous (v1.x) versions of ColorMatrix used."

So I found a help file for version 1.9 and while it doesn't mention a clamp option, it does say this:
"As a final note. This filter will clamp (= round) your input video to CCIR-601 compliant values (these ranges are 16-235 for the luma component and 16-240 for the chroma component)."

Which leads me to conclude the current version of colormatrix does prevent clipping by default if that's what version 1.9 did (as clamp=3 is the default) and clamp=0 would stop it from preventing clipping.
Comments anyone?

poisondeathray
3rd January 2012, 01:02
Last few versions clip to "legal" values by default.

You can confirm the behaviour yourself by using histogram() with a full range source (or use coloryuv(analyze=true) )

hello_hello
3rd January 2012, 01:08
Cheers. So am I correct then in assuming clamp=0 would actually allow "illegal" values?

Maybe I've just been reading the help file the wrong way. You said "clip to legal values" which obviously means "limit to legal values". I've assumed in the context of the help file clamp=0 (no clipping) would mean the application of limiting, as it would apply when referring to audio, while "pre and post clipping" would mean a lack of limiting. Obviously it's the other way around.
So if I substitute "limit" for clip in the help files I'd get this:

0 - no limiting
1 - pre limiting (limit input to ColorMatrix)
2 - post limiting (limit output from ColorMatrix)
3 - pre and post limiting

default - 3 (int) - pre and post limiting

Is that how it works?

I wonder why I've seen clamp=0 as the recommended option quite a few times? Once again I guess I assumed it was recommended as it prevents illegal values but now as I understand it, it allows them. What would be the reasoning behind allowing them?

Thanks.

poisondeathray
3rd January 2012, 01:47
Cheers. So am I correct then in assuming clamp=0 would actually allow "illegal" values?


Yes, it means YUV in = YUV out . Source levels unchanged

You're allowed to have overshoot and undershoot . It's part of the spec. You see it in retail dvd's / blu-ray all the time



I wonder why I've seen clamp=0 as the recommended option quite a few times?


clamp= 0 is usually recommended because presumably you want same as source levels (if you're coming from another program, presumably you've fixed the levels there already)

hello_hello
3rd January 2012, 03:19
Okay, thanks. I had no idea overshooting and undershooting is okay.
Out of curiosity, is using color conversion (R.709 to R.601 etc) likely to result in illegal levels when encoding if the original video only used legal levels to begin with?

I think now I understand what was happening when I was experimenting with some calibration images on my TV the other day. The back/white calibration image ranged from 0 to 255 and I wasn't quite sure why 255 was obviously whiter than 235 given I thought 235 was supposed to be "white". Same with black at 0 and 16. I thought with the TV at least, 16-235 were supposed to be the minimum and maximum. You learn something every day.

Thanks for the help. Given I've encoded countless videos without using "clamp=0" I might have to re-encode a couple just to see if it makes a noticeable difference. I almost wish I'd never asked the question in case I discover not using it was making a difference to my encodes only I just hadn't noticed. Oh well.....

poisondeathray
3rd January 2012, 03:33
Okay, thanks. I had no idea overshooting and undershooting is okay.


Small excursions are ok - the ranges 0-15 and 236-255 are there for under/over shoot - but most of the data should still be within Y' 16-235 CbCr 16-240


Out of curiosity, is using color conversion (R.709 to R.601 etc) likely to result in illegal levels when encoding if the original video only used legal levels to begin with?


No, levels are unchanged when using the Rec matrices. Only when you use PC matrix is there a contrast stretch/shrink



I think now I understand what was happening when I was experimenting with some calibration images on my TV the other day. The back/white calibration image ranged from 0 to 255 and I wasn't quite sure why 255 was obviously whiter than 235 given I thought 235 was supposed to be "white". Same with black at 0 and 16. I thought with the TV at least, 16-235 were supposed to be the minimum and maximum. You learn something every day.


That's correct, Y' 235 is supposed to be "white", Y' 16 is supposed to be "black" , but small over/undershoots are acceptable (that's why "superdarks" and "superbrights" are in the spec to begin with)

hello_hello
3rd January 2012, 03:52
Thanks for the info.