FFmpeg
vf_chromakey.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Timo Rothenpieler <timo@rothenpieler.org>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/opt.h"
22 #include "libavutil/imgutils.h"
23 #include "libavutil/intreadwrite.h"
24 #include "avfilter.h"
25 #include "formats.h"
26 #include "internal.h"
27 #include "video.h"
28 
29 typedef struct ChromakeyContext {
30  const AVClass *class;
31 
33  uint16_t chromakey_uv[2];
34 
35  float similarity;
36  float blend;
37 
38  int is_yuv;
39  int depth;
40  int mid;
41  int max;
42 
43  int hsub_log2;
44  int vsub_log2;
45 
47  int jobnr, int nb_jobs);
49 
51 {
52  double diff = 0.0;
53  int du, dv, i;
54 
55  for (i = 0; i < 9; ++i) {
56  du = (int)u[i] - ctx->chromakey_uv[0];
57  dv = (int)v[i] - ctx->chromakey_uv[1];
58 
59  diff += sqrt((du * du + dv * dv) / (255.0 * 255.0 * 2));
60  }
61 
62  diff /= 9.0;
63 
64  if (ctx->blend > 0.0001) {
65  return av_clipd((diff - ctx->similarity) / ctx->blend, 0.0, 1.0) * 255.0;
66  } else {
67  return (diff > ctx->similarity) ? 255 : 0;
68  }
69 }
70 
71 static uint16_t do_chromakey_pixel16(ChromakeyContext *ctx, uint16_t u[9], uint16_t v[9])
72 {
73  double max = ctx->max;
74  double diff = 0.0;
75  int du, dv, i;
76 
77  for (i = 0; i < 9; ++i) {
78  du = (int)u[i] - ctx->chromakey_uv[0];
79  dv = (int)v[i] - ctx->chromakey_uv[1];
80 
81  diff += sqrt((du * du + dv * dv) / (max * max * 2));
82  }
83 
84  diff /= 9.0;
85 
86  if (ctx->blend > 0.0001) {
87  return av_clipd((diff - ctx->similarity) / ctx->blend, 0.0, 1.0) * max;
88  } else {
89  return (diff > ctx->similarity) ? max : 0;
90  }
91 }
92 
93 static av_always_inline void get_pixel_uv(AVFrame *frame, int hsub_log2, int vsub_log2, int x, int y, uint8_t *u, uint8_t *v)
94 {
95  if (x < 0 || x >= frame->width || y < 0 || y >= frame->height)
96  return;
97 
98  x >>= hsub_log2;
99  y >>= vsub_log2;
100 
101  *u = frame->data[1][frame->linesize[1] * y + x];
102  *v = frame->data[2][frame->linesize[2] * y + x];
103 }
104 
105 static av_always_inline void get_pixel16_uv(AVFrame *frame, int hsub_log2, int vsub_log2, int x, int y, uint16_t *u, uint16_t *v)
106 {
107  if (x < 0 || x >= frame->width || y < 0 || y >= frame->height)
108  return;
109 
110  x >>= hsub_log2;
111  y >>= vsub_log2;
112 
113  *u = AV_RN16(&frame->data[1][frame->linesize[1] * y + 2 * x]);
114  *v = AV_RN16(&frame->data[2][frame->linesize[2] * y + 2 * x]);
115 }
116 
117 static int do_chromakey_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
118 {
119  AVFrame *frame = arg;
120 
121  const int slice_start = (frame->height * jobnr) / nb_jobs;
122  const int slice_end = (frame->height * (jobnr + 1)) / nb_jobs;
123 
124  ChromakeyContext *ctx = avctx->priv;
125 
126  int x, y, xo, yo;
127  uint8_t u[9], v[9];
128 
129  memset(u, ctx->chromakey_uv[0], sizeof(u));
130  memset(v, ctx->chromakey_uv[1], sizeof(v));
131 
132  for (y = slice_start; y < slice_end; ++y) {
133  for (x = 0; x < frame->width; ++x) {
134  for (yo = 0; yo < 3; ++yo) {
135  for (xo = 0; xo < 3; ++xo) {
136  get_pixel_uv(frame, ctx->hsub_log2, ctx->vsub_log2, x + xo - 1, y + yo - 1, &u[yo * 3 + xo], &v[yo * 3 + xo]);
137  }
138  }
139 
140  frame->data[3][frame->linesize[3] * y + x] = do_chromakey_pixel(ctx, u, v);
141  }
142  }
143 
144  return 0;
145 }
146 
147 static int do_chromakey16_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
148 {
149  AVFrame *frame = arg;
150 
151  const int slice_start = (frame->height * jobnr) / nb_jobs;
152  const int slice_end = (frame->height * (jobnr + 1)) / nb_jobs;
153 
154  ChromakeyContext *ctx = avctx->priv;
155 
156  int x, y, xo, yo;
157  uint16_t u[9], v[9];
158 
159  for (int i = 0; i < 9; i++) {
160  u[i] = ctx->chromakey_uv[0];
161  v[i] = ctx->chromakey_uv[1];
162  }
163 
164  for (y = slice_start; y < slice_end; ++y) {
165  for (x = 0; x < frame->width; ++x) {
166  uint16_t *dst = (uint16_t *)(frame->data[3] + frame->linesize[3] * y);
167 
168  for (yo = 0; yo < 3; ++yo) {
169  for (xo = 0; xo < 3; ++xo) {
170  get_pixel16_uv(frame, ctx->hsub_log2, ctx->vsub_log2, x + xo - 1, y + yo - 1, &u[yo * 3 + xo], &v[yo * 3 + xo]);
171  }
172  }
173 
174  dst[x] = do_chromakey_pixel16(ctx, u, v);
175  }
176  }
177 
178  return 0;
179 }
180 
181 static int do_chromahold_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
182 {
183  ChromakeyContext *ctx = avctx->priv;
184  AVFrame *frame = arg;
185  const int slice_start = ((frame->height >> ctx->vsub_log2) * jobnr) / nb_jobs;
186  const int slice_end = ((frame->height >> ctx->vsub_log2) * (jobnr + 1)) / nb_jobs;
187 
188  int x, y, alpha;
189 
190  for (y = slice_start; y < slice_end; ++y) {
191  for (x = 0; x < frame->width >> ctx->hsub_log2; ++x) {
192  int u = frame->data[1][frame->linesize[1] * y + x];
193  int v = frame->data[2][frame->linesize[2] * y + x];
194  double diff;
195  int du, dv;
196 
197  du = u - ctx->chromakey_uv[0];
198  dv = v - ctx->chromakey_uv[1];
199 
200  diff = sqrt((du * du + dv * dv) / (255.0 * 255.0));
201 
202  alpha = diff > ctx->similarity;
203  if (ctx->blend > 0.0001) {
204  double f = 1. - av_clipd((diff - ctx->similarity) / ctx->blend, 0.0, 1.0);
205 
206  frame->data[1][frame->linesize[1] * y + x] = 128 + (u - 128) * f;
207  frame->data[2][frame->linesize[2] * y + x] = 128 + (v - 128) * f;
208  } else if (alpha) {
209  frame->data[1][frame->linesize[1] * y + x] = 128;
210  frame->data[2][frame->linesize[2] * y + x] = 128;
211  }
212  }
213  }
214 
215  return 0;
216 }
217 
218 static int do_chromahold16_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
219 {
220  ChromakeyContext *ctx = avctx->priv;
221  AVFrame *frame = arg;
222  const int slice_start = ((frame->height >> ctx->vsub_log2) * jobnr) / nb_jobs;
223  const int slice_end = ((frame->height >> ctx->vsub_log2) * (jobnr + 1)) / nb_jobs;
224  const int mid = ctx->mid;
225  double max = ctx->max;
226 
227  int x, y, alpha;
228 
229  for (y = slice_start; y < slice_end; ++y) {
230  for (x = 0; x < frame->width >> ctx->hsub_log2; ++x) {
231  int u = AV_RN16(&frame->data[1][frame->linesize[1] * y + 2 * x]);
232  int v = AV_RN16(&frame->data[2][frame->linesize[2] * y + 2 * x]);
233  double diff;
234  int du, dv;
235 
236  du = u - ctx->chromakey_uv[0];
237  dv = v - ctx->chromakey_uv[1];
238 
239  diff = sqrt((du * du + dv * dv) / (max * max));
240 
241  alpha = diff > ctx->similarity;
242  if (ctx->blend > 0.0001) {
243  double f = 1. - av_clipd((diff - ctx->similarity) / ctx->blend, 0.0, 1.0);
244 
245  AV_WN16(&frame->data[1][frame->linesize[1] * y + 2 * x], mid + (u - mid) * f);
246  AV_WN16(&frame->data[2][frame->linesize[2] * y + 2 * x], mid + (v - mid) * f);
247  } else if (alpha) {
248  AV_WN16(&frame->data[1][frame->linesize[1] * y + 2 * x], mid);
249  AV_WN16(&frame->data[2][frame->linesize[2] * y + 2 * x], mid);
250  }
251  }
252  }
253 
254  return 0;
255 }
256 
258 {
259  AVFilterContext *avctx = link->dst;
260  ChromakeyContext *ctx = avctx->priv;
261  int res;
262 
263  if (res = avctx->internal->execute(avctx, ctx->do_slice, frame, NULL, FFMIN(frame->height, ff_filter_get_nb_threads(avctx))))
264  return res;
265 
266  return ff_filter_frame(avctx->outputs[0], frame);
267 }
268 
269 #define FIXNUM(x) lrint((x) * (1 << 10))
270 #define RGB_TO_U(rgb) (((- FIXNUM(0.16874) * rgb[0] - FIXNUM(0.33126) * rgb[1] + FIXNUM(0.50000) * rgb[2] + (1 << 9) - 1) >> 10) + 128)
271 #define RGB_TO_V(rgb) ((( FIXNUM(0.50000) * rgb[0] - FIXNUM(0.41869) * rgb[1] - FIXNUM(0.08131) * rgb[2] + (1 << 9) - 1) >> 10) + 128)
272 
273 static av_cold int config_output(AVFilterLink *outlink)
274 {
276  AVFilterContext *avctx = outlink->src;
277  ChromakeyContext *ctx = avctx->priv;
278  int factor;
279 
280  ctx->depth = desc->comp[0].depth;
281  ctx->mid = 1 << (ctx->depth - 1);
282  ctx->max = (1 << ctx->depth) - 1;
283 
284  factor = 1 << (ctx->depth - 8);
285 
286  if (ctx->is_yuv) {
287  ctx->chromakey_uv[0] = ctx->chromakey_rgba[1] * factor;
288  ctx->chromakey_uv[1] = ctx->chromakey_rgba[2] * factor;
289  } else {
290  ctx->chromakey_uv[0] = RGB_TO_U(ctx->chromakey_rgba) * factor;
291  ctx->chromakey_uv[1] = RGB_TO_V(ctx->chromakey_rgba) * factor;
292  }
293 
294  if (!strcmp(avctx->filter->name, "chromakey")) {
295  ctx->do_slice = ctx->depth <= 8 ? do_chromakey_slice : do_chromakey16_slice;
296  } else {
297  ctx->do_slice = ctx->depth <= 8 ? do_chromahold_slice: do_chromahold16_slice;
298  }
299 
300  return 0;
301 }
302 
304 {
305  static const enum AVPixelFormat pixel_fmts[] = {
314  };
315 
316  static const enum AVPixelFormat hold_pixel_fmts[] = {
333  };
334 
336 
337  formats = ff_make_format_list(!strcmp(avctx->filter->name, "chromahold") ? hold_pixel_fmts : pixel_fmts);
338  if (!formats)
339  return AVERROR(ENOMEM);
340 
341  return ff_set_common_formats(avctx, formats);
342 }
343 
345 {
346  AVFilterContext *avctx = inlink->dst;
347  ChromakeyContext *ctx = avctx->priv;
349 
350  ctx->hsub_log2 = desc->log2_chroma_w;
351  ctx->vsub_log2 = desc->log2_chroma_h;
352 
353  return 0;
354 }
355 
356 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
357  char *res, int res_len, int flags)
358 {
359  int ret;
360 
361  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
362  if (ret < 0)
363  return ret;
364 
365  return config_output(ctx->outputs[0]);
366 }
367 
368 static const AVFilterPad chromakey_inputs[] = {
369  {
370  .name = "default",
371  .type = AVMEDIA_TYPE_VIDEO,
372  .needs_writable = 1,
373  .filter_frame = filter_frame,
374  .config_props = config_input,
375  },
376  { NULL }
377 };
378 
379 static const AVFilterPad chromakey_outputs[] = {
380  {
381  .name = "default",
382  .type = AVMEDIA_TYPE_VIDEO,
383  .config_props = config_output,
384  },
385  { NULL }
386 };
387 
388 #define OFFSET(x) offsetof(ChromakeyContext, x)
389 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
390 
391 static const AVOption chromakey_options[] = {
392  { "color", "set the chromakey key color", OFFSET(chromakey_rgba), AV_OPT_TYPE_COLOR, { .str = "black" }, 0, 0, FLAGS },
393  { "similarity", "set the chromakey similarity value", OFFSET(similarity), AV_OPT_TYPE_FLOAT, { .dbl = 0.01 }, 0.01, 1.0, FLAGS },
394  { "blend", "set the chromakey key blend value", OFFSET(blend), AV_OPT_TYPE_FLOAT, { .dbl = 0.0 }, 0.0, 1.0, FLAGS },
395  { "yuv", "color parameter is in yuv instead of rgb", OFFSET(is_yuv), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
396  { NULL }
397 };
398 
399 AVFILTER_DEFINE_CLASS(chromakey);
400 
402  .name = "chromakey",
403  .description = NULL_IF_CONFIG_SMALL("Turns a certain color into transparency. Operates on YUV colors."),
404  .priv_size = sizeof(ChromakeyContext),
405  .priv_class = &chromakey_class,
411 };
412 
413 static const AVOption chromahold_options[] = {
414  { "color", "set the chromahold key color", OFFSET(chromakey_rgba), AV_OPT_TYPE_COLOR, { .str = "black" }, 0, 0, FLAGS },
415  { "similarity", "set the chromahold similarity value", OFFSET(similarity), AV_OPT_TYPE_FLOAT, { .dbl = 0.01 }, 0.01, 1.0, FLAGS },
416  { "blend", "set the chromahold blend value", OFFSET(blend), AV_OPT_TYPE_FLOAT, { .dbl = 0.0 }, 0.0, 1.0, FLAGS },
417  { "yuv", "color parameter is in yuv instead of rgb", OFFSET(is_yuv), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS },
418  { NULL }
419 };
420 
421 static const AVFilterPad chromahold_inputs[] = {
422  {
423  .name = "default",
424  .type = AVMEDIA_TYPE_VIDEO,
425  .needs_writable = 1,
426  .filter_frame = filter_frame,
427  .config_props = config_input,
428  },
429  { NULL }
430 };
431 
432 static const AVFilterPad chromahold_outputs[] = {
433  {
434  .name = "default",
435  .type = AVMEDIA_TYPE_VIDEO,
436  .config_props = config_output,
437  },
438  { NULL }
439 };
440 
441 AVFILTER_DEFINE_CLASS(chromahold);
442 
444  .name = "chromahold",
445  .description = NULL_IF_CONFIG_SMALL("Turns a certain color range into gray."),
446  .priv_size = sizeof(ChromakeyContext),
447  .priv_class = &chromahold_class,
453 };
formats
formats
Definition: signature.h:48
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:440
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
config_input
static av_cold int config_input(AVFilterLink *inlink)
Definition: vf_chromakey.c:344
ChromakeyContext::do_slice
int(* do_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_chromakey.c:46
AVERROR
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 all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
RGB_TO_V
#define RGB_TO_V(rgb)
Definition: vf_chromakey.c:271
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:300
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:262
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1075
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2549
inlink
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
Definition: filter_design.txt:212
chromakey_outputs
static const AVFilterPad chromakey_outputs[]
Definition: vf_chromakey.c:379
AV_RN16
#define AV_RN16(p)
Definition: intreadwrite.h:360
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:432
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:439
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:434
AVOption
AVOption.
Definition: opt.h:246
chromahold_inputs
static const AVFilterPad chromahold_inputs[]
Definition: vf_chromakey.c:421
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:397
max
#define max(a, b)
Definition: cuda_runtime.h:33
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
video.h
ChromakeyContext::chromakey_uv
uint16_t chromakey_uv[2]
Definition: vf_chromakey.c:33
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:435
do_chromakey_pixel
static uint8_t do_chromakey_pixel(ChromakeyContext *ctx, uint8_t u[9], uint8_t v[9])
Definition: vf_chromakey.c:50
AVFilterFormats
A list of supported formats for one end of a filter link.
Definition: formats.h:64
formats.h
ChromakeyContext::max
int max
Definition: vf_chromakey.c:41
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:431
chromahold_options
static const AVOption chromahold_options[]
Definition: vf_chromakey.c:413
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:353
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:441
ChromakeyContext::mid
int mid
Definition: vf_chromakey.c:40
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:395
ChromakeyContext::depth
int depth
Definition: vf_chromakey.c:39
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:400
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(chromakey)
av_cold
#define av_cold
Definition: attributes.h:90
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:409
ff_set_common_formats
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:605
ChromakeyContext::is_yuv
int is_yuv
Definition: vf_chromakey.c:38
intreadwrite.h
get_pixel16_uv
static av_always_inline void get_pixel16_uv(AVFrame *frame, int hsub_log2, int vsub_log2, int x, int y, uint16_t *u, uint16_t *v)
Definition: vf_chromakey.c:105
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:410
ChromakeyContext
Definition: vf_chromakey.c:29
slice_end
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:2040
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:438
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:394
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:408
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
f
#define f(width, name)
Definition: cbs_vp9.c:255
link
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
Definition: filter_design.txt:23
ff_vf_chromahold
AVFilter ff_vf_chromahold
Definition: vf_chromakey.c:443
arg
const char * arg
Definition: jacosubdec.c:66
chromakey_options
static const AVOption chromakey_options[]
Definition: vf_chromakey.c:391
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
ff_vf_chromakey
AVFilter ff_vf_chromakey
Definition: vf_chromakey.c:401
AV_OPT_TYPE_COLOR
@ AV_OPT_TYPE_COLOR
Definition: opt.h:238
ChromakeyContext::blend
float blend
Definition: vf_chromakey.c:36
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_chromakey.c:356
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:398
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 inputs
Definition: filter_design.txt:243
chromahold_outputs
static const AVFilterPad chromahold_outputs[]
Definition: vf_chromakey.c:432
filter_frame
static int filter_frame(AVFilterLink *link, AVFrame *frame)
Definition: vf_chromakey.c:257
desc
const char * desc
Definition: nvenc.c:79
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:402
do_chromahold16_slice
static int do_chromahold16_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_chromakey.c:218
ChromakeyContext::chromakey_rgba
uint8_t chromakey_rgba[4]
Definition: vf_chromakey.c:32
do_chromakey16_slice
static int do_chromakey16_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_chromakey.c:147
RGB_TO_U
#define RGB_TO_U(rgb)
Definition: vf_chromakey.c:270
do_chromakey_pixel16
static uint16_t do_chromakey_pixel16(ChromakeyContext *ctx, uint16_t u[9], uint16_t v[9])
Definition: vf_chromakey.c:71
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:404
ff_filter_process_command
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.
Definition: avfilter.c:869
chromakey_inputs
static const AVFilterPad chromakey_inputs[]
Definition: vf_chromakey.c:368
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:177
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:436
internal.h
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:125
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:226
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:784
av_always_inline
#define av_always_inline
Definition: attributes.h:49
uint8_t
uint8_t
Definition: audio_convert.c:194
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:396
get_pixel_uv
static av_always_inline void get_pixel_uv(AVFrame *frame, int hsub_log2, int vsub_log2, int x, int y, uint8_t *u, uint8_t *v)
Definition: vf_chromakey.c:93
AVFilter
Filter definition.
Definition: avfilter.h:144
ret
ret
Definition: filter_design.txt:187
frame
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
Definition: filter_design.txt:264
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:433
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:401
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:406
do_chromakey_slice
static int do_chromakey_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_chromakey.c:117
AVFilterInternal::execute
avfilter_execute_func * execute
Definition: internal.h:144
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:437
avfilter.h
AVFilterContext::internal
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:378
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
AVFilterContext
An instance of a filter.
Definition: avfilter.h:338
factor
static const int factor[16]
Definition: vf_pp7.c:75
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:116
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
OFFSET
#define OFFSET(x)
Definition: vf_chromakey.c:388
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
diff
static av_always_inline int diff(const uint32_t a, const uint32_t b)
Definition: vf_palettegen.c:136
alpha
static const int16_t alpha[]
Definition: ilbcdata.h:55
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:240
do_chromahold_slice
static int do_chromahold_slice(AVFilterContext *avctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_chromakey.c:181
FLAGS
#define FLAGS
Definition: vf_chromakey.c:389
ChromakeyContext::vsub_log2
int vsub_log2
Definition: vf_chromakey.c:44
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
query_formats
static av_cold int query_formats(AVFilterContext *avctx)
Definition: vf_chromakey.c:303
ChromakeyContext::similarity
float similarity
Definition: vf_chromakey.c:35
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:407
AVFilterContext::filter
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:341
ChromakeyContext::hsub_log2
int hsub_log2
Definition: vf_chromakey.c:43
int
int
Definition: ffmpeg_filter.c:192
config_output
static av_cold int config_output(AVFilterLink *outlink)
Definition: vf_chromakey.c:273
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:176
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:405
AVFilterContext::outputs
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
AV_WN16
#define AV_WN16(p, v)
Definition: intreadwrite.h:372