Log in

View Full Version : ffmpeg cliping luma values


Cary Knoop
20th May 2017, 03:15
Is it possible with ffmpeg and available filters to clip luma values below a certain level or would I have to use avi/vapour-synth?

poisondeathray
20th May 2017, 05:30
Is it possible with ffmpeg and available filters to clip luma values below a certain level or would I have to use avi/vapour-synth?

By "clip" did you mean replace with zero ? e.g. all values below a certain Y= threshold return zero ? All values above Y= threshold are untouched ?

One way is to use -vf lutyuv with an expression
https://ffmpeg.org/ffmpeg-filters.html#lut_002c-lutrgb_002c-lutyuv
https://ffmpeg.org/ffmpeg-utils.html#Expression-Evaluation

eg. if the Y value is greater than 50, then return the value, otherwise zero



ffmpeg -i INPUT.ext -vf lutyuv=y='if(gte(val,50),val,0)' -c:v utvideo -an OUTPUT.avi



You probably want to do for the U, V planes as well , or maybe U,V based on Y

Cary Knoop
20th May 2017, 05:46
Thanks, poisondeathray!

Actually I meant by 'clip' raise to the given lowest value.
I suppose the formula would be: lutyuv=y='if(gte(val,128),val,128)'

Just verifying, is this code 10 bit safe?

poisondeathray
20th May 2017, 05:55
Actually I meant by 'clip' raise to the given lowest value.
I suppose the formula would be: lutyuv=y='if(gte(val,128),val,128)'

Just verifying, is this code 10 bit safe?



"Clip" in video and image processing (and audio) terminology usually means "cut off"

To clarify, are you wanting to adjust a certain range of values ? Maybe a shadow boost etc....? Or did you mean raise the pedestal to a certain value ? - It's tricky because there are non linear ways to do it

ffmpeg filters used to be 8bit only. Not sure what the current status is.

Cary Knoop
20th May 2017, 06:15
To clarify, are you wanting to adjust a certain range of values ? Maybe a shadow boost etc....? Or did you mean raise the pedestal to a certain value ? - It's tricky because there are non linear ways to do it

I am testing log footage. Luma value 128 (in 10 bit) is defined as absolute black, but the noise is actually shaped above and below this number. Some input transformations transform the below 128 values as well, with the result that in some cases (during color grading) more noise is introduced than is necessary. By setting all <128 values to 128 this is avoided.

But if the filters are 8 bit only it is not going to be useful, unless they would leave the actual bits alone and only set everything below 32 to 32 and still remain 10 bit integrity.

Do you have any alternatives you can think of?

Thanks for your help!

richardpl
20th May 2017, 11:59
lut* filters are not 8bit only any more. Make sure you use recent enough FFmpeg version.

Use something like: -vf "lutyuv='clip(val,128,255)'" to clip only luma.

poisondeathray
20th May 2017, 15:57
Good to know richardpl

I verified valid 10bit is retained with lutyuv . (1023 in 10bit)

-vf "lutyuv='clip(val,128,1023)'"


One possible "gotcha" is the YUV<=>RGB mapping in other programs, especially with log, might not be what you expect it to be (e.g. when viewing LUT or reverse transform is applied). So double check with some tests if that "128" is the value you actually want it to be