From patchwork Tue Apr 12 08:28:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 35288 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:671c:b0:7c:62c8:b2d1 with SMTP id q28csp1457559pzh; Tue, 12 Apr 2022 01:26:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzq4Y5Njny0ROsMnXP2NJdTuegVJ+JHc0DcVgmqmUS1PgW2ECnHqdsiiyvd01ClR1qesh2J X-Received: by 2002:a05:6402:28b6:b0:41d:8c2e:c97e with SMTP id eg54-20020a05640228b600b0041d8c2ec97emr4037943edb.45.1649751996354; Tue, 12 Apr 2022 01:26:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649751996; cv=none; d=google.com; s=arc-20160816; b=jnz9I5i18jVQyjmORqjpG3JCbDnDG4cuPwNGB6QK5p4gIRY3SWFPy+Ch57CCpuwpg2 4UV+hWQqKtupfvs+tgjltkpJIgaRFID7qzODft1N5J7CT7ij8g2vlk5KpHbaXUQIGIWH EJ3bLrRhTuJ+RXknWk8RbCs3T2rIh5dvTFq1t3waMhRQYBKdR3rHKAuwh7CaFSd/a72g 0W6funD8PQtdCPlnalcuKZcpxaheQOL5Ec6eWNbJ4hRidif2mOHr3oB5dwNX1WHRh3EY 3ojrnOTvmxIxsIRN9kCdQrB4Gibj/E0bM9N00q7z8klXCl767fUIgCVPRhtQeXuRUrTj LVZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=5aEKCzcbQCHmBnSbXRYGP2ndVIFFkkMTikxTosl8feI=; b=sieAU/QT5FI5fzJA/X0zrSuzfUoQ1uGWD7scWuJwjk8w3Ozv4SMTD473Z1q+8nuSUT 9mJY5YfaP6Z+6Q2fCGxBZZM8M0n7jvdD4GueOJClwlW/dByMxz7TtHjv0qGdVThzPBrs KTueCIFhuw0bltvOB4lL2FZhH5zfz974NpdLc0Mud1OXZcZtLuOFyDpOS4VkhrMwaKqk S3vCV1D+LVh5xt8ZaCKkrlh6QAJmNDC+pIWrRm/SZpJmRo6NtXJH8mh25F7XUFwwEN2V 5iJzghl49XmtqvCEl7iQ6/ALVqTO7OsaAxGxyXirz8U8QC12LXybywivWfPB7e4I/Bed KTHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=UpoOrkUz; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d9-20020a50e409000000b00418c2b5bd47si9416214edm.41.2022.04.12.01.26.35; Tue, 12 Apr 2022 01:26:36 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=UpoOrkUz; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0CE9A68B3A4; Tue, 12 Apr 2022 11:26:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0D44268B2F5 for ; Tue, 12 Apr 2022 11:26:27 +0300 (EEST) Received: by mail-wm1-f42.google.com with SMTP id v64-20020a1cac43000000b0038cfd1b3a6dso1194901wme.5 for ; Tue, 12 Apr 2022 01:26:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=SW7/09bc4VVHN23mS512oK+3XX6wPw+Ki7EDvchrFkE=; b=UpoOrkUzanBf2Os7HDjZGJvMFwYxoIF3K1Umh7R4Px6dFWneb8zEFv1nXmv9L6vb+w HHL2JIHSY0QqDc3XmrWXUZRi/PImdzI8tXEDmEezeynYvorPROvagH3RI5oUbMwamYLZ wID7E7gL5wjWS79i6FvXhf567kB8pQBKZHuFM/zOlCHKkbJS7aAePRWok7D58CAlnqPH FXfkf0WV0TOmD+1ovjq5EzjvxC80LuH8s/NHd6P+UbpDfHTrNMUOX5wf655JZb/x6mRG YZrGeoN99129bMIbj+h57RVxoTddLL3lDTd6zOgithafTj4Bzk0T9r2Ceecqa8BqiwZK fpPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=SW7/09bc4VVHN23mS512oK+3XX6wPw+Ki7EDvchrFkE=; b=ugBUdFZ+PGP9iu03gYRPni4LCAkZTGq3Zd+wF7EFbBYaxOVWzD71vaAtXhzw5Dpe/i Y8y65VUMQdAK5ztC+XqJlzWfIfuUj5LuqwubTYHnV3QyFRIK/+XUlEtt+ohRCOrxNR0B TGJis+jTMRHZuey+1QGH3GAzaISEfWGxvnTEHFm9X53tQCORqJrPX0hQQLfBKw6MzgZ0 QLbsGhNmmi6lDSagSV3x6UBk1PmDu8DN9C1zCURCOU+AHHcVpAtm9BzE9KWzwSsgfXrr n0xfJy+R6HRDN5pGHmimXUA1kpuwslMtJarDWpeJPKKYS/mg+bp3Gs9CEeElN+YBp5Ee NnnA== X-Gm-Message-State: AOAM531RFVziY6A3EqcSsS8PXs9xFPHslvXwxck+idd2Ha1OOTcboXlP X1eH7quxwRIm02Z3vcqHWPCLoxUKbh4= X-Received: by 2002:a05:600c:3c9b:b0:38e:4c59:68b9 with SMTP id bg27-20020a05600c3c9b00b0038e4c5968b9mr2977745wmb.105.1649751986361; Tue, 12 Apr 2022 01:26:26 -0700 (PDT) Received: from localhost.localdomain ([95.168.121.46]) by smtp.gmail.com with ESMTPSA id c24-20020a7bc018000000b0038a18068cf5sm1709560wmb.15.2022.04.12.01.26.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 01:26:25 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Tue, 12 Apr 2022 10:28:47 +0200 Message-Id: <20220412082847.120415-1-onemda@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avfilter: add pixelize video filter 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: JkRqMeGprWCb Signed-off-by: Paul B Mahol --- doc/filters.texi | 29 ++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_pixelize.c | 348 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 379 insertions(+) create mode 100644 libavfilter/vf_pixelize.c diff --git a/doc/filters.texi b/doc/filters.texi index de2b674ba2..e3d45daa99 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -17892,6 +17892,35 @@ format=monow, pixdesctest can be used to test the monowhite pixel format descriptor definition. +@section pixelize +Apply pixelization to video stream. + +The filter accepts the following options: +@table @option +@item width, w +@item height, h +Set block dimensions that will be used for pixelization. +Default value is @code{16}. + +@item mode, m +Set the mode of pixelization used. + +Possible values are: +@table @samp +@item avg +@item min +@item max +@end table +Default value is @code{avg}. + +@item planes, p +Set what planes to filter. Default is to filter all planes. +@end table + +@subsection Commands + +This filter supports all options as @ref{commands}. + @section pixscope Display sample values of color channels. Mainly useful for checking color diff --git a/libavfilter/Makefile b/libavfilter/Makefile index bdfdfdc04a..945ce6c4cd 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -393,6 +393,7 @@ OBJS-$(CONFIG_PERSPECTIVE_FILTER) += vf_perspective.o OBJS-$(CONFIG_PHASE_FILTER) += vf_phase.o OBJS-$(CONFIG_PHOTOSENSITIVITY_FILTER) += vf_photosensitivity.o OBJS-$(CONFIG_PIXDESCTEST_FILTER) += vf_pixdesctest.o +OBJS-$(CONFIG_PIXELIZE_FILTER) += vf_pixelize.o OBJS-$(CONFIG_PIXSCOPE_FILTER) += vf_datascope.o OBJS-$(CONFIG_PP_FILTER) += vf_pp.o qp_table.o OBJS-$(CONFIG_PP7_FILTER) += vf_pp7.o qp_table.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 44fac46521..494ef32937 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -375,6 +375,7 @@ extern const AVFilter ff_vf_perspective; extern const AVFilter ff_vf_phase; extern const AVFilter ff_vf_photosensitivity; extern const AVFilter ff_vf_pixdesctest; +extern const AVFilter ff_vf_pixelize; extern const AVFilter ff_vf_pixscope; extern const AVFilter ff_vf_pp; extern const AVFilter ff_vf_pp7; diff --git a/libavfilter/vf_pixelize.c b/libavfilter/vf_pixelize.c new file mode 100644 index 0000000000..3be0a9cca7 --- /dev/null +++ b/libavfilter/vf_pixelize.c @@ -0,0 +1,348 @@ +/* + * Copyright (c) 2022 Paul B Mahol + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/common.h" +#include "libavutil/internal.h" +#include "libavutil/imgutils.h" +#include "libavutil/lfg.h" +#include "libavutil/opt.h" +#include "libavutil/pixdesc.h" +#include "libavutil/random_seed.h" + +#include "avfilter.h" +#include "internal.h" +#include "video.h" + +enum PixelizeModes { + PIXELIZE_AVG, + PIXELIZE_MIN, + PIXELIZE_MAX, + PIXELIZE_MODES +}; + +typedef struct PixelizeContext { + const AVClass *class; + + int block_w[4], block_h[4]; + int mode; + + int depth; + int planes; + int nb_planes; + int linesize[4]; + int planewidth[4]; + int planeheight[4]; + + int (*pixelize[PIXELIZE_MODES])(const uint8_t *src, uint8_t *dst, + ptrdiff_t src_linesize, + ptrdiff_t dst_linesize, + int w, int h); +} PixelizeContext; + +static const enum AVPixelFormat pix_fmts[] = { + AV_PIX_FMT_GRAY8, + AV_PIX_FMT_GRAY9, + AV_PIX_FMT_GRAY10, + AV_PIX_FMT_GRAY12, + AV_PIX_FMT_GRAY14, + AV_PIX_FMT_GRAY16, + 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_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9, + AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10, + AV_PIX_FMT_YUV440P10, + AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, + AV_PIX_FMT_YUV440P12, + AV_PIX_FMT_YUV444P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV420P14, + AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16, + AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, + AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16, + AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P, + AV_PIX_FMT_YUVA444P9, AV_PIX_FMT_YUVA444P10, AV_PIX_FMT_YUVA444P12, AV_PIX_FMT_YUVA444P16, + AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA422P12, AV_PIX_FMT_YUVA422P16, + AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA420P16, + AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP16, + AV_PIX_FMT_NONE +}; + +typedef struct ThreadData { + AVFrame *in, *out; +} ThreadData; + +#define PIXELIZE_AVG(name, type, stype) \ +static int pixelize_avg##name(const uint8_t *ssrc, uint8_t *ddst, \ + ptrdiff_t src_linesize, ptrdiff_t dst_linesize, \ + int w, int h) \ +{ \ + const type *src = (const type *)ssrc; \ + type *dst = (type *)ddst; \ + stype sum = 0; \ + type fill; \ + for (int y = 0; y < h; y++) { \ + for (int x = 0; x < w; x++) \ + sum += src[x]; \ + \ + src += src_linesize / sizeof(type); \ + } \ + \ + fill = sum / (w * h); \ + \ + for (int y = 0; y < h; y++) { \ + for (int x = 0; x < w; x++) \ + dst[x] = fill; \ + \ + dst += dst_linesize / sizeof(type); \ + } \ + \ + return 0; \ +} + +#define PIXELIZE_MIN(name, type, stype) \ +static int pixelize_min##name(const uint8_t *ssrc, uint8_t *ddst, \ + ptrdiff_t src_linesize, ptrdiff_t dst_linesize, \ + int w, int h) \ +{ \ + const type *src = (const type *)ssrc; \ + type *dst = (type *)ddst; \ + type fill = src[0]; \ + \ + for (int y = 0; y < h; y++) { \ + for (int x = 0; x < w; x++) \ + fill = FFMIN(src[x], fill); \ + \ + src += src_linesize / sizeof(type); \ + } \ + \ + for (int y = 0; y < h; y++) { \ + for (int x = 0; x < w; x++) \ + dst[x] = fill; \ + \ + dst += dst_linesize / sizeof(type); \ + } \ + \ + return 0; \ +} + +#define PIXELIZE_MAX(name, type, stype) \ +static int pixelize_max##name(const uint8_t *ssrc, uint8_t *ddst, \ + ptrdiff_t src_linesize, ptrdiff_t dst_linesize, \ + int w, int h) \ +{ \ + const type *src = (const type *)ssrc; \ + type *dst = (type *)ddst; \ + type fill = src[0]; \ + \ + for (int y = 0; y < h; y++) { \ + for (int x = 0; x < w; x++) \ + fill = FFMAX(src[x], fill); \ + \ + src += src_linesize / sizeof(type); \ + } \ + \ + for (int y = 0; y < h; y++) { \ + for (int x = 0; x < w; x++) \ + dst[x] = fill; \ + \ + dst += dst_linesize / sizeof(type); \ + } \ + \ + return 0; \ +} + +PIXELIZE_AVG(8, uint8_t, unsigned) +PIXELIZE_AVG(16, uint16_t, uint64_t) +PIXELIZE_MIN(8, uint8_t, unsigned) +PIXELIZE_MIN(16, uint16_t, uint64_t) +PIXELIZE_MAX(8, uint8_t, unsigned) +PIXELIZE_MAX(16, uint16_t, uint64_t) + +static int pixelize_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) +{ + PixelizeContext *s = ctx->priv; + const int mode = s->mode; + ThreadData *td = arg; + AVFrame *out = td->out; + AVFrame *in = td->in; + + for (int p = 0; p < s->nb_planes; p++) { + const int wh = s->planeheight[p]; + const int h = (s->planeheight[p] + s->block_h[p] - 1) / s->block_h[p]; + const int w = (s->planewidth[p] + s->block_w[p] - 1) / s->block_w[p]; + const int wslice_start = (wh * jobnr) / nb_jobs; + const int wslice_end = (wh * (jobnr+1)) / nb_jobs; + const int slice_start = (h * jobnr) / nb_jobs; + const int slice_end = (h * (jobnr+1)) / nb_jobs; + const ptrdiff_t out_linesize = out->linesize[p]; + const ptrdiff_t in_linesize = in->linesize[p]; + const uint8_t *src = in->data[p]; + uint8_t *dst = out->data[p]; + + if (!((1 << p) & s->planes)) { + av_image_copy_plane(dst + wslice_start * out_linesize, + out_linesize, + src + wslice_start * in_linesize, + in_linesize, + s->linesize[p], wslice_end - wslice_start); + continue; + } + + for (int y = slice_start; y < slice_end; y++) { + const int block_h = FFMIN(s->block_h[p], s->planeheight[p] - y * s->block_h[p]); + for (int x = 0; x < w; x++) { + const int block_w = FFMIN(s->block_w[p], s->planewidth[p] - x * s->block_w[p]); + + s->pixelize[mode](src + s->block_h[p] * y * in_linesize + + x * s->block_w[p] * (1 + (s->depth > 8)), + dst + s->block_h[p] * y * out_linesize + + x * s->block_w[p] * (1 + (s->depth > 8)), + in_linesize, out_linesize, block_w, block_h); + } + } + } + + return 0; +} + +static int config_output(AVFilterLink *outlink) +{ + AVFilterContext *ctx = outlink->src; + PixelizeContext *s = ctx->priv; + AVFilterLink *inlink = ctx->inputs[0]; + const AVPixFmtDescriptor *desc; + int ret; + + desc = av_pix_fmt_desc_get(outlink->format); + if (!desc) + return AVERROR_BUG; + s->nb_planes = av_pix_fmt_count_planes(outlink->format); + s->depth = desc->comp[0].depth; + + if ((ret = av_image_fill_linesizes(s->linesize, inlink->format, inlink->w)) < 0) + return ret; + + s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); + 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->block_w[1] = s->block_w[2] = s->block_w[0] >> desc->log2_chroma_w; + s->block_w[3] = s->block_w[0]; + + s->block_h[1] = s->block_h[2] = s->block_h[0] >> desc->log2_chroma_h; + s->block_h[3] = s->block_h[0]; + + s->pixelize[PIXELIZE_AVG] = s->depth <= 8 ? pixelize_avg8 : pixelize_avg16; + s->pixelize[PIXELIZE_MIN] = s->depth <= 8 ? pixelize_min8 : pixelize_min16; + s->pixelize[PIXELIZE_MAX] = s->depth <= 8 ? pixelize_max8 : pixelize_max16; + + return 0; +} + +static int filter_frame(AVFilterLink *inlink, AVFrame *in) +{ + AVFilterContext *ctx = inlink->dst; + AVFilterLink *outlink = ctx->outputs[0]; + PixelizeContext *s = ctx->priv; + ThreadData td; + AVFrame *out; + int ret; + + if (av_frame_is_writable(in)) { + out = in; + } else { + out = ff_get_video_buffer(outlink, outlink->w, outlink->h); + if (!out) { + ret = AVERROR(ENOMEM); + goto fail; + } + + ret = av_frame_copy_props(out, in); + if (ret < 0) { + av_frame_free(&out); + goto fail; + } + } + + td.out = out; + td.in = in; + ff_filter_execute(ctx, pixelize_slice, &td, NULL, + FFMIN((s->planeheight[1] + s->block_h[1] - 1) / s->block_h[1], + ff_filter_get_nb_threads(ctx))); + + if (out != in) + av_frame_free(&in); + return ff_filter_frame(outlink, out); +fail: + av_frame_free(&in); + return ret; +} + +#define OFFSET(x) offsetof(PixelizeContext, x) +#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_RUNTIME_PARAM) + +static const AVOption pixelize_options[] = { + { "width", "set block width", OFFSET(block_w[0]), AV_OPT_TYPE_INT, {.i64=16}, 1, 1024, FLAGS }, + { "w", "set block width", OFFSET(block_w[0]), AV_OPT_TYPE_INT, {.i64=16}, 1, 1024, FLAGS }, + { "height", "set block height", OFFSET(block_h[0]), AV_OPT_TYPE_INT, {.i64=16}, 1, 1024, FLAGS }, + { "h", "set block height", OFFSET(block_h[0]), AV_OPT_TYPE_INT, {.i64=16}, 1, 1024, FLAGS }, + { "mode", "set the pixelize mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, PIXELIZE_MODES-1, FLAGS, "mode" }, + { "m", "set the pixelize mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=0}, 0, PIXELIZE_MODES-1, FLAGS, "mode" }, + { "avg", "average", 0, AV_OPT_TYPE_CONST, {.i64=PIXELIZE_AVG}, 0, 0, FLAGS, "mode" }, + { "min", "minimum", 0, AV_OPT_TYPE_CONST, {.i64=PIXELIZE_MIN}, 0, 0, FLAGS, "mode" }, + { "max", "maximum", 0, AV_OPT_TYPE_CONST, {.i64=PIXELIZE_MAX}, 0, 0, FLAGS, "mode" }, + { "planes", "set what planes to filter", OFFSET(planes), AV_OPT_TYPE_FLAGS, {.i64=15}, 0, 15, FLAGS }, + { "p", "set what planes to filter", OFFSET(planes), AV_OPT_TYPE_FLAGS, {.i64=15}, 0, 15, FLAGS }, + { NULL }, +}; + +AVFILTER_DEFINE_CLASS(pixelize); + +static const AVFilterPad pixelize_inputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .filter_frame = filter_frame, + }, +}; + +static const AVFilterPad pixelize_outputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_output, + }, +}; + +const AVFilter ff_vf_pixelize = { + .name = "pixelize", + .description = NULL_IF_CONFIG_SMALL("Pixelize video."), + .priv_size = sizeof(PixelizeContext), + .priv_class = &pixelize_class, + FILTER_INPUTS(pixelize_inputs), + FILTER_OUTPUTS(pixelize_outputs), + FILTER_PIXFMTS_ARRAY(pix_fmts), + .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS, + .process_command = ff_filter_process_command, +};