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 277344CD6B for ; Tue, 30 Dec 2025 17:55:41 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b't6nI8hFt8EWOkc6dexkNfebUswZD3gX9yL681T14Ff0=', expected b'gvapvBOsAfXG2pN4YB+aKj7htXAzOvOLo0HIZ6sT8kI=')) header.d=gmail.com header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1767117331; h=to : date : message-id : in-reply-to : 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=MoeDlimH2Hb5CFdZFgxt5/EZXgSHRsgPov8odmjkcss=; b=27iXPUVTBhnFApvKreV+U3dv4Mi/i9PEbGAOWzL2xfomkKJFVXyghnGHgvIrnsal/eXqJ jhNajnmTwRsf7FdNEW/oHi5clqssHOvdsljq9U3cqn9HDUKFaOAgUnsoF1zxThmhL2Afh8E oiVkQDiYtIMcch/S/4zUx/In1f5QKpN37k3c/xRkKefWwJcpKMSFDaOUyrB3a+rlEQ88QpQ JEE6mQPIC7ii/li2bTgQoGVHD9LbE648XHOdZ/64WzOfan2WPN4tpd2YCYak8y42GgnlK2m Wl/TZs1BbWKqgohf0AaQzZzQb2vvRNgxjtqhyEf/RwOl3MrZwIHJQJvuvlxw== Received: from [172.20.0.4] (unknown [172.20.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 3ACAF690C7A; Tue, 30 Dec 2025 19:55:31 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1767117315; b=oFtajjh6Q/XCRgKQF7yP2Me3AE+Ikrp/2jQzge1u5ni7z7fsPgz5a0lzB44XeXDV3xaGW MRAalDeIGlJOrwv1x2KxwTNHYQVDBRnVUhYlFOxImWBSg9YQzVVeWBgyAWZu3Ot+BecjxoG o2kcNIB1QXb+VbW4TQnAfTgdNg9COVY/Iy95yvGF7am+iy4ueifM2U8uiicwRNf0++27nkc KAGLYVbfdbgxYlM1enEkgGADbO07grkS4mWMIeH7AwntKvE6Dv1Z7Rfl1kXJ0A8RITeilbE r3k7x9YBv7UHJujDBrSXOLkg8K7lTv9uqHohvAl5aI3FGLU/YhBKk0VP29+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1767117315; 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=t6nI8hFt8EWOkc6dexkNfebUswZD3gX9yL681T14Ff0=; b=ibPeWX2mWjsDKoZ6Js9LFZwFMzccoE+675ZhnwSH236+CEXOwK/fNNAhEta0Y131qBDB1 9QqmJoMFfXQ81LeBodUVzN+ei4ucWiXTimbWAGj4cIkD0MOOLS8QQdXGnwdiYI0vz8M/wB1 IkNylYXAjgb+u9eJfNmbpJ4iuzGAopmp3g01WlQEBHCOKlrHlGdohNRL+4DSf9DkX04G4we Fld7NnbYiaJaRoK2hfJ5dthoh5UN23G3yzf4CEEl2hUMsVS0dvSZ8+aLLWDMtwtlxYlXqGB EK+TEuYzu/CLT880i+K+pY3xFVmeULG7V5VBpOCTvfXy3BQw7TfbtdqzctxQ== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=gmail.com; arc=none; dmarc=pass header.from=gmail.com policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=gmail.com; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=gmail.com policy.dmarc=quarantine Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 4B81E690BE9 for ; Tue, 30 Dec 2025 19:55:02 +0200 (EET) Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-7aae5f2633dso10384580b3a.3 for ; Tue, 30 Dec 2025 09:55:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767117300; x=1767722100; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gvapvBOsAfXG2pN4YB+aKj7htXAzOvOLo0HIZ6sT8kI=; b=EGJ6FW1I3Nwjr4Hx8EUywAihKeoDzIVzJZjSroLlz/YB0yX9RFNV5K8E/mps+hfl0a MX1k/NOzxvrvSruEkYmkQFhA04dEN082czqojVF6Jb+3PLB3DycZh3tYZXOnbB+KgB6z aQ+KOSGtQ1bQWk3B/VoMY8XbDGUZiI6p6V2+WmjxxM3IX8zZUO/kXcDcJcO/UenAvR4K BC79AMl6AUxPuyJ5jfeHoTr9ucQSaiwjJ5Ryos5S3/eh/wLUg3YpZ3etzoHiRnIZwhNq wEbHFGQ9uRhnXTLdOUk+BvpIpGnlM2jH+LOCyz9eqLO4TytznkhlPaRN5UdWKysx8kJZ ZHag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767117300; x=1767722100; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=gvapvBOsAfXG2pN4YB+aKj7htXAzOvOLo0HIZ6sT8kI=; b=B6gCHufJzQ4j1hnIfyELXyMFZn/5aJI9+yDoLpl5gpkLLizf5BoQKGiA9RFJWCuUb/ c8LGtNRumTUduYxkYBpWWWtbAqFX33ccTq/YApePWhdnYMplpDtMJHDP/r56KVbBmQuO wnr3pmBOSWY9tQ/x/sAGPgSIidEZgpSROm8IPDpZY5poAoP2Z8F5XnFowGouZujfWJjd mRbDfANLD+yiiZtwo0rHZIiZgsm1R1yvaA9daftkQYInjq3MaNMlZ/WofWz27vvUQYxD kNGpNuapayTT9C4AmLcklrZHwkV1f2MK6f8GLzInsdYXG2bP2kq/5Uy2N3T+TOnNNIN/ onxw== X-Gm-Message-State: AOJu0YwyhqiFQ90RlKKTWttL0X1llIENsrNBCw8XWjH21yx1vxXxxFdR 6Th2xorp49H+zv381J1YlVRbUz8nl/ETjlaK8bTEyoGOBAlj7ifLWZLRG202jg== X-Gm-Gg: AY/fxX7iG9JndF/s+LSNc4I1xU9rYw28RuB0NA2wDcfFWsauNGomsT0VTeCdtxAgook 83HUFnx++rXFe4kHSpFaqj2OmXMmEZCiZ6F3Qcq+BteDJj7hIwvLL7Pt13G9wSQBGbqQ5cONZyz cABdhDYPreaDz/ooEdFVIENZU+n8ua3rC0JKywXbal7DjEgwJgD0WfIM3vx3+bPd0lDw9AIKQaI dhWQtqz/D9Fc8B3jzcpH9VjyeG7JlYScRnJmFLAALZ5+MXOk/VDBw0oss+iVBvsXFhEDj0+ryve tCsYBPXpC2S1nD27/ov60OlaDZGcrVDpqjDhKoH68GF6kRZnheuhPT5j9wUN+w2rbW9c4lgHG8P nJPLRju/gOTTkrRR7We7q6sQr0UbjKaiUE/cSTnfmOQn+USSUwst69C25Q7nid4h7YCJnW+Dqxh SAeBrXwMhyZXVqAic0abtuau9Y+Ye9t6wibdXWmClM X-Google-Smtp-Source: AGHT+IGsVC8aCFWYsRNoaflIMWlpx8Pt6gqdxzYp67/1qBXYb7WYzS2ErieydDnBodiwmL6MB3vV5A== X-Received: by 2002:a05:6a00:1d9f:b0:7c2:60c6:8ca0 with SMTP id d2e1a72fcca58-7ff6430ccbemr30694842b3a.5.1767117300040; Tue, 30 Dec 2025 09:55:00 -0800 (PST) Received: from Raja-Rathour-ASUS-TUF-Gaming-A15.. ([150.242.72.109]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7ff7b423d86sm32915166b3a.26.2025.12.30.09.54.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Dec 2025 09:54:59 -0800 (PST) To: ffmpeg-devel@ffmpeg.org Date: Tue, 30 Dec 2025 23:23:44 +0530 Message-ID: <20251230175442.71079-1-imraja729@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251230173156.62073-1-imraja729@gmail.com> References: <20251230173156.62073-1-imraja729@gmail.com> MIME-Version: 1.0 Message-ID-Hash: Q5MGQHNPXUPDC3VBVSJPVSZKVH7DZSDF X-Message-ID-Hash: Q5MGQHNPXUPDC3VBVSJPVSZKVH7DZSDF X-MailFrom: SRS0=cf/C=7E=gmail.com=imraja729@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] [PATCH v6] 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: Raja Rathour via ffmpeg-devel Cc: Raja Rathour Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: v6: Rebased on master to resolve automated Patchwork application failures. This patch adds slice threading support to the blackframe filter, improving performance on multi-core systems. Changes in v5: - Removed meta-comments regarding C90 compliance as requested. - Removed redundant null checks for ThreadData pointers. - Renamed the thread results array to 'nb_black_pixels_per_slice' for clarity. Signed-off-by: Raja Rathour --- libavfilter/vf_blackframe.c | 73 ++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/libavfilter/vf_blackframe.c b/libavfilter/vf_blackframe.c index cb566d103d..fb531b8a4c 100644 --- a/libavfilter/vf_blackframe.c +++ b/libavfilter/vf_blackframe.c @@ -39,19 +39,20 @@ typedef struct BlackFrameContext { const AVClass *class; - int bamount; ///< black amount - int bthresh; ///< black threshold - unsigned int frame; ///< frame number - unsigned int nblack; ///< number of black pixels counted so far - unsigned int last_keyframe; ///< frame number of the last received key-frame + int bamount; + int bthresh; + unsigned int frame; + unsigned int nblack; + unsigned int last_keyframe; } BlackFrameContext; typedef struct ThreadData { - const uint8_t *data; // Pointer to the image data - int linesize; // How wide is the memory line - int bthresh; // The black threshold - int width; // Image width - unsigned int *counts; // POINTER to the array where threads write results + const uint8_t *data; + int linesize; + int bthresh; + int width; + int height; // Added height for cleaner slice math + unsigned int *counts; } ThreadData; static const enum AVPixelFormat pix_fmts[] = { @@ -67,25 +68,21 @@ static const enum AVPixelFormat pix_fmts[] = { static int blackframe_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) { ThreadData *td = arg; - // Calculate vertical slice - int slice_start = (ctx->inputs[0]->h * jobnr) / nb_jobs; - int slice_end = (ctx->inputs[0]->h * (jobnr+1)) / nb_jobs; - - // Safety check for pointers - if (!td || !td->data || !td->counts) return 0; - - const uint8_t *p = td->data + slice_start * td->linesize; - unsigned int local_nblack = 0; + 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++) - local_nblack += p[x] < td->bthresh; + black_pixels_count += p[x] < td->bthresh; p += td->linesize; } - // Save my private count - td->counts[jobnr] = local_nblack; + td->counts[jobnr] = black_pixels_count; return 0; } @@ -97,39 +94,31 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) 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); - // 1. Get thread count - int nb_threads = ff_filter_get_nb_threads(ctx); - - // Allocate memory for thread results - unsigned int *thread_counts = av_calloc(nb_threads, sizeof(*thread_counts)); - if (!thread_counts) { - av_log(ctx, AV_LOG_ERROR, "Failed to allocate thread_counts\n"); + nb_black_pixels_per_slice = av_calloc(nb_threads, sizeof(*nb_black_pixels_per_slice)); + if (!nb_black_pixels_per_slice) return AVERROR(ENOMEM); - } - // 3. Prepare the data package td.data = frame->data[0]; td.linesize = frame->linesize[0]; td.width = inlink->w; + td.height = inlink->h; td.bthresh = s->bthresh; - td.counts = thread_counts; + td.counts = nb_black_pixels_per_slice; - // 4. Run the threads! - // We calculate the exact number of jobs we are about to run - int nb_jobs = FFMIN(frame->height, nb_threads); + nb_jobs = FFMIN(td.height, nb_threads); ff_filter_execute(ctx, blackframe_slice, &td, NULL, nb_jobs); - // 5. THE REDUCE STEP: Sum up the results s->nblack = 0; - // Only sum up the jobs that actually ran - for (int i = 0; i < nb_jobs; i++) { - s->nblack += thread_counts[i]; + for (i = 0; i < nb_jobs; i++) { + s->nblack += nb_black_pixels_per_slice[i]; } - // --- FROM HERE DOWN, THE CODE IS THE SAME AS THE ORIGINAL --- - if (frame->flags & AV_FRAME_FLAG_KEY) s->last_keyframe = s->frame; @@ -149,7 +138,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) s->frame++; s->nblack = 0; - av_free(thread_counts); + av_free(nb_black_pixels_per_slice); return ff_filter_frame(inlink->dst->outputs[0], frame); } -- 2.48.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org