From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 6D2A24DD29 for ; Sun, 4 Jan 2026 22:17:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1767565003; h=date : to : in-reply-to : message-id : references : mime-version : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=f9qVYl5bSmR8i3gLylxPflBCPH4hd15ujJfPfKpZDiI=; b=JlgOQy6MhEz1uWDU2VAbr5g9LetZxEagT4NkQe2qbE4K9Kw5E39LScKoYKbvAOP4fbCYC Syt6iA9qA3yp5Px3NgaBqhwa8vNxyq0Q1mAmkMPMG7eq980TmCJPuJiYsKGfW+CWbFezpUZ JWk4zC7bed9yuvljDRc0Ke4qMyCVm9DCZqbxoR2QeYGVqU0Poor3GvkRtRYriZcBTdWdXIv aeD6REjNY/BIdRq1ZfipEZgTTvf8hhuzrH6efwqhVf/PLh8AJvKSitrpWsTwBNugckSOMhB 7+hibBRYVSv/BaAF/a3jXOL1HJranoEiFWadWQ0Kcnt/2tvDwIUhHHWT5mPQ== Received: from [172.20.0.4] (unknown [172.20.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id C62FA690D59; Mon, 5 Jan 2026 00:16:43 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1767564971; b=ln7PjeotfhwCQkBI7qvvYnbRJsUtoTcVhxXvkB6Jd+3BBswiiCfppAjXD8YumaSgAEmZC w4H39c0ny3Mum4b6OpyfVP3gWPpwmRbaPyatN76LBUIATQODJS1j1X/JSxRAligmzQeKfRG 10UE6qiW69MkUmAH4+lvfwwL9ZUDQi37fBlzGoWdgAt9taTQ+GheiVnTrlCmvjhqoj5AdXy hPsEKvnMbFfv+oct9HUPjGILjtlNz/B8mJCFONcUAwRFkjL/7UhAkN3Eztuv9gkuhEA45Zj Vq/AfJjgNsYohTYZRA8i9roWNB5+whLRX5EUqccZIGG7G75R/xO50Tmw8qZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1767564971; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=VBkM8ql/UrjYctZopA3gxc4moOyBBA69iLZzoA8Nv9w=; b=QYIZ5l2mW2r3/eMXFoyblj6cn21PkzyvheEGgTubjDcRRfk94rvIeoXA5nyC0jye6ql9X I+FEtm2XT0B43z5GeYVRi1hPLjECIpqECguenq/pTBoqcXF41QT4KMObGqhC3x6I7Y2Rcy1 D1hvUbnwwnrIt53o4JNY73OmTQhvdz6Qy6ElSYyGR6dgFwBvy+/TcqVmDJ4gP4hqAihVRG/ WLyI2iM0eL5YmoSlZtvPrGFvddn1du8T6Tw+zbLenRGbSdEAycaYPbSrFp3Ej2j67wFSGTB 6Nlul+pLvHGt81My9iJrDTkx/PiJSbEPKz3z9G7md6wjH4x45uFhWcH9rVWw== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=fail; arc=none; dmarc=none Authentication-Results: ffmpeg.org; dkim=fail; arc=none (Message is not ARC signed); dmarc=none Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id D021168FDC9 for ; Mon, 5 Jan 2026 00:15:57 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 182EEEC95E for ; Sun, 4 Jan 2026 23:15:50 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id h8LI7qRGaoVq for ; Sun, 4 Jan 2026 23:15:48 +0100 (CET) Received: from iq (iq [217.27.212.140]) by iq.passwd.hu (Postfix) with ESMTPS id 3A28DEC95B for ; Sun, 4 Jan 2026 23:15:48 +0100 (CET) Date: Sun, 4 Jan 2026 23:15:48 +0100 (CET) To: Raja Rathour via ffmpeg-devel In-Reply-To: <20260101064038.17335-1-imraja729@gmail.com> Message-ID: <28f23b4d-2137-ed53-fc04-312844a27d0f@passwd.hu> References: <20260101064038.17335-1-imraja729@gmail.com> MIME-Version: 1.0 Message-ID-Hash: 7F65QE3U7YL5J6CBC46Q4TMAQV5ZI5OV X-Message-ID-Hash: 7F65QE3U7YL5J6CBC46Q4TMAQV5ZI5OV X-MailFrom: SRS0=SKQ7=7J=passwd.hu=cus@ffmpeg.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] Re: [PATCH v8] avfilter/vf_blackframe: add slice threading List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Marton Balint via ffmpeg-devel Cc: Marton Balint Content-Type: text/plain; charset="us-ascii"; format="flowed" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: On Thu, 1 Jan 2026, Raja Rathour via ffmpeg-devel wrote: > v8: Restored original struct comments (unrelated to threads) and updated height comment to Doxygen style (///<) as requested. > > Thank you for the detailed feedback on the patch structure and project style. > > Signed-off-by: Raja Rathour > --- > libavfilter/vf_blackframe.c | 69 ++++++++++++++++++++++++++++++++----- > 1 file changed, 60 insertions(+), 9 deletions(-) > > diff --git a/libavfilter/vf_blackframe.c b/libavfilter/vf_blackframe.c > index f0aa53e133..5b198e6594 100644 > --- a/libavfilter/vf_blackframe.c > +++ b/libavfilter/vf_blackframe.c > @@ -32,6 +32,7 @@ > > #include "libavutil/internal.h" > #include "libavutil/opt.h" > +#include "libavutil/mem.h" > #include "avfilter.h" > #include "filters.h" > #include "video.h" > @@ -45,6 +46,15 @@ typedef struct BlackFrameContext { > unsigned int last_keyframe; ///< frame number of the last received key-frame > } BlackFrameContext; > > +typedef struct ThreadData { > + const uint8_t *data; > + int linesize; > + int bthresh; > + int width; > + int height; ///< height for cleaner slice math > + unsigned int *counts; You can use a single stdatomic atomic int for this and avoid the allocation. Also I suggest you open a pull request at code.ffmpeg.org. Regards, Marton > +} ThreadData; > + > static const enum AVPixelFormat pix_fmts[] = { > AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NV12, > AV_PIX_FMT_NV21, AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV411P, > @@ -55,22 +65,60 @@ static const enum AVPixelFormat pix_fmts[] = { > snprintf(buf, sizeof(buf), format, value); \ > av_dict_set(metadata, key, buf, 0) > > +static int blackframe_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) > +{ > + ThreadData *td = arg; > + int slice_start = (td->height * jobnr) / nb_jobs; > + int slice_end = (td->height * (jobnr+1)) / nb_jobs; > + int x, y; > + const uint8_t *p; > + unsigned int black_pixels_count = 0; > + > + p = td->data + slice_start * td->linesize; > + > + for (y = slice_start; y < slice_end; y++) { > + for (x = 0; x < td->width; x++) > + black_pixels_count += p[x] < td->bthresh; > + p += td->linesize; > + } > + > + td->counts[jobnr] = black_pixels_count; > + return 0; > +} > + > static int filter_frame(AVFilterLink *inlink, AVFrame *frame) > { > AVFilterContext *ctx = inlink->dst; > BlackFrameContext *s = ctx->priv; > - int x, i; > int pblack = 0; > - uint8_t *p = frame->data[0]; > AVDictionary **metadata; > char buf[32]; > + ThreadData td; > + int nb_threads, nb_jobs, i; > + unsigned int *nb_black_pixels_per_slice; > + > + nb_threads = ff_filter_get_nb_threads(ctx); > + > + nb_black_pixels_per_slice = av_calloc(nb_threads, sizeof(*nb_black_pixels_per_slice)); > + if (!nb_black_pixels_per_slice) > + return AVERROR(ENOMEM); > + > + td.data = frame->data[0]; > + td.linesize = frame->linesize[0]; > + td.width = inlink->w; > + td.height = inlink->h; > + td.bthresh = s->bthresh; > + td.counts = nb_black_pixels_per_slice; > + > + nb_jobs = FFMIN(td.height, nb_threads); > + > + ff_filter_execute(ctx, blackframe_slice, &td, NULL, nb_jobs); > > - for (i = 0; i < frame->height; i++) { > - for (x = 0; x < inlink->w; x++) > - s->nblack += p[x] < s->bthresh; > - p += frame->linesize[0]; > + s->nblack = 0; > + for (i = 0; i < nb_jobs; i++) { > + s->nblack += nb_black_pixels_per_slice[i]; > } > - > + > if (frame->flags & AV_FRAME_FLAG_KEY) > s->last_keyframe = s->frame; > > @@ -89,6 +137,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) > > s->frame++; > s->nblack = 0; > + > + av_free(nb_black_pixels_per_slice); > + > return ff_filter_frame(inlink->dst->outputs[0], frame); > } > > @@ -118,9 +169,9 @@ const FFFilter ff_vf_blackframe = { > .p.name = "blackframe", > .p.description = NULL_IF_CONFIG_SMALL("Detect frames that are (almost) black."), > .p.priv_class = &blackframe_class, > - .p.flags = AVFILTER_FLAG_METADATA_ONLY, > + .p.flags = AVFILTER_FLAG_METADATA_ONLY | AVFILTER_FLAG_SLICE_THREADS, > .priv_size = sizeof(BlackFrameContext), > FILTER_INPUTS(avfilter_vf_blackframe_inputs), > FILTER_OUTPUTS(ff_video_default_filterpad), > FILTER_PIXFMTS_ARRAY(pix_fmts), > -}; > +}; > \ No newline at end of file > -- > 2.48.1 > > _______________________________________________ > ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org > To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org > _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org