Go to the documentation of this file.
49 int jobnr,
int nb_jobs);
52 #define SQR(x) ((x)*(x))
55 float hue_key,
float sat_key,
float val_key)
57 const float similarity =
s->similarity;
58 const float scale =
s->scale;
59 const float blend =
s->blend;
60 const int imax =
s->max;
61 const float max = imax;
62 const float half =
s->half;
63 const float uf =
u -
half;
64 const float vf = v -
half;
65 const float hue = hue_key < 0.f ? -hue_key :
atan2f(uf, vf) +
M_PI;
66 const float sat = sat_key < 0.f ? -sat_key : sqrtf((uf * uf + vf * vf) / (
half *
half * 2.
f));
67 const float val = val_key < 0.f ? -val_key :
scale * y;
70 hue_key =
fabsf(hue_key);
71 sat_key =
fabsf(sat_key);
72 val_key =
fabsf(val_key);
75 SQR(sat_key) *
SQR(val_key) -
76 2.
f * sat *
val * sat_key * val_key *
cosf(hue_key - hue) +
78 if (
diff < similarity) {
80 }
else if (blend > FLT_MIN) {
93 const int slice_start = (
frame->height * jobnr) / nb_jobs;
95 const int hsub_log2 =
s->hsub_log2;
96 const int vsub_log2 =
s->vsub_log2;
97 const float hue =
s->hue;
98 const float sat =
s->sat;
99 const float val =
s->val;
101 for (
int y = slice_start; y <
slice_end; y++) {
102 for (
int x = 0; x <
frame->width; x++) {
103 int Y =
frame->data[0][
frame->linesize[0] * y + x];
104 int u =
frame->data[1][
frame->linesize[1] * (y >> vsub_log2) + (x >> hsub_log2)];
105 int v =
frame->data[2][
frame->linesize[2] * (y >> vsub_log2) + (x >> hsub_log2)];
118 const int slice_start = (
frame->height * jobnr) / nb_jobs;
120 const int hsub_log2 =
s->hsub_log2;
121 const int vsub_log2 =
s->vsub_log2;
122 const float hue =
s->hue;
123 const float sat =
s->sat;
124 const float val =
s->val;
126 for (
int y = slice_start; y <
slice_end; ++y) {
127 for (
int x = 0; x <
frame->width; ++x) {
128 uint16_t *dst = (uint16_t *)(
frame->data[3] +
frame->linesize[3] * y);
130 int u =
AV_RN16(&
frame->data[1][
frame->linesize[1] * (y >> vsub_log2) + 2 * (x >> hsub_log2)]);
131 int v =
AV_RN16(&
frame->data[2][
frame->linesize[2] * (y >> vsub_log2) + 2 * (x >> hsub_log2)]);
144 const int hsub_log2 =
s->hsub_log2;
145 const int vsub_log2 =
s->vsub_log2;
148 const int slice_start = (
height * jobnr) / nb_jobs;
150 const float scale =
s->scale;
151 const float hue =
s->hue;
152 const float sat =
s->sat;
153 const float val =
s->val;
155 for (
int y = slice_start; y <
slice_end; ++y) {
156 for (
int x = 0; x <
width; ++x) {
157 uint8_t *dstu =
frame->data[1] +
frame->linesize[1] * y;
158 uint8_t *dstv =
frame->data[2] +
frame->linesize[2] * y;
159 int Y =
frame->data[0][
frame->linesize[0] * (y << vsub_log2) + (x << hsub_log2)];
160 int u =
frame->data[1][
frame->linesize[1] * y + x];
161 int v =
frame->data[2][
frame->linesize[2] * y + x];
165 float f = 1.f - t *
scale;
167 dstu[x] = 128 + (
u - 128) *
f;
168 dstv[x] = 128 + (v - 128) *
f;
180 const int hsub_log2 =
s->hsub_log2;
181 const int vsub_log2 =
s->vsub_log2;
184 const int slice_start = (
height * jobnr) / nb_jobs;
186 const float scale =
s->scale;
187 const float half =
s->half;
188 const float hue =
s->hue;
189 const float sat =
s->sat;
190 const float val =
s->val;
192 for (
int y = slice_start; y <
slice_end; ++y) {
193 for (
int x = 0; x <
width; ++x) {
194 uint16_t *dstu = (uint16_t *)(
frame->data[1] +
frame->linesize[1] * y);
195 uint16_t *dstv = (uint16_t *)(
frame->data[2] +
frame->linesize[2] * y);
196 int Y =
AV_RN16(&
frame->data[0][
frame->linesize[0] * (y << vsub_log2) + 2 * (x << hsub_log2)]);
202 float f = 1.f - t *
scale;
233 s->depth =
desc->comp[0].depth;
234 s->max = (1 <<
s->depth) - 1;
235 s->half = 0.5f *
s->max;
236 s->scale = 1.f /
s->max;
253 s->hsub_log2 =
desc->log2_chroma_w;
254 s->vsub_log2 =
desc->log2_chroma_h;
288 #define OFFSET(x) offsetof(HSVKeyContext, x)
289 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
304 .description =
NULL_IF_CONFIG_SMALL(
"Turns a certain HSV range into transparency. Operates on YUV colors."),
306 .priv_class = &hsvkey_class,
366 .priv_class = &hsvhold_class,
#define AV_PIX_FMT_YUVA422P16
AVPixelFormat
Pixel format.
#define u(width, name, range_min, range_max)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define FILTER_PIXFMTS_ARRAY(array)
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
#define AV_PIX_FMT_YUVA422P9
This structure describes decoded (raw) audio or video data.
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUV420P10
static uint8_t half(int a, int b)
const char * name
Filter name.
A link between two filters.
#define AV_PIX_FMT_YUVA422P10
static av_cold int config_input(AVFilterLink *inlink)
#define AV_PIX_FMT_YUVA420P9
AVFILTER_DEFINE_CLASS(hsvkey)
static int do_hsvhold_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
void * priv
private data for use by the filter
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUV422P9
static double val(void *priv, double ch)
static av_always_inline float scale(float x, float s)
static __device__ float fabsf(float a)
A filter pad used for either input or output.
#define AV_PIX_FMT_YUV444P10
static av_cold int config_output(AVFilterLink *outlink)
#define AV_PIX_FMT_YUV422P16
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_PIX_FMT_YUV444P16
static int filter_frame(AVFilterLink *link, AVFrame *frame)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
static int do_hsvkey_pixel(HSVKeyContext *s, int y, int u, int v, float hue_key, float sat_key, float val_key)
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P16
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_INPUTS(array)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
static const AVFilterPad hsvhold_inputs[]
static const AVFilterPad hsvkey_outputs[]
Describe the class of an AVClass context structure.
static int do_hsvhold16_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
static const AVOption hsvkey_options[]
static int do_hsvkey16_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_YUV422P10
static const AVOption hsvhold_options[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
float fmaxf(float, float)
int format
agreed upon media format
#define AV_PIX_FMT_YUV422P12
const AVFilter ff_vf_hsvkey
#define AV_PIX_FMT_YUV444P12
AVFilterContext * src
source filter
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
static int do_hsvkey_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AV_PIX_FMT_YUVA444P10
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
int(* do_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
const AVFilter ff_vf_hsvhold
const char * name
Pad name.
#define AV_PIX_FMT_YUV444P9
static enum AVPixelFormat key_pixel_fmts[]
static const AVFilterPad hsvkey_inputs[]
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUVA422P12
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static enum AVPixelFormat hold_pixel_fmts[]
#define FILTER_OUTPUTS(array)
static const AVFilterPad hsvhold_outputs[]
#define AV_PIX_FMT_YUV444P14
const AVFilter * filter
the AVFilter of which this is an instance
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
#define AV_PIX_FMT_YUV420P14
AVFilterLink ** outputs
array of pointers to output links
#define AVFILTERPAD_FLAG_NEEDS_WRITABLE
The filter expects writable frames from its input link, duplicating data buffers if needed.