* [FFmpeg-devel] [PATCH v2 0/2] avfilter/vf_thumbnail: support more formats @ 2025-06-20 14:13 Niklas Haas 2025-06-20 14:13 ` [FFmpeg-devel] [PATCH v2 1/2] avfilter/vf_thumbnail: support more planar formats Niklas Haas 2025-06-20 14:13 ` [FFmpeg-devel] [PATCH v2 2/2] avfilter/vf_thumbnail: switch to query_func2 Niklas Haas 0 siblings, 2 replies; 4+ messages in thread From: Niklas Haas @ 2025-06-20 14:13 UTC (permalink / raw) To: ffmpeg-devel Changes since v1: - merge the 16-bit and 8-bit cases to reduce a bit of code duplication - add the support for grayscale formats as well - switch to query_func2 instead of hard-coding the format list I'm not sure I like the complicated logic inside query_func2 now, it feels like it hard-codes just as many assumptions as a static list. _______________________________________________ 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". ^ permalink raw reply [flat|nested] 4+ messages in thread
* [FFmpeg-devel] [PATCH v2 1/2] avfilter/vf_thumbnail: support more planar formats 2025-06-20 14:13 [FFmpeg-devel] [PATCH v2 0/2] avfilter/vf_thumbnail: support more formats Niklas Haas @ 2025-06-20 14:13 ` Niklas Haas 2025-06-20 14:13 ` [FFmpeg-devel] [PATCH v2 2/2] avfilter/vf_thumbnail: switch to query_func2 Niklas Haas 1 sibling, 0 replies; 4+ messages in thread From: Niklas Haas @ 2025-06-20 14:13 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Niklas Haas From: Niklas Haas <git@haasn.dev> This adds support for high bit depth formats, as well as formats with fewer than 3 planes. The implementation for HBD is the same as for 8 bit formats, just right shifted to 8 bits. It's worth pointing out that this also works for HDR formats (and even DV), because the underlying implementation is just trying to minimize the histogram difference. If anything, using a HDR format will result in a *more* accurate detection, because HDR formats tend to be more perceptually uniform. --- libavfilter/vf_thumbnail.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/libavfilter/vf_thumbnail.c b/libavfilter/vf_thumbnail.c index 90125a879c..55a0598e50 100644 --- a/libavfilter/vf_thumbnail.c +++ b/libavfilter/vf_thumbnail.c @@ -53,6 +53,8 @@ typedef struct ThumbContext { int planewidth[4]; int planeheight[4]; + int planes; + int bitdepth; } ThumbContext; #define OFFSET(x) offsetof(ThumbContext, x) @@ -194,7 +196,7 @@ static int do_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) } break; default: - for (int plane = 0; plane < 3; plane++) { + for (int plane = 0; plane < s->planes; plane++) { const int slice_start = (s->planeheight[plane] * jobnr) / nb_jobs; const int slice_end = (s->planeheight[plane] * (jobnr+1)) / nb_jobs; const uint8_t *p = frame->data[plane] + slice_start * frame->linesize[plane]; @@ -202,10 +204,21 @@ static int do_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) const int planewidth = s->planewidth[plane]; int *hhist = hist + 256 * plane; - for (int j = slice_start; j < slice_end; j++) { - for (int i = 0; i < planewidth; i++) - hhist[p[i]]++; - p += linesize; + if (s->bitdepth > 8) { + const uint16_t *p16 = (const uint16_t *) p; + const int shift = s->bitdepth - 8; + + for (int j = slice_start; j < slice_end; j++) { + for (int i = 0; i < planewidth; i++) + hhist[(p16[i] >> shift) & 0xFF]++; + p16 += linesize >> 1; + } + } else { + for (int j = slice_start; j < slice_end; j++) { + for (int i = 0; i < planewidth; i++) + hhist[p[i]]++; + p += linesize; + } } } break; @@ -286,6 +299,8 @@ static int config_props(AVFilterLink *inlink) s->planewidth[0] = s->planewidth[3] = inlink->w; s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); s->planeheight[0] = s->planeheight[3] = inlink->h; + s->planes = av_pix_fmt_count_planes(inlink->format) - !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA); + s->bitdepth = desc->comp[0].depth; return 0; } -- 2.49.0 _______________________________________________ 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". ^ permalink raw reply [flat|nested] 4+ messages in thread
* [FFmpeg-devel] [PATCH v2 2/2] avfilter/vf_thumbnail: switch to query_func2 2025-06-20 14:13 [FFmpeg-devel] [PATCH v2 0/2] avfilter/vf_thumbnail: support more formats Niklas Haas 2025-06-20 14:13 ` [FFmpeg-devel] [PATCH v2 1/2] avfilter/vf_thumbnail: support more planar formats Niklas Haas @ 2025-06-20 14:13 ` Niklas Haas 2025-06-20 14:16 ` Niklas Haas 1 sibling, 1 reply; 4+ messages in thread From: Niklas Haas @ 2025-06-20 14:13 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Niklas Haas From: Niklas Haas <git@haasn.dev> Instead of enumerating a static list of planar formats to support, walk through the format list and enable all supported formats. As of writing, this generates the following format list: - gbrap - gbrap10le - gbrap12le - gbrap14le - gbrap16le - gbrp - gbrp10le - gbrp12le - gbrp14le - gbrp16le - gbrp9le - gray - gray10le - gray12le - gray14le - gray16le - gray9le - ya16le - ya8 - yuv410p - yuv411p - yuv420p - yuv420p10le - yuv420p12le - yuv420p14le - yuv420p16le - yuv420p9le - yuv422p - yuv422p10le - yuv422p12le - yuv422p14le - yuv422p16le - yuv422p9le - yuv440p - yuv440p10le - yuv440p12le - yuv444p - yuv444p10le - yuv444p12le - yuv444p14le - yuv444p16le - yuv444p9le - yuva420p - yuva420p10le - yuva420p16le - yuva420p9le - yuva422p - yuva422p10le - yuva422p12le - yuva422p16le - yuva422p9le - yuva444p - yuva444p10le - yuva444p12le - yuva444p16le - yuva444p9le - yuvj411p - yuvj420p - yuvj422p - yuvj440p - yuvj444p --- libavfilter/vf_thumbnail.c | 43 +++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/libavfilter/vf_thumbnail.c b/libavfilter/vf_thumbnail.c index 55a0598e50..6f7a0ba766 100644 --- a/libavfilter/vf_thumbnail.c +++ b/libavfilter/vf_thumbnail.c @@ -32,6 +32,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" #include "filters.h" +#include "formats.h" #define HIST_SIZE (3*256) @@ -305,23 +306,45 @@ static int config_props(AVFilterLink *inlink) return 0; } -static const enum AVPixelFormat pix_fmts[] = { +static const enum AVPixelFormat packed_rgb_fmts[] = { AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24, AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA, AV_PIX_FMT_RGB0, AV_PIX_FMT_BGR0, AV_PIX_FMT_ABGR, AV_PIX_FMT_ARGB, AV_PIX_FMT_0BGR, AV_PIX_FMT_0RGB, - AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, - AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, - AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P, - AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, - AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ444P, - AV_PIX_FMT_YUVJ411P, - AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P, - AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, AV_PIX_FMT_NONE }; +static int query_formats(const AVFilterContext *ctx, + AVFilterFormatsConfig **cfg_in, + AVFilterFormatsConfig **cfg_out) +{ + const AVPixFmtDescriptor *desc = NULL; + AVFilterFormats *formats; + + formats = ff_make_format_list(packed_rgb_fmts); + if (!formats) + return AVERROR(ENOMEM); + + + while ((desc = av_pix_fmt_desc_next(desc))) { + int color_comps = desc->nb_components - !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA); + if ((color_comps == 1 || (desc->flags & AV_PIX_FMT_FLAG_PLANAR)) && + !(desc->flags & (AV_PIX_FMT_FLAG_FLOAT | AV_PIX_FMT_FLAG_BITSTREAM)) && + (desc->comp[0].depth <= 8 || HAVE_BIGENDIAN == !!(desc->flags & AV_PIX_FMT_FLAG_BE)) && + (desc->nb_components < 3 || desc->comp[1].plane != desc->comp[2].plane) && + desc->comp[0].depth <= 16) + { + printf("Adding format %s\n", desc->name); + int ret = ff_add_format(&formats, av_pix_fmt_desc_get_id(desc)); + if (ret < 0) + return ret; + } + } + + return ff_set_common_formats2(ctx, cfg_in, cfg_out, formats); +} + static const AVFilterPad thumbnail_inputs[] = { { .name = "default", @@ -350,5 +373,5 @@ const FFFilter ff_vf_thumbnail = { .uninit = uninit, FILTER_INPUTS(thumbnail_inputs), FILTER_OUTPUTS(thumbnail_outputs), - FILTER_PIXFMTS_ARRAY(pix_fmts), + FILTER_QUERY_FUNC2(query_formats), }; -- 2.49.0 _______________________________________________ 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". ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2 2/2] avfilter/vf_thumbnail: switch to query_func2 2025-06-20 14:13 ` [FFmpeg-devel] [PATCH v2 2/2] avfilter/vf_thumbnail: switch to query_func2 Niklas Haas @ 2025-06-20 14:16 ` Niklas Haas 0 siblings, 0 replies; 4+ messages in thread From: Niklas Haas @ 2025-06-20 14:16 UTC (permalink / raw) To: ffmpeg-devel; +Cc: Niklas Haas On Fri, 20 Jun 2025 16:13:34 +0200 Niklas Haas <ffmpeg@haasn.xyz> wrote: > From: Niklas Haas <git@haasn.dev> > > Instead of enumerating a static list of planar formats to support, walk > through the format list and enable all supported formats. > > As of writing, this generates the following format list: > - gbrap > - gbrap10le > - gbrap12le > - gbrap14le > - gbrap16le > - gbrp > - gbrp10le > - gbrp12le > - gbrp14le > - gbrp16le > - gbrp9le > - gray > - gray10le > - gray12le > - gray14le > - gray16le > - gray9le > - ya16le > - ya8 > - yuv410p > - yuv411p > - yuv420p > - yuv420p10le > - yuv420p12le > - yuv420p14le > - yuv420p16le > - yuv420p9le > - yuv422p > - yuv422p10le > - yuv422p12le > - yuv422p14le > - yuv422p16le > - yuv422p9le > - yuv440p > - yuv440p10le > - yuv440p12le > - yuv444p > - yuv444p10le > - yuv444p12le > - yuv444p14le > - yuv444p16le > - yuv444p9le > - yuva420p > - yuva420p10le > - yuva420p16le > - yuva420p9le > - yuva422p > - yuva422p10le > - yuva422p12le > - yuva422p16le > - yuva422p9le > - yuva444p > - yuva444p10le > - yuva444p12le > - yuva444p16le > - yuva444p9le > - yuvj411p > - yuvj420p > - yuvj422p > - yuvj440p > - yuvj444p > --- > libavfilter/vf_thumbnail.c | 43 +++++++++++++++++++++++++++++--------- > 1 file changed, 33 insertions(+), 10 deletions(-) > > diff --git a/libavfilter/vf_thumbnail.c b/libavfilter/vf_thumbnail.c > index 55a0598e50..6f7a0ba766 100644 > --- a/libavfilter/vf_thumbnail.c > +++ b/libavfilter/vf_thumbnail.c > @@ -32,6 +32,7 @@ > #include "libavutil/pixdesc.h" > #include "avfilter.h" > #include "filters.h" > +#include "formats.h" > > #define HIST_SIZE (3*256) > > @@ -305,23 +306,45 @@ static int config_props(AVFilterLink *inlink) > return 0; > } > > -static const enum AVPixelFormat pix_fmts[] = { > +static const enum AVPixelFormat packed_rgb_fmts[] = { > AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24, > AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA, > AV_PIX_FMT_RGB0, AV_PIX_FMT_BGR0, > AV_PIX_FMT_ABGR, AV_PIX_FMT_ARGB, > AV_PIX_FMT_0BGR, AV_PIX_FMT_0RGB, > - AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, > - AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, > - AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P, > - AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, > - AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ444P, > - AV_PIX_FMT_YUVJ411P, > - AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P, > - AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, > AV_PIX_FMT_NONE > }; > > +static int query_formats(const AVFilterContext *ctx, > + AVFilterFormatsConfig **cfg_in, > + AVFilterFormatsConfig **cfg_out) > +{ > + const AVPixFmtDescriptor *desc = NULL; > + AVFilterFormats *formats; > + > + formats = ff_make_format_list(packed_rgb_fmts); > + if (!formats) > + return AVERROR(ENOMEM); > + > + > + while ((desc = av_pix_fmt_desc_next(desc))) { > + int color_comps = desc->nb_components - !!(desc->flags & AV_PIX_FMT_FLAG_ALPHA); > + if ((color_comps == 1 || (desc->flags & AV_PIX_FMT_FLAG_PLANAR)) && > + !(desc->flags & (AV_PIX_FMT_FLAG_FLOAT | AV_PIX_FMT_FLAG_BITSTREAM)) && > + (desc->comp[0].depth <= 8 || HAVE_BIGENDIAN == !!(desc->flags & AV_PIX_FMT_FLAG_BE)) && > + (desc->nb_components < 3 || desc->comp[1].plane != desc->comp[2].plane) && > + desc->comp[0].depth <= 16) > + { > + printf("Adding format %s\n", desc->name); Oops, removed this left-over printf locally. > + int ret = ff_add_format(&formats, av_pix_fmt_desc_get_id(desc)); > + if (ret < 0) > + return ret; > + } > + } > + > + return ff_set_common_formats2(ctx, cfg_in, cfg_out, formats); > +} > + > static const AVFilterPad thumbnail_inputs[] = { > { > .name = "default", > @@ -350,5 +373,5 @@ const FFFilter ff_vf_thumbnail = { > .uninit = uninit, > FILTER_INPUTS(thumbnail_inputs), > FILTER_OUTPUTS(thumbnail_outputs), > - FILTER_PIXFMTS_ARRAY(pix_fmts), > + FILTER_QUERY_FUNC2(query_formats), > }; > -- > 2.49.0 > _______________________________________________ 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". ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-06-20 14:16 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2025-06-20 14:13 [FFmpeg-devel] [PATCH v2 0/2] avfilter/vf_thumbnail: support more formats Niklas Haas 2025-06-20 14:13 ` [FFmpeg-devel] [PATCH v2 1/2] avfilter/vf_thumbnail: support more planar formats Niklas Haas 2025-06-20 14:13 ` [FFmpeg-devel] [PATCH v2 2/2] avfilter/vf_thumbnail: switch to query_func2 Niklas Haas 2025-06-20 14:16 ` Niklas Haas
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git