[FFmpeg-user] Curves filter to only affect dark grey/black
Joshua Grauman
jnfo-c at grauman.com
Wed Aug 1 21:03:56 EEST 2018
If anyone is interested, I figured out how to fix my problem. Since I
already had to compile ffmpeg, I just modifed the source code to the
curves filter.
Basically, I compute the saturation and value for each pixel, and only
apply the curve if the saturation and value are low enough... It works
well for me.
The relevant filter is libavfilter/vf_curves.c
I modified the function:
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
} else {
uint8_t *dst = out->data[0] + slice_start * out->linesize[0];
const uint8_t *src = in->data[0] + slice_start * in->linesize[0];
for (y = slice_start; y < slice_end; y++) {
for (x = 0; x < in->width * step; x += step) {
unsigned char rgbMin, rgbMax, val, sat;
rgbMin = src[x + r] < src[x + g] ? (src[x + r] < src[x + b] ? src[x + r] : src[x + b]) : (src[x + g] < src[x + b] ? src[x + g] : src[x + b]);
rgbMax = src[x + r] > src[x + g] ? (src[x + r] > src[x + b] ? src[x + r] : src[x + b]) : (src[x + g] > src[x + b] ? src[x + g] : src[x + b]);
val = rgbMax;
if(val == 0)
sat = 255;
else
sat = 255 * (long)(rgbMax - rgbMin) / val;
if((sat <= 200 && val < 30) || val < 20)
{
dst[x + r] = curves->graph[R][src[x + r]];
dst[x + g] = curves->graph[G][src[x + g]];
dst[x + b] = curves->graph[B][src[x + b]];
if(!direct && step == 4)
dst[x + a] = src[x + a];
}
else
{
dst[x + r] = src[x + r];
dst[x + g] = src[x + g];
dst[x + b] = src[x + b];
if(!direct && step == 4)
dst[x + a] = src[x + a];
}
}
dst += out->linesize[0];
src += in ->linesize[0];
}
}
return 0;
}
> Hi all,
>
> I am processing some video and would love help with the curves filter. The
> video is shot with a 'black' background, but it is not completely black
> (notice folds in the backdrop). I want to filter the video to make the
> background completely black without affecting any of the rest of the video at
> all. I'm using the following curves filter with some success:
>
> curves=master='0/0 0.10/0 .15/.15 .16/.16 .17/.17 .2/.2 .25/.25 .3/.3 .4/.4
> .5/.5 .8/.8 1/1'
>
> The problem is that the curves filter is affecting (darkening) the dark blue
> shirt as well.
>
> Here is a screenshot of the video I am working on.
> http://grauman.com/Screenshot_20180801_143551.png
>
> Is there a way to only affect the levels when the saturation is low
> (gray/black)?
>
> Josh
> _______________________________________________
> ffmpeg-user mailing list
> ffmpeg-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> ffmpeg-user-request at ffmpeg.org with subject "unsubscribe".
>
More information about the ffmpeg-user
mailing list