From patchwork Sat Aug 21 12:51:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 29667 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp497625iov; Sat, 21 Aug 2021 05:51:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfnGhhp1/Wi8TqoAwejZ6/ajVkAqWjZLTKuSd4qIFqzjj8NW1MQj2UQcYXpSguNZky3YRJ X-Received: by 2002:a05:6402:4d1:: with SMTP id n17mr27163676edw.337.1629550314798; Sat, 21 Aug 2021 05:51:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629550314; cv=none; d=google.com; s=arc-20160816; b=beDSROXX0ip1aY9nWpSLYMJkPhsWhBeQ9n/mznW6DvIDJVsLPV1eXMfXDTsNNEbRN4 2D54Jjqy3ZgfX5rFOowVaWpeoZfcbTFkQ1I7x9X4rz+/ixEGY3IZ5i7PIq8pOBfazVpy Y7SGc/Nezh7qMD0O1RghlfVleTCAQze7+RA+Xjta8EFcx0CxDeHusvpHeDEP6oUvnFHR JWjNqkqEp90nRkqvNd7NDG8nnty9aJMylFhGO5erQnviG0c2wvivERTGxjBHpXnXBDsb Dep5CKBGHs+06CVqtjYEebPgrJzxCk23H594Fh8S2RcQfKT8Q8VZYSmNYykN/iF60edh J03A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to; bh=kTPzuKrL7QjnWrBHGy3HYIcRga80nPotZ5qzFG418KM=; b=GVOXEzWuVkQnyh0q0OOlvqPTfFuNcDMRIT4/k8pSRDGgDUHWYzVUoGMRAoKqNcMB5g OGmlp7LCauP7g9hrKTSqsl6nqUVEfpLT798gDnm6LCF/JMsjAzu5vsxY8wOYUmzoYo+a MDt+9NdVisSXxAAj7ZpyxLgkFQa0nS7dmPJLRZs9mRjtArAh9bpOF99Kc2WqOad+BRdn Qb+3IDL9GjOShbwudzp5H+iPXO+BMK7gmVouSmusMRmCtV9yOQ/+Qo3z8P2HHdo9TliY 2Uo6xVZHr9zNNmR/mO0+eSvJWietA3ad8LF2mZS+g2fwmrTDyssj/EIXyEYhKZbDc96o nLfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=K5z+AXj3; 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 v15si9006696edy.99.2021.08.21.05.51.53; Sat, 21 Aug 2021 05:51:54 -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=20161025 header.b=K5z+AXj3; 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 D3E9C689A81; Sat, 21 Aug 2021 15:51:49 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 920F7689963 for ; Sat, 21 Aug 2021 15:51:43 +0300 (EEST) Received: by mail-wr1-f51.google.com with SMTP id q10so18313317wro.2 for ; Sat, 21 Aug 2021 05:51:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=4iO1t3kfdwFs17SrbsqO77WFqZAViDOXWbx7tzuWsLU=; b=K5z+AXj3EP0JbjqZUFbone7/qiADP/eAQK6KsZcGcGczMjlWvLMt+8pMyM/olGFtGM SaZR1EUuxylKcZ3xyM1Yvue8XErc502oPL0VVMvIrLaMBgLkkAEtikPsn6a0WImOf+JQ 3fY11f3ZvBkAj1GHtDOIUvhrgh533/I2tcARUGKaKo3+1Pbn4JCwJsvTBXUNfVFVBCrB Jp5PEKg/eqyZWWKQ9DTelmUyLBhkiXemvEd4jnVr+te21AAsm+YnEdhtoCsga6yll8Bn sg56FZgYWWYe0Yikf4iK+f56uc+OSq+WJ9x+sRTu2YdjrARM9hZ9b7GbOfTi5vlUmbm3 X9oQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=4iO1t3kfdwFs17SrbsqO77WFqZAViDOXWbx7tzuWsLU=; b=EjhOOgwne/NlpJdCX9s/VxSLcOM7zWTQIE091jp6wERzyKPC6xqamWmJh4n8jbyejz VOPxxsTv40RnNYYjQ6TUXKs+QGjC6yFOHrpEuVucwJkEqmG8+c+I375ZDzoSSGIvDci4 a352U2vtbRZ455wWOSG3MqTAZDx/XKm8KwXrgX8rmwQ/wPlWzntzwGeE6jsDZ3kNLEe8 ooeTccJ3PODM5yP7Fv3zQnP97fCjF88jmRTIweUBQJ2SP6mephE5980ltHEmUgybEoHs QYfh01VVOSRDvwL8qWjsnzUrj56R9KWyGWmX577eb4CX6XGpYdxq4JUHP77seWtq/4YJ rCzQ== X-Gm-Message-State: AOAM531AU27/rb97IkKUuKMwF+IwVoUuGvDqQOO4gju6xMh2qf/aJ6vP efWuvbFjWPfJRYKFug2wTfclr1KGySA= X-Received: by 2002:a5d:4143:: with SMTP id c3mr3894626wrq.29.1629550302535; Sat, 21 Aug 2021 05:51:42 -0700 (PDT) Received: from localhost.localdomain ([95.168.120.15]) by smtp.gmail.com with ESMTPSA id c29sm872476wrb.63.2021.08.21.05.51.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Aug 2021 05:51:41 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Sat, 21 Aug 2021 14:51:32 +0200 Message-Id: <20210821125132.20526-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] avfilter: add hsvkey and hsvhold video filters 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: owYJdBOuSfLN Signed-off-by: Paul B Mahol --- libavfilter/Makefile | 2 + libavfilter/allfilters.c | 2 + libavfilter/vf_hsvkey.c | 380 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 384 insertions(+) create mode 100644 libavfilter/vf_hsvkey.c diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 102ce7beff..3166e70b58 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -296,6 +296,8 @@ OBJS-$(CONFIG_HISTOGRAM_FILTER) += vf_histogram.o OBJS-$(CONFIG_HQDN3D_FILTER) += vf_hqdn3d.o OBJS-$(CONFIG_HQX_FILTER) += vf_hqx.o OBJS-$(CONFIG_HSTACK_FILTER) += vf_stack.o framesync.o +OBJS-$(CONFIG_HSVHOLD_FILTER) += vf_hsvkey.o +OBJS-$(CONFIG_HSVKEY_FILTER) += vf_hsvkey.o OBJS-$(CONFIG_HUE_FILTER) += vf_hue.o OBJS-$(CONFIG_HWDOWNLOAD_FILTER) += vf_hwdownload.o OBJS-$(CONFIG_HWMAP_FILTER) += vf_hwmap.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 73040d2824..c49c831203 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -281,6 +281,8 @@ extern const AVFilter ff_vf_histogram; extern const AVFilter ff_vf_hqdn3d; extern const AVFilter ff_vf_hqx; extern const AVFilter ff_vf_hstack; +extern const AVFilter ff_vf_hsvhold; +extern const AVFilter ff_vf_hsvkey; extern const AVFilter ff_vf_hue; extern const AVFilter ff_vf_hwdownload; extern const AVFilter ff_vf_hwmap; diff --git a/libavfilter/vf_hsvkey.c b/libavfilter/vf_hsvkey.c new file mode 100644 index 0000000000..ec6af0862d --- /dev/null +++ b/libavfilter/vf_hsvkey.c @@ -0,0 +1,380 @@ +/* + * Copyright (c) 2021 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 + +#include "libavutil/opt.h" +#include "libavutil/imgutils.h" +#include "libavutil/intreadwrite.h" +#include "avfilter.h" +#include "formats.h" +#include "internal.h" +#include "video.h" + +typedef struct HSVKeyContext { + const AVClass *class; + + float hue, hue_opt, sat, val; + float similarity; + float blend; + + float scale; + + float half; + + int depth; + int max; + + int hsub_log2; + int vsub_log2; + + int (*do_slice)(AVFilterContext *ctx, void *arg, + int jobnr, int nb_jobs); +} HSVKeyContext; + +#define SQR(x) ((x)*(x)) + +static int do_hsvkey_pixel(HSVKeyContext *s, int y, int u, int v, + float hue_key, float sat_key, float val_key) +{ + const float similarity = s->similarity; + const float scale = s->scale; + const float blend = s->blend; + const int imax = s->max; + const float max = imax; + const float half = s->half; + const float uf = u - half; + const float vf = v - half; + const float hue = atan2f(uf, vf) + M_PI; + const float sat = sqrtf((uf * uf + vf * vf) / (half * half * 2.f)); + const float val = y * scale; + float diff; + + diff = sqrtf(SQR(sat) * SQR(val) + + SQR(sat_key) * SQR(val_key) - + 2.f * sat * val * sat_key * val_key * cosf(hue_key - hue) + + SQR(val - val_key)); + if (diff < similarity) { + return 0; + } else if (blend > 0.000001f) { + return av_clipf((diff - similarity) / blend, 0.f, 1.f) * max; + } else { + return imax; + } + + return 0; +} + +static int do_hsvkey_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs) +{ + HSVKeyContext *s = avctx->priv; + AVFrame *frame = arg; + const int slice_start = (frame->height * jobnr) / nb_jobs; + const int slice_end = (frame->height * (jobnr + 1)) / nb_jobs; + const int hsub_log2 = s->hsub_log2; + const int vsub_log2 = s->vsub_log2; + const float hue = s->hue; + const float sat = s->sat; + const float val = s->val; + + for (int y = slice_start; y < slice_end; y++) { + for (int x = 0; x < frame->width; x++) { + int Y = frame->data[0][frame->linesize[0] * y + x]; + int u = frame->data[1][frame->linesize[1] * (y >> vsub_log2) + (x >> hsub_log2)]; + int v = frame->data[2][frame->linesize[2] * (y >> vsub_log2) + (x >> hsub_log2)]; + + frame->data[3][frame->linesize[3] * y + x] = do_hsvkey_pixel(s, Y, u, v, hue, sat, val); + } + } + + return 0; +} + +static int do_hsvkey16_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs) +{ + HSVKeyContext *s = avctx->priv; + AVFrame *frame = arg; + const int slice_start = (frame->height * jobnr) / nb_jobs; + const int slice_end = (frame->height * (jobnr + 1)) / nb_jobs; + const int hsub_log2 = s->hsub_log2; + const int vsub_log2 = s->vsub_log2; + const float hue = s->hue; + const float sat = s->sat; + const float val = s->val; + + for (int y = slice_start; y < slice_end; ++y) { + for (int x = 0; x < frame->width; ++x) { + uint16_t *dst = (uint16_t *)(frame->data[3] + frame->linesize[3] * y); + int Y = AV_RN16(&frame->data[0][frame->linesize[0] * y + 2 * x]); + int u = AV_RN16(&frame->data[1][frame->linesize[1] * (y >> vsub_log2) + 2 * (x >> hsub_log2)]); + int v = AV_RN16(&frame->data[2][frame->linesize[2] * (y >> vsub_log2) + 2 * (x >> hsub_log2)]); + + dst[x] = do_hsvkey_pixel(s, Y, u, v, hue, sat, val); + } + } + + return 0; +} + +static int do_hsvhold_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs) +{ + HSVKeyContext *s = avctx->priv; + AVFrame *frame = arg; + const int hsub_log2 = s->hsub_log2; + const int vsub_log2 = s->vsub_log2; + const int width = frame->width >> hsub_log2; + const int height = frame->height >> vsub_log2; + const int slice_start = (height * jobnr) / nb_jobs; + const int slice_end = (height * (jobnr + 1)) / nb_jobs; + const float scale = s->scale; + const float hue = s->hue; + const float sat = s->sat; + const float val = s->val; + + for (int y = slice_start; y < slice_end; ++y) { + for (int x = 0; x < width; ++x) { + uint8_t *dstu = frame->data[1] + frame->linesize[1] * y; + uint8_t *dstv = frame->data[2] + frame->linesize[2] * y; + int Y = frame->data[0][frame->linesize[0] * (y << vsub_log2) + (x << hsub_log2)]; + int u = frame->data[1][frame->linesize[1] * y + x]; + int v = frame->data[2][frame->linesize[2] * y + x]; + int t = do_hsvkey_pixel(s, Y, u, v, hue, sat, val); + + if (t > 0) { + float f = 1.f - t * scale; + + dstu[x] = 128 + (u - 128) * f; + dstv[x] = 128 + (v - 128) * f; + } + } + } + + return 0; +} + +static int do_hsvhold16_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs) +{ + HSVKeyContext *s = avctx->priv; + AVFrame *frame = arg; + const int hsub_log2 = s->hsub_log2; + const int vsub_log2 = s->vsub_log2; + const int width = frame->width >> hsub_log2; + const int height = frame->height >> vsub_log2; + const int slice_start = (height * jobnr) / nb_jobs; + const int slice_end = (height * (jobnr + 1)) / nb_jobs; + const float scale = s->scale; + const float half = s->half; + const float hue = s->hue; + const float sat = s->sat; + const float val = s->val; + + for (int y = slice_start; y < slice_end; ++y) { + for (int x = 0; x < width; ++x) { + uint16_t *dstu = (uint16_t *)(frame->data[1] + frame->linesize[1] * y); + uint16_t *dstv = (uint16_t *)(frame->data[2] + frame->linesize[2] * y); + int Y = AV_RN16(&frame->data[0][frame->linesize[0] * (y << vsub_log2) + 2 * (x << hsub_log2)]); + int u = AV_RN16(&frame->data[1][frame->linesize[1] * y + 2 * x]); + int v = AV_RN16(&frame->data[2][frame->linesize[2] * y + 2 * x]); + int t = do_hsvkey_pixel(s, Y, u, v, hue, sat, val); + + if (t > 0) { + float f = 1.f - t * scale; + + dstu[x] = half + (u - half) * f; + dstv[x] = half + (v - half) * f; + } + } + } + + return 0; +} + +static int filter_frame(AVFilterLink *link, AVFrame *frame) +{ + AVFilterContext *avctx = link->dst; + HSVKeyContext *s = avctx->priv; + int res; + + s->hue = M_PI * fmodf(526.f - s->hue_opt, 360.f) / 180.f; + if (res = ff_filter_execute(avctx, s->do_slice, frame, NULL, + FFMIN(frame->height, ff_filter_get_nb_threads(avctx)))) + return res; + + return ff_filter_frame(avctx->outputs[0], frame); +} + +static av_cold int config_output(AVFilterLink *outlink) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format); + AVFilterContext *avctx = outlink->src; + HSVKeyContext *s = avctx->priv; + + s->depth = desc->comp[0].depth; + s->max = (1 << s->depth) - 1; + s->half = 0.5f * s->max; + s->scale = 1.f / s->max; + + if (!strcmp(avctx->filter->name, "hsvkey")) { + s->do_slice = s->depth <= 8 ? do_hsvkey_slice : do_hsvkey16_slice; + } else { + s->do_slice = s->depth <= 8 ? do_hsvhold_slice: do_hsvhold16_slice; + } + + return 0; +} + +static av_cold int query_formats(AVFilterContext *avctx) +{ + static const enum AVPixelFormat pixel_fmts[] = { + AV_PIX_FMT_YUVA420P, + AV_PIX_FMT_YUVA422P, + AV_PIX_FMT_YUVA444P, + AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA444P9, + AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA444P10, + AV_PIX_FMT_YUVA422P12, AV_PIX_FMT_YUVA444P12, + AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16, + AV_PIX_FMT_NONE + }; + + static const enum AVPixelFormat hold_pixel_fmts[] = { + AV_PIX_FMT_YUV420P, + AV_PIX_FMT_YUV422P, + AV_PIX_FMT_YUV444P, + AV_PIX_FMT_YUVA420P, + AV_PIX_FMT_YUVA422P, + AV_PIX_FMT_YUVA444P, + 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_YUV444P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV420P12, + 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_YUVA420P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA444P9, + AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA444P10, + AV_PIX_FMT_YUVA422P12, AV_PIX_FMT_YUVA444P12, + AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16, + AV_PIX_FMT_NONE + }; + const enum AVPixelFormat *pix_fmts; + + pix_fmts = !strcmp(avctx->filter->name, "hsvhold") ? hold_pixel_fmts : pixel_fmts; + + return ff_set_common_formats_from_list(avctx, pix_fmts); +} + +static av_cold int config_input(AVFilterLink *inlink) +{ + AVFilterContext *avctx = inlink->dst; + HSVKeyContext *s = avctx->priv; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); + + s->hsub_log2 = desc->log2_chroma_w; + s->vsub_log2 = desc->log2_chroma_h; + + return 0; +} + +static const AVFilterPad hsvkey_inputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .flags = AVFILTERPAD_FLAG_NEEDS_WRITABLE, + .filter_frame = filter_frame, + .config_props = config_input, + }, + { NULL } +}; + +static const AVFilterPad hsvkey_outputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_output, + }, + { NULL } +}; + +#define OFFSET(x) offsetof(HSVKeyContext, x) +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM + +static const AVOption hsvkey_options[] = { + { "hue", "set the hue value", OFFSET(hue_opt), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, 360, FLAGS }, + { "sat", "set the saturation value", OFFSET(sat), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, 1, FLAGS }, + { "val", "set the value value", OFFSET(val), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, 1, FLAGS }, + { "similarity", "set the hsvkey similarity value", OFFSET(similarity), AV_OPT_TYPE_FLOAT, { .dbl = 0.01}, 0.00001, 1.0, FLAGS }, + { "blend", "set the hsvkey blend value", OFFSET(blend), AV_OPT_TYPE_FLOAT, { .dbl = 0.0 }, 0.0, 1.0, FLAGS }, + { NULL } +}; + +AVFILTER_DEFINE_CLASS(hsvkey); + +const AVFilter ff_vf_hsvkey = { + .name = "hsvkey", + .description = NULL_IF_CONFIG_SMALL("Turns a certain HSV range into transparency. Operates on YUV colors."), + .priv_size = sizeof(HSVKeyContext), + .priv_class = &hsvkey_class, + .query_formats = query_formats, + .inputs = hsvkey_inputs, + .outputs = hsvkey_outputs, + .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS, + .process_command = ff_filter_process_command, +}; + +static const AVOption hsvhold_options[] = { + { "hue", "set the hue value", OFFSET(hue_opt), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, 360, FLAGS }, + { "sat", "set the saturation value", OFFSET(sat), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, 1, FLAGS }, + { "val", "set the value value", OFFSET(val), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, 0, 1, FLAGS }, + { "similarity", "set the hsvhold similarity value", OFFSET(similarity), AV_OPT_TYPE_FLOAT, { .dbl = 0.01 }, 0.00001, 1.0, FLAGS }, + { "blend", "set the hsvhold blend value", OFFSET(blend), AV_OPT_TYPE_FLOAT, { .dbl = 0.0 }, 0.0, 1.0, FLAGS }, + { NULL } +}; + +static const AVFilterPad hsvhold_inputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .flags = AVFILTERPAD_FLAG_NEEDS_WRITABLE, + .filter_frame = filter_frame, + .config_props = config_input, + }, + { NULL } +}; + +static const AVFilterPad hsvhold_outputs[] = { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_output, + }, + { NULL } +}; + +AVFILTER_DEFINE_CLASS(hsvhold); + +const AVFilter ff_vf_hsvhold = { + .name = "hsvhold", + .description = NULL_IF_CONFIG_SMALL("Turns a certain HSV range into gray."), + .priv_size = sizeof(HSVKeyContext), + .priv_class = &hsvhold_class, + .query_formats = query_formats, + .inputs = hsvhold_inputs, + .outputs = hsvhold_outputs, + .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS, + .process_command = ff_filter_process_command, +};