FFmpeg
Loading...
Searching...
No Matches
vf_blend.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 Paul B Mahol
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 "config_components.h"
22
23#include "libavutil/eval.h"
24#include "libavutil/mem.h"
25#include "libavutil/opt.h"
26#include "libavutil/pixfmt.h"
27#include "avfilter.h"
28#include "filters.h"
29#include "framesync.h"
30#include "vf_blend_init.h"
31#include "video.h"
32#include "blend.h"
33
34#define TOP 0
35#define BOTTOM 1
36
37typedef struct BlendContext {
38 const AVClass *class;
40 int hsub, vsub; ///< chroma subsampling values
42 char *all_expr;
43 /* enum BlendMode */
46
47 int depth;
49 int tblend;
50 AVFrame *prev_frame; /* only used with tblend */
53
54static const char *const var_names[] = { "X", "Y", "W", "H", "SW", "SH", "T", "N", "A", "B", "TOP", "BOTTOM", NULL };
56
57typedef struct ThreadData {
58 const AVFrame *top, *bottom;
61 int plane;
62 int w, h;
65
66#define OFFSET(x) offsetof(BlendContext, x)
67#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
68
69static const AVOption blend_options[] = {
70 { "c0_mode", "set component #0 blend mode", OFFSET(params[0].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, .unit = "mode" },
71 { "c1_mode", "set component #1 blend mode", OFFSET(params[1].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, .unit = "mode" },
72 { "c2_mode", "set component #2 blend mode", OFFSET(params[2].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, .unit = "mode" },
73 { "c3_mode", "set component #3 blend mode", OFFSET(params[3].mode), AV_OPT_TYPE_INT, {.i64=0}, 0, BLEND_NB-1, FLAGS, .unit = "mode" },
74 { "all_mode", "set blend mode for all components", OFFSET(all_mode), AV_OPT_TYPE_INT, {.i64=-1},-1, BLEND_NB-1, FLAGS, .unit = "mode" },
75 { "addition", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_ADDITION}, 0, 0, FLAGS, .unit = "mode" },
76 { "addition128","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GRAINMERGE}, 0, 0, FLAGS, .unit = "mode" },
77 { "grainmerge", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GRAINMERGE}, 0, 0, FLAGS, .unit = "mode" },
78 { "and", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_AND}, 0, 0, FLAGS, .unit = "mode" },
79 { "average", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_AVERAGE}, 0, 0, FLAGS, .unit = "mode" },
80 { "burn", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_BURN}, 0, 0, FLAGS, .unit = "mode" },
81 { "darken", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DARKEN}, 0, 0, FLAGS, .unit = "mode" },
82 { "difference", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIFFERENCE}, 0, 0, FLAGS, .unit = "mode" },
83 { "difference128", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GRAINEXTRACT}, 0, 0, FLAGS, .unit = "mode" },
84 { "grainextract", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GRAINEXTRACT}, 0, 0, FLAGS, .unit = "mode" },
85 { "divide", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DIVIDE}, 0, 0, FLAGS, .unit = "mode" },
86 { "dodge", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_DODGE}, 0, 0, FLAGS, .unit = "mode" },
87 { "exclusion", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_EXCLUSION}, 0, 0, FLAGS, .unit = "mode" },
88 { "extremity", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_EXTREMITY}, 0, 0, FLAGS, .unit = "mode" },
89 { "freeze", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_FREEZE}, 0, 0, FLAGS, .unit = "mode" },
90 { "glow", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GLOW}, 0, 0, FLAGS, .unit = "mode" },
91 { "hardlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HARDLIGHT}, 0, 0, FLAGS, .unit = "mode" },
92 { "hardmix", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HARDMIX}, 0, 0, FLAGS, .unit = "mode" },
93 { "heat", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HEAT}, 0, 0, FLAGS, .unit = "mode" },
94 { "lighten", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_LIGHTEN}, 0, 0, FLAGS, .unit = "mode" },
95 { "linearlight","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_LINEARLIGHT},0, 0, FLAGS, .unit = "mode" },
96 { "multiply", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_MULTIPLY}, 0, 0, FLAGS, .unit = "mode" },
97 { "multiply128","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_MULTIPLY128},0, 0, FLAGS, .unit = "mode" },
98 { "negation", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_NEGATION}, 0, 0, FLAGS, .unit = "mode" },
99 { "normal", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_NORMAL}, 0, 0, FLAGS, .unit = "mode" },
100 { "or", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_OR}, 0, 0, FLAGS, .unit = "mode" },
101 { "overlay", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_OVERLAY}, 0, 0, FLAGS, .unit = "mode" },
102 { "phoenix", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_PHOENIX}, 0, 0, FLAGS, .unit = "mode" },
103 { "pinlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_PINLIGHT}, 0, 0, FLAGS, .unit = "mode" },
104 { "reflect", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_REFLECT}, 0, 0, FLAGS, .unit = "mode" },
105 { "screen", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SCREEN}, 0, 0, FLAGS, .unit = "mode" },
106 { "softlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SOFTLIGHT}, 0, 0, FLAGS, .unit = "mode" },
107 { "subtract", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SUBTRACT}, 0, 0, FLAGS, .unit = "mode" },
108 { "vividlight", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_VIVIDLIGHT}, 0, 0, FLAGS, .unit = "mode" },
109 { "xor", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_XOR}, 0, 0, FLAGS, .unit = "mode" },
110 { "softdifference","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_SOFTDIFFERENCE}, 0, 0, FLAGS, .unit = "mode" },
111 { "geometric", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_GEOMETRIC}, 0, 0, FLAGS, .unit = "mode" },
112 { "harmonic", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HARMONIC}, 0, 0, FLAGS, .unit = "mode" },
113 { "bleach", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_BLEACH}, 0, 0, FLAGS, .unit = "mode" },
114 { "stain", "", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_STAIN}, 0, 0, FLAGS, .unit = "mode" },
115 { "interpolate","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_INTERPOLATE},0, 0, FLAGS, .unit = "mode" },
116 { "hardoverlay","", 0, AV_OPT_TYPE_CONST, {.i64=BLEND_HARDOVERLAY},0, 0, FLAGS, .unit = "mode" },
117 { "c0_expr", "set color component #0 expression", OFFSET(params[0].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
118 { "c1_expr", "set color component #1 expression", OFFSET(params[1].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
119 { "c2_expr", "set color component #2 expression", OFFSET(params[2].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
120 { "c3_expr", "set color component #3 expression", OFFSET(params[3].expr_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
121 { "all_expr", "set expression for all color components", OFFSET(all_expr), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
122 { "c0_opacity", "set color component #0 opacity", OFFSET(params[0].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
123 { "c1_opacity", "set color component #1 opacity", OFFSET(params[1].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
124 { "c2_opacity", "set color component #2 opacity", OFFSET(params[2].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
125 { "c3_opacity", "set color component #3 opacity", OFFSET(params[3].opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
126 { "all_opacity", "set opacity for all color components", OFFSET(all_opacity), AV_OPT_TYPE_DOUBLE, {.dbl=1}, 0, 1, FLAGS },
127 { NULL }
128};
129
131
132#define DEFINE_BLEND_EXPR(type, name, div, clip) \
133static void blend_expr_## name(const uint8_t *_top, ptrdiff_t top_linesize, \
134 const uint8_t *_bottom, ptrdiff_t bottom_linesize, \
135 uint8_t *_dst, ptrdiff_t dst_linesize, \
136 ptrdiff_t width, ptrdiff_t height, \
137 FilterParams *param, SliceParams *sliceparam) \
138{ \
139 const type *top = (const type*)_top; \
140 const type *bottom = (const type*)_bottom; \
141 double *values = sliceparam->values; \
142 int starty = sliceparam->starty; \
143 type *dst = (type*)_dst; \
144 AVExpr *e = sliceparam->e; \
145 int y, x; \
146 dst_linesize /= div; \
147 top_linesize /= div; \
148 bottom_linesize /= div; \
149 \
150 for (y = 0; y < height; y++) { \
151 values[VAR_Y] = y + starty; \
152 for (x = 0; x < width; x++) { \
153 values[VAR_X] = x; \
154 values[VAR_TOP] = values[VAR_A] = top[x]; \
155 values[VAR_BOTTOM] = values[VAR_B] = bottom[x]; \
156 double value = av_expr_eval(e, values, NULL); \
157 dst[x] = clip ? av_clipd(value, 0, param->max_value) : value; \
158 } \
159 dst += dst_linesize; \
160 top += top_linesize; \
161 bottom += bottom_linesize; \
162 } \
163}
164
165DEFINE_BLEND_EXPR(uint8_t, 8bit, 1, 1)
166DEFINE_BLEND_EXPR(uint16_t, 16bit, 2, 1)
167DEFINE_BLEND_EXPR(float, 32bit, 4, 0)
168
169static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
170{
171 ThreadData *td = arg;
172 int slice_start = ff_slice_pos(td->h, jobnr, nb_jobs);
173 int slice_end = ff_slice_pos(td->h, jobnr + 1, nb_jobs);
175 const uint8_t *top = td->top->data[td->plane];
176 const uint8_t *bottom = td->bottom->data[td->plane];
177 uint8_t *dst = td->dst->data[td->plane];
178 FilterLink *inl = ff_filter_link(td->inlink);
179 double values[VAR_VARS_NB];
180 SliceParams sliceparam = {.values = &values[0], .starty = slice_start, .e = td->param->e ? td->param->e[jobnr] : NULL};
181
182 values[VAR_N] = inl->frame_count_out;
183 values[VAR_T] = td->dst->pts == AV_NOPTS_VALUE ? NAN : td->dst->pts * av_q2d(td->inlink->time_base);
184 values[VAR_W] = td->w;
185 values[VAR_H] = td->h;
186 values[VAR_SW] = td->w / (double)td->dst->width;
187 values[VAR_SH] = td->h / (double)td->dst->height;
188
189 td->param->blend(top + slice_start * td->top->linesize[td->plane],
190 td->top->linesize[td->plane],
191 bottom + slice_start * td->bottom->linesize[td->plane],
192 td->bottom->linesize[td->plane],
193 dst + slice_start * td->dst->linesize[td->plane],
194 td->dst->linesize[td->plane],
195 td->w, height, td->param, &sliceparam);
196 return 0;
197}
198
200 const AVFrame *bottom_buf)
201{
202 BlendContext *s = ctx->priv;
203 AVFilterLink *inlink = ctx->inputs[0];
204 AVFilterLink *outlink = ctx->outputs[0];
205 AVFrame *dst_buf;
206 int plane;
207
208 dst_buf = ff_get_video_buffer(outlink, outlink->w, outlink->h);
209 if (!dst_buf)
210 return top_buf;
211
212 if (av_frame_copy_props(dst_buf, top_buf) < 0) {
213 av_frame_free(&dst_buf);
214 return top_buf;
215 }
216
217 for (plane = 0; plane < s->nb_planes; plane++) {
218 int hsub = plane == 1 || plane == 2 ? s->hsub : 0;
219 int vsub = plane == 1 || plane == 2 ? s->vsub : 0;
220 int outw = AV_CEIL_RSHIFT(dst_buf->width, hsub);
221 int outh = AV_CEIL_RSHIFT(dst_buf->height, vsub);
222 FilterParams *param = &s->params[plane];
223 ThreadData td = { .top = top_buf, .bottom = bottom_buf, .dst = dst_buf,
224 .w = outw, .h = outh, .param = param, .plane = plane,
225 .inlink = inlink };
226
228 FFMIN(outh, s->nb_threads));
229 }
230
231 if (!s->tblend)
232 av_frame_free(&top_buf);
233
234 return dst_buf;
235}
236
238{
239 AVFilterContext *ctx = fs->parent;
240 AVFrame *top_buf, *bottom_buf, *dst_buf;
241 int ret;
242
243 ret = ff_framesync_dualinput_get(fs, &top_buf, &bottom_buf);
244 if (ret < 0)
245 return ret;
246 if (!bottom_buf)
247 return ff_filter_frame(ctx->outputs[0], top_buf);
248 dst_buf = blend_frame(ctx, top_buf, bottom_buf);
249 return ff_filter_frame(ctx->outputs[0], dst_buf);
250}
251
253{
254 BlendContext *s = ctx->priv;
255
256 s->tblend = !strcmp(ctx->filter->name, "tblend");
257 s->nb_threads = ff_filter_get_nb_threads(ctx);
258
259 s->fs.on_event = blend_frame_for_dualinput;
260 return 0;
261}
262
283
285{
286 BlendContext *s = ctx->priv;
287 int i;
288
290 av_frame_free(&s->prev_frame);
291
292 for (i = 0; i < FF_ARRAY_ELEMS(s->params); i++) {
293 if (s->params[i].e) {
294 for (int j = 0; j < s->nb_threads; j++)
295 av_expr_free(s->params[i].e[j]);
296 av_freep(&s->params[i].e);
297 }
298 }
299
300}
301
303{
304 BlendContext *s = ctx->priv;
305 int ret;
306
307 for (int plane = 0; plane < FF_ARRAY_ELEMS(s->params); plane++) {
308 FilterParams *param = &s->params[plane];
309
310 param->max_value = UINT32_MAX >> (32 - s->depth);
311
312 if (s->all_mode >= 0)
313 param->mode = s->all_mode;
314 if (s->all_opacity < 1)
315 param->opacity = s->all_opacity;
316
317 ff_blend_init(param, s->depth);
318
319 if (s->all_expr && !param->expr_str) {
320 param->expr_str = av_strdup(s->all_expr);
321 if (!param->expr_str)
322 return AVERROR(ENOMEM);
323 }
324 if (param->expr_str) {
325 if (!param->e) {
326 param->e = av_calloc(s->nb_threads, sizeof(*param->e));
327 if (!param->e)
328 return AVERROR(ENOMEM);
329 }
330 for (int i = 0; i < s->nb_threads; i++) {
331 av_expr_free(param->e[i]);
332 param->e[i] = NULL;
333 ret = av_expr_parse(&param->e[i], param->expr_str, var_names,
334 NULL, NULL, NULL, NULL, 0, ctx);
335 if (ret < 0)
336 return ret;
337 }
338 param->blend = s->depth > 8 ? s->depth > 16 ? blend_expr_32bit : blend_expr_16bit : blend_expr_8bit;
339 }
340 }
341
342 return 0;
343}
344
345static int config_output(AVFilterLink *outlink)
346{
347 FilterLink *outl = ff_filter_link(outlink);
348 AVFilterContext *ctx = outlink->src;
349 AVFilterLink *toplink = ctx->inputs[TOP];
350 FilterLink *tl = ff_filter_link(toplink);
351 BlendContext *s = ctx->priv;
352 const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(toplink->format);
353 int ret;
354
355 if (!s->tblend) {
356 AVFilterLink *bottomlink = ctx->inputs[BOTTOM];
357
358 if (toplink->w != bottomlink->w || toplink->h != bottomlink->h) {
359 av_log(ctx, AV_LOG_ERROR, "First input link %s parameters "
360 "(size %dx%d) do not match the corresponding "
361 "second input link %s parameters (size %dx%d)\n",
362 ctx->input_pads[TOP].name, toplink->w, toplink->h,
363 ctx->input_pads[BOTTOM].name, bottomlink->w, bottomlink->h);
364 return AVERROR(EINVAL);
365 }
366 }
367
368 outlink->w = toplink->w;
369 outlink->h = toplink->h;
370 outlink->time_base = toplink->time_base;
371 outlink->sample_aspect_ratio = toplink->sample_aspect_ratio;
372 outl->frame_rate = tl->frame_rate;
373
374 s->hsub = pix_desc->log2_chroma_w;
375 s->vsub = pix_desc->log2_chroma_h;
376
377 s->depth = pix_desc->comp[0].depth;
378 s->nb_planes = av_pix_fmt_count_planes(toplink->format);
379
380 if (!s->tblend)
381 if ((ret = ff_framesync_init_dualinput(&s->fs, ctx)) < 0)
382 return ret;
383
384 ret = config_params(ctx);
385 if (ret < 0)
386 return ret;
387
388 if (s->tblend)
389 return 0;
390
391 ret = ff_framesync_configure(&s->fs);
392 outlink->time_base = s->fs.time_base;
393
394 return ret;
395}
396
397static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
398 char *res, int res_len, int flags)
399{
400 int ret;
401
402 ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
403 if (ret < 0)
404 return ret;
405
406 return config_params(ctx);
407}
408
409static const AVFilterPad blend_outputs[] = {
410 {
411 .name = "default",
412 .type = AVMEDIA_TYPE_VIDEO,
413 .config_props = config_output,
414 },
415};
416
417#if CONFIG_BLEND_FILTER
418
419static int activate(AVFilterContext *ctx)
420{
421 BlendContext *s = ctx->priv;
422 return ff_framesync_activate(&s->fs);
423}
424
425static const AVFilterPad blend_inputs[] = {
426 {
427 .name = "top",
428 .type = AVMEDIA_TYPE_VIDEO,
429 },{
430 .name = "bottom",
431 .type = AVMEDIA_TYPE_VIDEO,
432 },
433};
434
435const FFFilter ff_vf_blend = {
436 .p.name = "blend",
437 .p.description = NULL_IF_CONFIG_SMALL("Blend two video frames into each other."),
438 .p.priv_class = &blend_class,
440 .preinit = blend_framesync_preinit,
441 .init = init,
442 .uninit = uninit,
443 .priv_size = sizeof(BlendContext),
445 FILTER_INPUTS(blend_inputs),
448 .process_command = process_command,
449};
450
451#endif
452
453#if CONFIG_TBLEND_FILTER
454
455static int tblend_filter_frame(AVFilterLink *inlink, AVFrame *frame)
456{
457 AVFilterContext *ctx = inlink->dst;
458 BlendContext *s = ctx->priv;
459 AVFilterLink *outlink = ctx->outputs[0];
460
461 if (s->prev_frame) {
462 AVFrame *out;
463
464 if (ctx->is_disabled)
466 else
467 out = blend_frame(ctx, frame, s->prev_frame);
468 av_frame_free(&s->prev_frame);
469 s->prev_frame = frame;
470 return ff_filter_frame(outlink, out);
471 }
472 s->prev_frame = frame;
473 return 0;
474}
475
477
478static const AVFilterPad tblend_inputs[] = {
479 {
480 .name = "default",
481 .type = AVMEDIA_TYPE_VIDEO,
482 .filter_frame = tblend_filter_frame,
483 },
484};
485
486const FFFilter ff_vf_tblend = {
487 .p.name = "tblend",
488 .p.description = NULL_IF_CONFIG_SMALL("Blend successive frames."),
489 .p.priv_class = &tblend_class,
491 .priv_size = sizeof(BlendContext),
492 .init = init,
493 .uninit = uninit,
494 FILTER_INPUTS(tblend_inputs),
497 .process_command = process_command,
498};
499
500#endif
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
SwsAArch64OpImplParams params
Definition ops.c:51
@ VAR_T
Definition aeval.c:53
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
const FFFilter ff_vf_blend
const FFFilter ff_vf_tblend
static FILE * out
static AVFormatContext * ctx
@ VAR_H
Definition avfilter.c:565
@ VAR_W
Definition avfilter.c:564
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
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:906
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition avfilter.c:1696
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition avfilter.c:846
Main libavfilter public API header.
@ BLEND_HARDLIGHT
Definition blend.h:40
@ BLEND_HARDMIX
Definition blend.h:54
@ BLEND_PHOENIX
Definition blend.h:46
@ BLEND_MULTIPLY128
Definition blend.h:58
@ BLEND_EXTREMITY
Definition blend.h:61
@ BLEND_XOR
Definition blend.h:53
@ BLEND_BURN
Definition blend.h:33
@ BLEND_BLEACH
Definition blend.h:65
@ BLEND_AVERAGE
Definition blend.h:32
@ BLEND_DIVIDE
Definition blend.h:37
@ BLEND_OR
Definition blend.h:44
@ BLEND_VIVIDLIGHT
Definition blend.h:52
@ BLEND_STAIN
Definition blend.h:66
@ BLEND_EXCLUSION
Definition blend.h:39
@ BLEND_DIFFERENCE
Definition blend.h:35
@ BLEND_DARKEN
Definition blend.h:34
@ BLEND_REFLECT
Definition blend.h:48
@ BLEND_SOFTDIFFERENCE
Definition blend.h:62
@ BLEND_HARMONIC
Definition blend.h:64
@ BLEND_HARDOVERLAY
Definition blend.h:68
@ BLEND_GRAINEXTRACT
Definition blend.h:36
@ BLEND_PINLIGHT
Definition blend.h:47
@ BLEND_DODGE
Definition blend.h:38
@ BLEND_GLOW
Definition blend.h:56
@ BLEND_OVERLAY
Definition blend.h:45
@ BLEND_AND
Definition blend.h:31
@ BLEND_FREEZE
Definition blend.h:60
@ BLEND_LIGHTEN
Definition blend.h:41
@ BLEND_LINEARLIGHT
Definition blend.h:55
@ BLEND_GEOMETRIC
Definition blend.h:63
@ BLEND_SOFTLIGHT
Definition blend.h:50
@ BLEND_GRAINMERGE
Definition blend.h:57
@ BLEND_INTERPOLATE
Definition blend.h:67
@ BLEND_SCREEN
Definition blend.h:49
@ BLEND_NEGATION
Definition blend.h:43
@ BLEND_HEAT
Definition blend.h:59
@ BLEND_NB
Definition blend.h:69
@ BLEND_ADDITION
Definition blend.h:30
@ BLEND_SUBTRACT
Definition blend.h:51
@ BLEND_MULTIPLY
Definition blend.h:42
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define bit(string, value)
Definition cbs_mpeg2.c:56
#define s(width, name)
Definition cbs_vp9.c:198
#define fs(width, name, subs,...)
Definition cbs_vp9.c:200
#define FLAGS
Definition cmdutils.c:598
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define NULL
Definition coverity.c:32
static AVFrame * frame
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition eval.c:368
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Definition eval.c:735
simple arithmetic expression evaluator
@ VAR_B
Definition f_select.c:114
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition framesync.c:137
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
Definition framesync.c:390
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
Definition framesync.c:352
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
Definition framesync.c:372
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
Definition framesync.c:301
#define FRAMESYNC_DEFINE_CLASS(name, context, field)
Definition framesync.h:352
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition opt.h:266
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition avfilter.h:166
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition avfilter.h:204
#define AVERROR(e)
Definition error.h:45
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:599
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition frame.c:483
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int activate(AVBitStreamFilterContext *ctx)
static int config_output(AVBitStreamFilterLink *outlink)
const char * arg
Definition jacosubdec.c:65
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
Definition filters.h:763
#define FILTER_PIXFMTS_ARRAY(array)
Definition filters.h:244
#define AVFILTER_DEFINE_CLASS_EXT(name, desc, options)
Definition filters.h:470
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition filters.h:199
static const AVOption blend_options[]
Definition vf_blend.c:69
static const AVFilterPad blend_outputs[]
Definition vf_blend.c:409
static AVFrame * blend_frame(AVFilterContext *ctx, AVFrame *top_buf, const AVFrame *bottom_buf)
Definition vf_blend.c:199
static int blend_frame_for_dualinput(FFFrameSync *fs)
Definition vf_blend.c:237
@ VAR_TOP
Definition vf_blend.c:55
@ VAR_SW
Definition vf_blend.c:55
@ VAR_SH
Definition vf_blend.c:55
@ VAR_BOTTOM
Definition vf_blend.c:55
@ VAR_X
Definition vf_blend.c:55
@ VAR_Y
Definition vf_blend.c:55
#define DEFINE_BLEND_EXPR(type, name, div, clip)
Definition vf_blend.c:132
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition vf_blend.c:397
static av_cold void uninit(AVFilterContext *ctx)
Definition vf_blend.c:284
static int config_params(AVFilterContext *ctx)
Definition vf_blend.c:302
#define OFFSET(x)
Definition vf_blend.c:66
static int config_output(AVFilterLink *outlink)
Definition vf_blend.c:345
#define av_cold
Definition attributes.h:117
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static enum AVPixelFormat pix_fmts[]
Definition libkvazaar.c:296
#define FFMIN(a, b)
Definition macros.h:49
#define NAN
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:264
Memory handling functions.
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
Definition mpeg12dec.c:1697
@ VAR_N
Definition noise.c:47
@ VAR_VARS_NB
Definition noise.c:59
static const char *const var_names[]
Definition noise.c:30
#define av_strdup(s)
Definition ops_static.c:55
AVOptions.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3500
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
pixel format definitions
#define AV_PIX_FMT_GBRAP12
Definition pixfmt.h:569
#define AV_PIX_FMT_YUV420P16
Definition pixfmt.h:556
#define AV_PIX_FMT_GBRPF32
Definition pixfmt.h:584
#define AV_PIX_FMT_YUV444P12
Definition pixfmt.h:552
#define AV_PIX_FMT_YUV444P9
Definition pixfmt.h:544
#define AV_PIX_FMT_YUV420P10
Definition pixfmt.h:545
#define AV_PIX_FMT_YUV440P12
Definition pixfmt.h:551
#define AV_PIX_FMT_GRAY9
Definition pixfmt.h:524
#define AV_PIX_FMT_GBRAP16
Definition pixfmt.h:571
#define AV_PIX_FMT_GBRP9
Definition pixfmt.h:563
#define AV_PIX_FMT_YUV422P9
Definition pixfmt.h:543
#define AV_PIX_FMT_YUVA444P10
Definition pixfmt.h:598
#define AV_PIX_FMT_YUVA420P16
Definition pixfmt.h:601
#define AV_PIX_FMT_YUV420P12
Definition pixfmt.h:549
#define AV_PIX_FMT_YUVA420P10
Definition pixfmt.h:596
#define AV_PIX_FMT_YUVA422P9
Definition pixfmt.h:594
#define AV_PIX_FMT_YUV422P12
Definition pixfmt.h:550
#define AV_PIX_FMT_GBRP10
Definition pixfmt.h:564
#define AV_PIX_FMT_YUV422P10
Definition pixfmt.h:546
#define AV_PIX_FMT_GRAY12
Definition pixfmt.h:526
#define AV_PIX_FMT_GBRP12
Definition pixfmt.h:565
#define AV_PIX_FMT_YUV420P9
Definition pixfmt.h:542
#define AV_PIX_FMT_YUVA420P9
Definition pixfmt.h:593
#define AV_PIX_FMT_YUVA422P10
Definition pixfmt.h:597
#define AV_PIX_FMT_GRAYF32
Definition pixfmt.h:588
#define AV_PIX_FMT_YUV420P14
Definition pixfmt.h:553
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition pixfmt.h:106
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition pixfmt.h:108
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition pixfmt.h:107
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition pixfmt.h:79
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition pixfmt.h:80
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition pixfmt.h:174
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition pixfmt.h:283
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition pixfmt.h:212
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition pixfmt.h:86
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition pixfmt.h:173
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition pixfmt.h:165
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition pixfmt.h:87
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition pixfmt.h:85
#define AV_PIX_FMT_YUVA422P12
Definition pixfmt.h:599
#define AV_PIX_FMT_YUV422P14
Definition pixfmt.h:554
#define AV_PIX_FMT_GRAY10
Definition pixfmt.h:525
#define AV_PIX_FMT_YUV422P16
Definition pixfmt.h:557
#define AV_PIX_FMT_YUV440P10
Definition pixfmt.h:547
#define AV_PIX_FMT_GRAY16
Definition pixfmt.h:528
#define AV_PIX_FMT_GBRAP10
Definition pixfmt.h:568
#define AV_PIX_FMT_YUVA444P16
Definition pixfmt.h:603
#define AV_PIX_FMT_YUVA422P16
Definition pixfmt.h:602
#define AV_PIX_FMT_GBRP16
Definition pixfmt.h:567
#define AV_PIX_FMT_YUV444P14
Definition pixfmt.h:555
#define AV_PIX_FMT_YUVA444P9
Definition pixfmt.h:595
#define AV_PIX_FMT_GBRP14
Definition pixfmt.h:566
#define AV_PIX_FMT_YUVA444P12
Definition pixfmt.h:600
#define AV_PIX_FMT_GBRAPF32
Definition pixfmt.h:585
#define AV_PIX_FMT_YUV444P16
Definition pixfmt.h:558
#define AV_PIX_FMT_YUV444P10
Definition pixfmt.h:548
@ VAR_A
Definition scale_eval.c:48
#define TOP
Definition scpr.c:33
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
Definition log.h:76
int depth
Number of bits in the component.
Definition pixdesc.h:57
An instance of a filter.
Definition avfilter.h:273
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition frame.h:574
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
int width
Definition frame.h:544
int height
Definition frame.h:544
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition frame.h:517
AVOption.
Definition opt.h:428
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition pixdesc.h:105
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition pixdesc.h:80
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition pixdesc.h:89
AVFrame * prev_frame
Definition vf_blend.c:50
int vsub
chroma subsampling values
Definition vf_blend.c:40
int nb_planes
Definition vf_blend.c:41
FFFrameSync fs
Definition vf_blend.c:39
FilterParams params[4]
Definition vf_blend.c:48
char * all_expr
Definition vf_blend.c:42
double all_opacity
Definition vf_blend.c:45
int nb_threads
Definition vf_blend.c:51
Frame sync structure.
Definition framesync.h:168
filter data
Definition mlp.h:86
unsigned max_value
Definition blend.h:81
AVExpr ** e
Definition blend.h:82
char * expr_str
Definition blend.h:83
void(* blend)(const uint8_t *top, ptrdiff_t top_linesize, const uint8_t *bottom, ptrdiff_t bottom_linesize, uint8_t *dst, ptrdiff_t dst_linesize, ptrdiff_t width, ptrdiff_t height, struct FilterParams *param, SliceParams *sliceparam)
Definition blend.h:84
enum BlendMode mode
Definition blend.h:79
double opacity
Definition blend.h:80
Used for passing data between threads.
Definition dsddec.c:71
const AVFrame * top
Definition vf_blend.c:58
FilterParams * param
Definition vf_blend.c:63
const AVFrame * bottom
Definition vf_blend.c:58
AVFilterLink * inlink
Definition vf_blend.c:60
AVFrame * dst
Definition vf_blend.c:59
int plane
Definition vf_blend.c:61
Definition swscale.c:71
#define av_freep(p)
#define av_log(a,...)
#define height
Definition dsp.h:89
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static av_unused void ff_blend_init(FilterParams *param, int depth)
#define BLEND_NORMAL(name, type)
static void hsub(htype *dst, const htype *src, int bins)
Definition vf_median.c:74
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition video.c:89
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
Definition dec.c:844
#define BOTTOM
Definition filter.c:34