History

avfilter/vf_blackdetect: support full-range YUV

This filter currently makes the distinction between limited and full range by testing for the deprecated YUVJ pixel formats at link setup time. This is deprecated and should be improved to perform the detection based on the per-frame metadata. Rewrite it to calculate the black pixel threshold at the time of filtering a frame, when metadata about the frame's color range is known. Doing it this way has the small side benefit of being able to handle streams with variable metadata, and is not a meaningful performance cost.

Niklas Haas committed 3 years ago

Commit 8e2f61e1 parent 3b667571 file · +10 −10Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_blackdetect.c+10−10
@@ -102,8 +102,6 @@ static int config_input(AVFilterLink *inlink) · 101 unmodified lines
102102 BlackDetectContext *s = ctx->priv;
103103 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
104104 const int depth = desc->comp[0].depth;
105− const int max = (1 << depth) - 1;
106− const int factor = (1 << (depth - 8));
107105
108106 s->depth = depth;
109107 s->nb_threads = ff_filter_get_nb_threads(ctx);
@@ -113,16 +111,10 @@ static int config_input(AVFilterLink *inlink) · 3 unmodified lines
113111 if (!s->counter)
114112 return AVERROR(ENOMEM);
115113
116− s->pixel_black_th_i = ff_fmt_is_in(inlink->format, yuvj_formats) ?
117− // luminance_minimum_value + pixel_black_th * luminance_range_size
118− s->pixel_black_th * max :
119− 16 * factor + s->pixel_black_th * (235 - 16) * factor;
120−
121114 av_log(s, AV_LOG_VERBOSE,
122− "black_min_duration:%s pixel_black_th:%f pixel_black_th_i:%d picture_black_ratio_th:%f\n",
115+ "black_min_duration:%s pixel_black_th:%f picture_black_ratio_th:%f\n",
123116 av_ts2timestr(s->black_min_duration, &s->time_base),
124− s->pixel_black_th, s->pixel_black_th_i,
125− s->picture_black_ratio_th);
117+ s->pixel_black_th, s->picture_black_ratio_th);
126118 return 0;
127119 }
128120
@@ -182,6 +174,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref) · 53 unmodified lines
182174 AVFilterContext *ctx = inlink->dst;
183175 BlackDetectContext *s = ctx->priv;
184176 double picture_black_ratio = 0;
177+ const int max = (1 << s->depth) - 1;
178+ const int factor = (1 << (s->depth - 8));
179+ const int full = picref->color_range == AVCOL_RANGE_JPEG ||
180+ ff_fmt_is_in(picref->format, yuvj_formats);
181+
182+ s->pixel_black_th_i = full ? s->pixel_black_th * max :
183+ // luminance_minimum_value + pixel_black_th * luminance_range_size
184+ 16 * factor + s->pixel_black_th * (235 - 16) * factor;
185185
186186 ff_filter_execute(ctx, black_counter, picref, NULL,
187187 FFMIN(inlink->h, s->nb_threads));

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t