Hi Raja On Tue, Dec 23, 2025 at 10:14:41PM +0530, Raja Rathour via ffmpeg-devel wrote: > --- > libavfilter/vf_blackframe.c | 80 ++++++++++++++++++++++++++++++++----- > 1 file changed, 71 insertions(+), 9 deletions(-) > > diff --git a/libavfilter/vf_blackframe.c b/libavfilter/vf_blackframe.c > index f0aa53e133..f09d564bf7 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,14 @@ typedef struct BlackFrameContext { > unsigned int last_keyframe; ///< frame number of the last received key-frame > } 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 > +} 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 +64,72 @@ 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; > + // --- C90 HARD FIX: ALL DECLARATIONS AT THE VERY TOP --- remove useless comments, like this > + int slice_start, slice_end, x, y; > + const uint8_t *p; > + unsigned int local_nblack = 0; > + // ------------------------------------------------------ > + > + // Safety check > + if (!td || !td->data || !td->counts) return 0; explain how these are possible conditions > + > + slice_start = (ctx->inputs[0]->h * jobnr) / nb_jobs; > + slice_end = (ctx->inputs[0]->h * (jobnr+1)) / nb_jobs; > + > + 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; > + p += td->linesize; > + } > + > + // Save my private count > + td->counts[jobnr] = local_nblack; > + return 0; > +} > + > static int filter_frame(AVFilterLink *inlink, AVFrame *frame) > { > AVFilterContext *ctx = inlink->dst; > BlackFrameContext *s = ctx->priv; > - int x, i; > + // --- C90 HARD FIX: ALL DECLARATIONS AT THE VERY TOP --- > int pblack = 0; > - uint8_t *p = frame->data[0]; > AVDictionary **metadata; > char buf[32]; > - > - for (i = 0; i < frame->height; i++) { > - for (x = 0; x < inlink->w; x++) > - s->nblack += p[x] < s->bthresh; > - p += frame->linesize[0]; > + ThreadData td; > + int nb_threads; > + unsigned int *thread_counts; please use a descriptive name that describes whats in the array thx [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Republics decline into democracies and democracies degenerate into despotisms. -- Aristotle