FFmpeg
vf_guided.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Xuewei Meng
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/imgutils.h"
22 #include "libavutil/opt.h"
23 #include "libavutil/pixdesc.h"
24 #include "avfilter.h"
25 #include "filters.h"
26 #include "formats.h"
27 #include "framesync.h"
28 #include "internal.h"
29 #include "video.h"
30 
35 };
36 
38  OFF,
39  ON,
41 };
42 
43 typedef struct GuidedContext {
44  const AVClass *class;
46 
47  int radius;
48  float eps;
49  int mode;
50  int sub;
51  int guidance;
52  int planes;
53 
54  int width;
55  int height;
56 
57  int nb_planes;
58  int depth;
59  int planewidth[4];
60  int planeheight[4];
61 
62  int (*box_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
64 
65 #define OFFSET(x) offsetof(GuidedContext, x)
66 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
67 
68 static const AVOption guided_options[] = {
69  { "radius", "set the box radius", OFFSET(radius), AV_OPT_TYPE_INT, {.i64 = 3 }, 1, 20, FLAGS },
70  { "eps", "set the regularization parameter (with square)", OFFSET(eps), AV_OPT_TYPE_FLOAT, {.dbl = 0.01 }, 0.0, 1, FLAGS },
71  { "mode", "set filtering mode (0: basic mode; 1: fast mode)", OFFSET(mode), AV_OPT_TYPE_INT, {.i64 = BASIC}, BASIC, NB_MODES - 1, FLAGS, "mode" },
72  { "basic", "basic guided filter", 0, AV_OPT_TYPE_CONST, {.i64 = BASIC}, 0, 0, FLAGS, "mode" },
73  { "fast", "fast guided filter", 0, AV_OPT_TYPE_CONST, {.i64 = FAST }, 0, 0, FLAGS, "mode" },
74  { "sub", "subsampling ratio for fast mode", OFFSET(sub), AV_OPT_TYPE_INT, {.i64 = 4 }, 2, 64, FLAGS },
75  { "guidance", "set guidance mode (0: off mode; 1: on mode)", OFFSET(guidance), AV_OPT_TYPE_INT, {.i64 = OFF }, OFF, NB_GUIDANCE_MODES - 1, FLAGS, "guidance" },
76  { "off", "only one input is enabled", 0, AV_OPT_TYPE_CONST, {.i64 = OFF }, 0, 0, FLAGS, "guidance" },
77  { "on", "two inputs are required", 0, AV_OPT_TYPE_CONST, {.i64 = ON }, 0, 0, FLAGS, "guidance" },
78  { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64 = 1 }, 0, 0xF, FLAGS },
79  { NULL }
80 };
81 
82 AVFILTER_DEFINE_CLASS(guided);
83 
84 typedef struct ThreadData {
85  int width;
86  int height;
87  float *src;
88  float *dst;
89  int srcStride;
90  int dstStride;
91 } ThreadData;
92 
93 static int box_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
94 {
95  GuidedContext *s = ctx->priv;
96  ThreadData *t = arg;
97 
98  const int width = t->width;
99  const int height = t->height;
100  const int src_stride = t->srcStride;
101  const int dst_stride = t->dstStride;
102  const int slice_start = (height * jobnr) / nb_jobs;
103  const int slice_end = (height * (jobnr + 1)) / nb_jobs;
104  const int radius = s->radius;
105  const float *src = t->src;
106  float *dst = t->dst;
107 
108  int w;
109  int numPix;
110  w = (radius << 1) + 1;
111  numPix = w * w;
112  for (int i = slice_start;i < slice_end;i++) {
113  for (int j = 0;j < width;j++) {
114  float temp = 0.0;
115  for (int row = -radius;row <= radius;row++) {
116  for (int col = -radius;col <= radius;col++) {
117  int x = i + row;
118  int y = j + col;
119  x = (x < 0) ? 0 : (x >= height ? height - 1 : x);
120  y = (y < 0) ? 0 : (y >= width ? width - 1 : y);
121  temp += src[x * src_stride + y];
122  }
123  }
124  dst[i * dst_stride + j] = temp / numPix;
125  }
126  }
127  return 0;
128 }
129 
131 {
132  static const enum AVPixelFormat pix_fmts[] = {
151  };
152 
154 }
155 
157 {
158  AVFilterContext *ctx = inlink->dst;
159  GuidedContext *s = ctx->priv;
161 
162  if (s->mode == BASIC) {
163  s->sub = 1;
164  }
165  else if (s->mode == FAST) {
166  if (s->radius >= s->sub)
167  s->radius = s->radius / s->sub;
168  else {
169  s->radius = 1;
170  }
171  }
172 
173  s->depth = desc->comp[0].depth;
174  s->width = ctx->inputs[0]->w;
175  s->height = ctx->inputs[0]->h;
176 
177  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
178  s->planewidth[0] = s->planewidth[3] = inlink->w;
179  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
180  s->planeheight[0] = s->planeheight[3] = inlink->h;
181 
182  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
183  s->box_slice = box_slice;
184  return 0;
185 }
186 
187 #define GUIDED(type, name) \
188 static int guided_##name(AVFilterContext *ctx, GuidedContext *s, \
189  const uint8_t *ssrc, const uint8_t *ssrcRef, \
190  uint8_t *ddst, int radius, float eps, int width, int height, \
191  int src_stride, int src_ref_stride, int dst_stride, \
192  float maxval) \
193 { \
194  int ret = 0; \
195  type *dst = (type *)ddst; \
196  const type *src = (const type *)ssrc; \
197  const type *srcRef = (const type *)ssrcRef; \
198  \
199  int sub = s->sub; \
200  int h = (height % sub) == 0 ? height / sub : height / sub + 1; \
201  int w = (width % sub) == 0 ? width / sub : width / sub + 1; \
202  \
203  ThreadData t; \
204  const int nb_threads = ff_filter_get_nb_threads(ctx); \
205  float *I; \
206  float *II; \
207  float *P; \
208  float *IP; \
209  float *meanI; \
210  float *meanII; \
211  float *meanP; \
212  float *meanIP; \
213  float *A; \
214  float *B; \
215  float *meanA; \
216  float *meanB; \
217  \
218  I = av_calloc(w * h, sizeof(float)); \
219  II = av_calloc(w * h, sizeof(float)); \
220  P = av_calloc(w * h, sizeof(float)); \
221  IP = av_calloc(w * h, sizeof(float)); \
222  meanI = av_calloc(w * h, sizeof(float)); \
223  meanII = av_calloc(w * h, sizeof(float)); \
224  meanP = av_calloc(w * h, sizeof(float)); \
225  meanIP = av_calloc(w * h, sizeof(float)); \
226  \
227  A = av_calloc(w * h, sizeof(float)); \
228  B = av_calloc(w * h, sizeof(float)); \
229  meanA = av_calloc(w * h, sizeof(float)); \
230  meanB = av_calloc(w * h, sizeof(float)); \
231  \
232  if (!I || !II || !P || !IP || !meanI || !meanII || !meanP || \
233  !meanIP || !A || !B || !meanA || !meanB) { \
234  ret = AVERROR(ENOMEM); \
235  goto end; \
236  } \
237  for (int i = 0;i < h;i++) { \
238  for (int j = 0;j < w;j++) { \
239  int x = i * w + j; \
240  I[x] = src[(i * src_stride + j) * sub] / maxval; \
241  II[x] = I[x] * I[x]; \
242  P[x] = srcRef[(i * src_ref_stride + j) * sub] / maxval; \
243  IP[x] = I[x] * P[x]; \
244  } \
245  } \
246  \
247  t.width = w; \
248  t.height = h; \
249  t.srcStride = w; \
250  t.dstStride = w; \
251  t.src = I; \
252  t.dst = meanI; \
253  ctx->internal->execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
254  t.src = II; \
255  t.dst = meanII; \
256  ctx->internal->execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
257  t.src = P; \
258  t.dst = meanP; \
259  ctx->internal->execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
260  t.src = IP; \
261  t.dst = meanIP; \
262  ctx->internal->execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
263  \
264  for (int i = 0;i < h;i++) { \
265  for (int j = 0;j < w;j++) { \
266  int x = i * w + j; \
267  float varI = meanII[x] - (meanI[x] * meanI[x]); \
268  float covIP = meanIP[x] - (meanI[x] * meanP[x]); \
269  A[x] = covIP / (varI + eps); \
270  B[x] = meanP[x] - A[x] * meanI[x]; \
271  } \
272  } \
273  \
274  t.src = A; \
275  t.dst = meanA; \
276  ctx->internal->execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
277  t.src = B; \
278  t.dst = meanB; \
279  ctx->internal->execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
280  \
281  for (int i = 0;i < height;i++) { \
282  for (int j = 0;j < width;j++) { \
283  int x = i / sub * w + j / sub; \
284  dst[i * dst_stride + j] = meanA[x] * src[i * src_stride + j] + \
285  meanB[x] * maxval; \
286  } \
287  } \
288 end: \
289  av_freep(&I); \
290  av_freep(&II); \
291  av_freep(&P); \
292  av_freep(&IP); \
293  av_freep(&meanI); \
294  av_freep(&meanII); \
295  av_freep(&meanP); \
296  av_freep(&meanIP); \
297  av_freep(&A); \
298  av_freep(&B); \
299  av_freep(&meanA); \
300  av_freep(&meanB); \
301  return ret; \
302 }
303 
304 GUIDED(uint8_t, byte)
305 GUIDED(uint16_t, word)
306 
308 {
309  GuidedContext *s = ctx->priv;
310  AVFilterLink *outlink = ctx->outputs[0];
311  *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
312  if (!*out)
313  return AVERROR(ENOMEM);
314  av_frame_copy_props(*out, in);
315 
316  for (int plane = 0; plane < s->nb_planes; plane++) {
317  if (!(s->planes & (1 << plane))) {
318  av_image_copy_plane((*out)->data[plane], (*out)->linesize[plane],
319  in->data[plane], in->linesize[plane],
320  s->planewidth[plane] * ((s->depth + 7) / 8), s->planeheight[plane]);
321  continue;
322  }
323  if (s->depth <= 8)
324  guided_byte(ctx, s, in->data[plane], ref->data[plane], (*out)->data[plane], s->radius, s->eps,
325  s->planewidth[plane], s->planeheight[plane],
326  in->linesize[plane], ref->linesize[plane], (*out)->linesize[plane], (1 << s->depth) - 1.f);
327  else
328  guided_word(ctx, s, in->data[plane], ref->data[plane], (*out)->data[plane], s->radius, s->eps,
329  s->planewidth[plane], s->planeheight[plane],
330  in->linesize[plane] / 2, ref->linesize[plane] / 2, (*out)->linesize[plane] / 2, (1 << s->depth) - 1.f);
331  }
332 
333  return 0;
334 }
335 
337 {
338  AVFilterContext *ctx = fs->parent;
339  AVFilterLink *outlink = ctx->outputs[0];
340  AVFrame *out_frame = NULL, *main_frame = NULL, *ref_frame = NULL;
341  int ret;
342  ret = ff_framesync_dualinput_get(fs, &main_frame, &ref_frame);
343  if (ret < 0)
344  return ret;
345 
346  ret = filter_frame(ctx, &out_frame, main_frame, ref_frame);
347  if (ret < 0) {
348  return ret;
349  }
350  av_frame_free(&main_frame);
351 
352  return ff_filter_frame(outlink, out_frame);
353 }
354 
355 static int config_output(AVFilterLink *outlink)
356 {
357  AVFilterContext *ctx = outlink->src;
358 
359  GuidedContext *s = ctx->priv;
360  AVFilterLink *mainlink = ctx->inputs[0];
361  FFFrameSyncIn *in;
362  int ret;
363 
364  if (s->guidance == ON) {
365  if (ctx->inputs[0]->w != ctx->inputs[1]->w ||
366  ctx->inputs[0]->h != ctx->inputs[1]->h) {
367  av_log(ctx, AV_LOG_ERROR, "Width and height of input videos must be same.\n");
368  return AVERROR(EINVAL);
369  }
370  if (ctx->inputs[0]->format != ctx->inputs[1]->format) {
371  av_log(ctx, AV_LOG_ERROR, "Inputs must be of same pixel format.\n");
372  return AVERROR(EINVAL);
373  }
374  }
375 
376  outlink->w = mainlink->w;
377  outlink->h = mainlink->h;
378  outlink->time_base = mainlink->time_base;
379  outlink->sample_aspect_ratio = mainlink->sample_aspect_ratio;
380  outlink->frame_rate = mainlink->frame_rate;
381 
382  if (s->guidance == OFF)
383  return 0;
384 
385  if ((ret = ff_framesync_init(&s->fs, ctx, 2)) < 0)
386  return ret;
387 
388  outlink->time_base = s->fs.time_base;
389 
390  in = s->fs.in;
391  in[0].time_base = mainlink->time_base;
392  in[1].time_base = ctx->inputs[1]->time_base;
393  in[0].sync = 2;
394  in[0].before = EXT_INFINITY;
395  in[0].after = EXT_INFINITY;
396  in[1].sync = 1;
397  in[1].before = EXT_INFINITY;
398  in[1].after = EXT_INFINITY;
399  s->fs.opaque = s;
400  s->fs.on_event = process_frame;
401 
402  return ff_framesync_configure(&s->fs);
403 }
404 
406 {
407  GuidedContext *s = ctx->priv;
408  AVFrame *frame = NULL;
409  AVFrame *out = NULL;
410  int ret, status;
411  int64_t pts;
412  if (s->guidance)
413  return ff_framesync_activate(&s->fs);
414 
415  FF_FILTER_FORWARD_STATUS_BACK(ctx->outputs[0], ctx->inputs[0]);
416 
417  if ((ret = ff_inlink_consume_frame(ctx->inputs[0], &frame)) > 0) {
420  if (ret < 0)
421  return ret;
422  ret = ff_filter_frame(ctx->outputs[0], out);
423  }
424  if (ret < 0)
425  return ret;
426  if (ff_inlink_acknowledge_status(ctx->inputs[0], &status, &pts)) {
427  ff_outlink_set_status(ctx->outputs[0], status, pts);
428  return 0;
429  }
430  if (ff_outlink_frame_wanted(ctx->outputs[0]))
431  ff_inlink_request_frame(ctx->inputs[0]);
432  return 0;
433 }
434 
436 {
437  GuidedContext *s = ctx->priv;
438  AVFilterPad pad = { 0 };
439  int ret;
440 
441  pad.type = AVMEDIA_TYPE_VIDEO;
442  pad.name = "source";
444 
445  if ((ret = ff_insert_inpad(ctx, 0, &pad)) < 0)
446  return ret;
447 
448  if (s->guidance == ON) {
449  pad.type = AVMEDIA_TYPE_VIDEO;
450  pad.name = "guidance";
451  pad.config_props = NULL;
452 
453  if ((ret = ff_insert_inpad(ctx, 1, &pad)) < 0)
454  return ret;
455  }
456 
457  return 0;
458 }
459 
461 {
462  GuidedContext *s = ctx->priv;
463  if (s->guidance == ON)
464  ff_framesync_uninit(&s->fs);
465  return;
466 }
467 
469  const char *cmd,
470  const char *arg,
471  char *res,
472  int res_len,
473  int flags)
474 {
475  int ret = ff_filter_process_command(ctx, cmd, arg, res, res_len, flags);
476 
477  if (ret < 0)
478  return ret;
479 
480  return 0;
481 }
482 
483 static const AVFilterPad guided_outputs[] = {
484  {
485  .name = "default",
486  .type = AVMEDIA_TYPE_VIDEO,
487  .config_props = config_output,
488  },
489  { NULL }
490 };
491 
493  .name = "guided",
494  .description = NULL_IF_CONFIG_SMALL("Apply Guided filter."),
495  .init = init,
496  .uninit = uninit,
497  .query_formats = query_formats,
498  .priv_size = sizeof(GuidedContext),
499  .priv_class = &guided_class,
500  .activate = activate,
501  .inputs = NULL,
505 };
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:97
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:432
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:411
FFFrameSyncIn::time_base
AVRational time_base
Time base for the incoming frames.
Definition: framesync.h:96
ff_framesync_configure
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition: framesync.c:124
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
status
they must not be accessed directly The fifo field contains the frames that are queued in the input for processing by the filter The status_in and status_out fields contains the queued status(EOF or error) of the link
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_guided.c:156
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
ff_make_format_list
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
ThreadData::dstStride
int dstStride
Definition: vf_guided.c:90
ff_framesync_uninit
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
Definition: framesync.c:290
out
FILE * out
Definition: movenc.c:54
filter_frame
static int filter_frame(AVFilterContext *ctx, AVFrame **out, AVFrame *in, AVFrame *ref)
Definition: vf_guided.c:307
sub
static float sub(float src0, float src1)
Definition: dnn_backend_native_layer_mathbinary.c:31
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:978
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2540
GuidedContext::depth
int depth
Definition: vf_guided.c:58
activate
static int activate(AVFilterContext *ctx)
Definition: vf_guided.c:405
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
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:112
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:424
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
pixdesc.h
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(guided)
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:431
w
uint8_t w
Definition: llviddspenc.c:38
GUIDED
#define GUIDED(type, name)
Definition: vf_guided.c:187
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:426
AVOption
AVOption.
Definition: opt.h:247
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:389
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
guided_outputs
static const AVFilterPad guided_outputs[]
Definition: vf_guided.c:483
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:149
FFFrameSync
Frame sync structure.
Definition: framesync.h:146
EXT_INFINITY
@ EXT_INFINITY
Extend the frame to infinity.
Definition: framesync.h:75
video.h
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:427
FF_FILTER_FORWARD_STATUS_BACK
#define FF_FILTER_FORWARD_STATUS_BACK(outlink, inlink)
Forward the status on an output link to an input link.
Definition: filters.h:199
ThreadData::width
int width
Definition: vf_avgblur.c:62
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:369
av_image_copy_plane
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition: imgutils.c:374
formats.h
ff_insert_inpad
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
Definition: internal.h:240
ff_inlink_consume_frame
int ff_inlink_consume_frame(AVFilterLink *link, AVFrame **rframe)
Take a frame from the link's FIFO and update the link's stats.
Definition: avfilter.c:1376
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2580
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:423
guided_options
static const AVOption guided_options[]
Definition: vf_guided.c:68
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:407
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:205
GuidedContext::nb_planes
int nb_planes
Definition: vf_guided.c:57
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:405
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:433
FFFrameSyncIn
Input stream structure.
Definition: framesync.h:81
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:387
pts
static int64_t pts
Definition: transcode_aac.c:653
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:373
FFFrameSyncIn::sync
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events.
Definition: framesync.h:139
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:392
AV_PIX_FMT_YUVJ411P
@ 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:248
planes
static const struct @318 planes[]
ff_vf_guided
const AVFilter ff_vf_guided
Definition: vf_guided.c:492
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
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
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:401
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:580
AV_PIX_FMT_YUVJ422P
@ 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:79
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:409
ff_outlink_set_status
static void ff_outlink_set_status(AVFilterLink *link, int status, int64_t pts)
Set the status field of a link from the source filter.
Definition: filters.h:189
ff_inlink_request_frame
void ff_inlink_request_frame(AVFilterLink *link)
Mark that a frame is wanted on the link.
Definition: avfilter.c:1502
width
#define width
OFFSET
#define OFFSET(x)
Definition: vf_guided.c:65
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:410
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:402
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
ThreadData::height
int height
Definition: vf_avgblur.c:61
slice_end
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:2031
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
filters.h
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:290
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:386
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:400
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:372
GuidedContext::planewidth
int planewidth[4]
Definition: vf_guided.c:59
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
AV_PIX_FMT_YUVJ444P
@ 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:80
arg
const char * arg
Definition: jacosubdec.c:67
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:370
ThreadData::dst
AVFrame * dst
Definition: vf_blend.c:56
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:408
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:537
fs
#define fs(width, name, subs,...)
Definition: cbs_vp9.c:259
ThreadData::src
const uint8_t * src
Definition: vf_bm3d.c:55
BASIC
@ BASIC
Definition: vf_guided.c:32
AV_PIX_FMT_YUVJ420P
@ 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:78
src
#define src
Definition: vp8dsp.c:255
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:390
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:404
box_slice
static int box_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_guided.c:93
ff_inlink_acknowledge_status
int ff_inlink_acknowledge_status(AVFilterLink *link, int *rstatus, int64_t *rpts)
Test and acknowledge the change of status on the link.
Definition: avfilter.c:1331
GuidedContext::height
int height
Definition: vf_guided.c:55
AVFilterPad::config_props
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: internal.h:118
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:116
ON
@ ON
Definition: vf_guided.c:39
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:394
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:396
OFF
@ OFF
Definition: vf_guided.c:38
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:842
NB_MODES
@ NB_MODES
Definition: vf_guided.c:34
height
#define height
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:167
GuidedContext::width
int width
Definition: vf_guided.c:54
GuidedContext::mode
int mode
Definition: vf_guided.c:49
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_guided.c:435
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:428
FLAGS
#define FLAGS
Definition: vf_guided.c:66
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:126
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:227
GuidedContext::eps
float eps
Definition: vf_guided.c:48
i
int i
Definition: input.c:406
FAST
@ FAST
Definition: vf_guided.c:33
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:406
ThreadData
Used for passing data between threads.
Definition: dsddec.c:67
AV_PIX_FMT_YUVJ440P
@ 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:100
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
GuidedContext
Definition: vf_guided.c:43
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:388
ThreadData::srcStride
int srcStride
Definition: vf_guided.c:89
AVFilter
Filter definition.
Definition: avfilter.h:145
GuidedContext::sub
int sub
Definition: vf_guided.c:50
ret
ret
Definition: filter_design.txt:187
AVFilterPad::type
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:65
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:425
ff_framesync_init
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
Definition: framesync.c:84
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:393
GuidedContext::radius
int radius
Definition: vf_guided.c:47
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:398
FFFrameSyncIn::before
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
Definition: framesync.h:86
GuidedContext::planeheight
int planeheight[4]
Definition: vf_guided.c:60
GuidedContext::box_slice
int(* box_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_guided.c:62
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Definition: vf_guided.c:468
framesync.h
mode
mode
Definition: ebur128.h:83
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
GuidedContext::fs
FFFrameSync fs
Definition: vf_guided.c:45
avfilter.h
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_guided.c:460
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
temp
else temp
Definition: vf_mcdeint.c:259
GuidanceModes
GuidanceModes
Definition: vf_guided.c:37
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:333
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:158
GuidedContext::planes
int planes
Definition: vf_guided.c:52
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:117
desc
const char * desc
Definition: libsvtav1.c:79
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
GuidedContext::guidance
int guidance
Definition: vf_guided.c:51
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
NB_GUIDANCE_MODES
@ NB_GUIDANCE_MODES
Definition: vf_guided.c:40
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_guided.c:355
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
FFFrameSyncIn::after
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
Definition: framesync.h:91
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:395
ff_outlink_frame_wanted
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the ff_outlink_frame_wanted() function. If this function returns true
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:399
ff_framesync_activate
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
Definition: framesync.c:341
ff_framesync_dualinput_get
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
Definition: framesync.c:376
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:371
int
int
Definition: ffmpeg_filter.c:156
query_formats
static int query_formats(AVFilterContext *ctx)
Definition: vf_guided.c:130
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:233
process_frame
static int process_frame(FFFrameSync *fs)
Definition: vf_guided.c:336
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:166
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:397
FilterModes
FilterModes
Definition: vf_bm3d.c:48