From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 3BD7744431 for ; Mon, 12 Dec 2022 14:12:30 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D133268BCF8; Mon, 12 Dec 2022 16:12:27 +0200 (EET) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9B55068B896 for ; Mon, 12 Dec 2022 16:12:21 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id C00734B66A; Mon, 12 Dec 2022 15:12:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1670854338; bh=j20+zZ4SppkQlEev7B3CWOliyBVay6LlMOKceO91ETA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=O+rdi+7mKPFJiOhGJsommdEA3KP137heTEWnQ2sChBy8b368otAJ6u/SDbgYOq3Yy 2nnb1RM5gEiMqCXqC5ij/Jq2RRAyAufeURDyYypPpxtHNREO0FrPUJ94tmb6FAuF0k 5JOGj9XtFyDSRyE8YdRa3l6kUOu5h0W+Jo16ct3I= Date: Mon, 12 Dec 2022 15:12:18 +0100 Message-ID: <20221212151218.GB20905@haasn.xyz> From: Niklas Haas To: ffmpeg-devel@ffmpeg.org In-Reply-To: <20221209002806.22424-1-ffmpeg@haasn.xyz> References: <20221209002806.22424-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Content-Disposition: inline Subject: Re: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_blackdetect: support full-range YUV X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Niklas Haas Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Any objections to these two patches? On Fri, 09 Dec 2022 01:28:05 +0100 Niklas Haas wrote: > From: Niklas Haas > > 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. > > Signed-off-by: Niklas Haas > --- > libavfilter/vf_blackdetect.c | 20 ++++++++++---------- > 1 file changed, 10 insertions(+), 10 deletions(-) > > diff --git a/libavfilter/vf_blackdetect.c b/libavfilter/vf_blackdetect.c > index 99ff1ac606..c937248169 100644 > --- a/libavfilter/vf_blackdetect.c > +++ b/libavfilter/vf_blackdetect.c > @@ -102,8 +102,6 @@ static int config_input(AVFilterLink *inlink) > BlackDetectContext *s = ctx->priv; > const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); > const int depth = desc->comp[0].depth; > - const int max = (1 << depth) - 1; > - const int factor = (1 << (depth - 8)); > > s->depth = depth; > s->nb_threads = ff_filter_get_nb_threads(ctx); > @@ -113,16 +111,10 @@ static int config_input(AVFilterLink *inlink) > if (!s->counter) > return AVERROR(ENOMEM); > > - s->pixel_black_th_i = ff_fmt_is_in(inlink->format, yuvj_formats) ? > - // luminance_minimum_value + pixel_black_th * luminance_range_size > - s->pixel_black_th * max : > - 16 * factor + s->pixel_black_th * (235 - 16) * factor; > - > av_log(s, AV_LOG_VERBOSE, > - "black_min_duration:%s pixel_black_th:%f pixel_black_th_i:%d picture_black_ratio_th:%f\n", > + "black_min_duration:%s pixel_black_th:%f picture_black_ratio_th:%f\n", > av_ts2timestr(s->black_min_duration, &s->time_base), > - s->pixel_black_th, s->pixel_black_th_i, > - s->picture_black_ratio_th); > + s->pixel_black_th, s->picture_black_ratio_th); > return 0; > } > > @@ -182,6 +174,14 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *picref) > AVFilterContext *ctx = inlink->dst; > BlackDetectContext *s = ctx->priv; > double picture_black_ratio = 0; > + const int max = (1 << s->depth) - 1; > + const int factor = (1 << (s->depth - 8)); > + const int full = picref->color_range == AVCOL_RANGE_JPEG || > + ff_fmt_is_in(picref->format, yuvj_formats); > + > + s->pixel_black_th_i = full ? s->pixel_black_th * max : > + // luminance_minimum_value + pixel_black_th * luminance_range_size > + 16 * factor + s->pixel_black_th * (235 - 16) * factor; > > ff_filter_execute(ctx, black_counter, picref, NULL, > FFMIN(inlink->h, s->nb_threads)); > -- > 2.38.1 > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".