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 "framesync.h"
27 #include "internal.h"
28 #include "video.h"
29 
34 };
35 
37  OFF,
38  ON,
40 };
41 
42 typedef struct GuidedContext {
43  const AVClass *class;
45 
46  int radius;
47  float eps;
48  int mode;
49  int sub;
50  int guidance;
51  int planes;
52 
53  int width;
54  int height;
55 
56  int nb_planes;
57  int depth;
58  int planewidth[4];
59  int planeheight[4];
60 
61  float *I;
62  float *II;
63  float *P;
64  float *IP;
65  float *meanI;
66  float *meanII;
67  float *meanP;
68  float *meanIP;
69 
70  float *A;
71  float *B;
72  float *meanA;
73  float *meanB;
74 
75  int (*box_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
77 
78 #define OFFSET(x) offsetof(GuidedContext, x)
79 #define TFLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
80 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
81 
82 static const AVOption guided_options[] = {
83  { "radius", "set the box radius", OFFSET(radius), AV_OPT_TYPE_INT, {.i64 = 3 }, 1, 20, TFLAGS },
84  { "eps", "set the regularization parameter (with square)", OFFSET(eps), AV_OPT_TYPE_FLOAT, {.dbl = 0.01 }, 0.0, 1, TFLAGS },
85  { "mode", "set filtering mode (0: basic mode; 1: fast mode)", OFFSET(mode), AV_OPT_TYPE_INT, {.i64 = BASIC}, BASIC, NB_MODES - 1, TFLAGS, .unit = "mode" },
86  { "basic", "basic guided filter", 0, AV_OPT_TYPE_CONST, {.i64 = BASIC}, 0, 0, TFLAGS, .unit = "mode" },
87  { "fast", "fast guided filter", 0, AV_OPT_TYPE_CONST, {.i64 = FAST }, 0, 0, TFLAGS, .unit = "mode" },
88  { "sub", "subsampling ratio for fast mode", OFFSET(sub), AV_OPT_TYPE_INT, {.i64 = 4 }, 2, 64, TFLAGS },
89  { "guidance", "set guidance mode (0: off mode; 1: on mode)", OFFSET(guidance), AV_OPT_TYPE_INT, {.i64 = OFF }, OFF, NB_GUIDANCE_MODES - 1, FLAGS, .unit = "guidance" },
90  { "off", "only one input is enabled", 0, AV_OPT_TYPE_CONST, {.i64 = OFF }, 0, 0, FLAGS, .unit = "guidance" },
91  { "on", "two inputs are required", 0, AV_OPT_TYPE_CONST, {.i64 = ON }, 0, 0, FLAGS, .unit = "guidance" },
92  { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64 = 1 }, 0, 0xF, TFLAGS },
93  { NULL }
94 };
95 
96 AVFILTER_DEFINE_CLASS(guided);
97 
98 typedef struct ThreadData {
99  int width;
100  int height;
101  float *src;
102  float *dst;
105 } ThreadData;
106 
107 static int box_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
108 {
109  GuidedContext *s = ctx->priv;
110  ThreadData *t = arg;
111 
112  const int width = t->width;
113  const int height = t->height;
114  const int src_stride = t->srcStride;
115  const int dst_stride = t->dstStride;
116  const int slice_start = (height * jobnr) / nb_jobs;
117  const int slice_end = (height * (jobnr + 1)) / nb_jobs;
118  const int radius = s->radius;
119  const float *src = t->src;
120  float *dst = t->dst;
121 
122  int w;
123  int numPix;
124  w = (radius << 1) + 1;
125  numPix = w * w;
126  for (int i = slice_start;i < slice_end;i++) {
127  for (int j = 0;j < width;j++) {
128  float temp = 0.0;
129  for (int row = -radius;row <= radius;row++) {
130  for (int col = -radius;col <= radius;col++) {
131  int x = i + row;
132  int y = j + col;
133  x = (x < 0) ? 0 : (x >= height ? height - 1 : x);
134  y = (y < 0) ? 0 : (y >= width ? width - 1 : y);
135  temp += src[x * src_stride + y];
136  }
137  }
138  dst[i * dst_stride + j] = temp / numPix;
139  }
140  }
141  return 0;
142 }
143 
144 static const enum AVPixelFormat pix_fmts[] = {
163 };
164 
166 {
167  AVFilterContext *ctx = inlink->dst;
168  GuidedContext *s = ctx->priv;
170 
171  if (s->mode == BASIC) {
172  s->sub = 1;
173  } else if (s->mode == FAST) {
174  if (s->radius >= s->sub)
175  s->radius = s->radius / s->sub;
176  else {
177  s->radius = 1;
178  }
179  }
180 
181  s->depth = desc->comp[0].depth;
182  s->width = ctx->inputs[0]->w;
183  s->height = ctx->inputs[0]->h;
184 
185  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
186  s->planewidth[0] = s->planewidth[3] = inlink->w;
187  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
188  s->planeheight[0] = s->planeheight[3] = inlink->h;
189 
190  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
191  s->box_slice = box_slice;
192  return 0;
193 }
194 
195 #define GUIDED(type, name) \
196 static int guided_##name(AVFilterContext *ctx, GuidedContext *s, \
197  const uint8_t *ssrc, const uint8_t *ssrcRef, \
198  uint8_t *ddst, int radius, float eps, int width, int height, \
199  int src_stride, int src_ref_stride, int dst_stride, \
200  float maxval) \
201 { \
202  int ret = 0; \
203  type *dst = (type *)ddst; \
204  const type *src = (const type *)ssrc; \
205  const type *srcRef = (const type *)ssrcRef; \
206  \
207  int sub = s->sub; \
208  int h = (height % sub) == 0 ? height / sub : height / sub + 1; \
209  int w = (width % sub) == 0 ? width / sub : width / sub + 1; \
210  \
211  ThreadData t; \
212  const int nb_threads = ff_filter_get_nb_threads(ctx); \
213  float *I = s->I; \
214  float *II = s->II; \
215  float *P = s->P; \
216  float *IP = s->IP; \
217  float *meanI = s->meanI; \
218  float *meanII = s->meanII; \
219  float *meanP = s->meanP; \
220  float *meanIP = s->meanIP; \
221  float *A = s->A; \
222  float *B = s->B; \
223  float *meanA = s->meanA; \
224  float *meanB = s->meanB; \
225  \
226  for (int i = 0;i < h;i++) { \
227  for (int j = 0;j < w;j++) { \
228  int x = i * w + j; \
229  I[x] = src[(i * src_stride + j) * sub] / maxval; \
230  II[x] = I[x] * I[x]; \
231  P[x] = srcRef[(i * src_ref_stride + j) * sub] / maxval; \
232  IP[x] = I[x] * P[x]; \
233  } \
234  } \
235  \
236  t.width = w; \
237  t.height = h; \
238  t.srcStride = w; \
239  t.dstStride = w; \
240  t.src = I; \
241  t.dst = meanI; \
242  ff_filter_execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
243  t.src = II; \
244  t.dst = meanII; \
245  ff_filter_execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
246  t.src = P; \
247  t.dst = meanP; \
248  ff_filter_execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
249  t.src = IP; \
250  t.dst = meanIP; \
251  ff_filter_execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
252  \
253  for (int i = 0;i < h;i++) { \
254  for (int j = 0;j < w;j++) { \
255  int x = i * w + j; \
256  float varI = meanII[x] - (meanI[x] * meanI[x]); \
257  float covIP = meanIP[x] - (meanI[x] * meanP[x]); \
258  A[x] = covIP / (varI + eps); \
259  B[x] = meanP[x] - A[x] * meanI[x]; \
260  } \
261  } \
262  \
263  t.src = A; \
264  t.dst = meanA; \
265  ff_filter_execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
266  t.src = B; \
267  t.dst = meanB; \
268  ff_filter_execute(ctx, s->box_slice, &t, NULL, FFMIN(h, nb_threads)); \
269  \
270  for (int i = 0;i < height;i++) { \
271  for (int j = 0;j < width;j++) { \
272  int x = i / sub * w + j / sub; \
273  dst[i * dst_stride + j] = meanA[x] * src[i * src_stride + j] + \
274  meanB[x] * maxval; \
275  } \
276  } \
277  \
278  return ret; \
279 }
280 
281 GUIDED(uint8_t, byte)
282 GUIDED(uint16_t, word)
283 
285 {
286  GuidedContext *s = ctx->priv;
287  AVFilterLink *outlink = ctx->outputs[0];
288  *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
289  if (!*out)
290  return AVERROR(ENOMEM);
291  av_frame_copy_props(*out, in);
292 
293  for (int plane = 0; plane < s->nb_planes; plane++) {
294  if (!(s->planes & (1 << plane))) {
295  av_image_copy_plane((*out)->data[plane], (*out)->linesize[plane],
296  in->data[plane], in->linesize[plane],
297  s->planewidth[plane] * ((s->depth + 7) / 8), s->planeheight[plane]);
298  continue;
299  }
300  if (s->depth <= 8)
301  guided_byte(ctx, s, in->data[plane], ref->data[plane], (*out)->data[plane], s->radius, s->eps,
302  s->planewidth[plane], s->planeheight[plane],
303  in->linesize[plane], ref->linesize[plane], (*out)->linesize[plane], (1 << s->depth) - 1.f);
304  else
305  guided_word(ctx, s, in->data[plane], ref->data[plane], (*out)->data[plane], s->radius, s->eps,
306  s->planewidth[plane], s->planeheight[plane],
307  in->linesize[plane] / 2, ref->linesize[plane] / 2, (*out)->linesize[plane] / 2, (1 << s->depth) - 1.f);
308  }
309 
310  return 0;
311 }
312 
314 {
315  AVFilterContext *ctx = fs->parent;
316  AVFilterLink *outlink = ctx->outputs[0];
317  AVFrame *out_frame = NULL, *main_frame = NULL, *ref_frame = NULL;
318  int ret;
319  ret = ff_framesync_dualinput_get(fs, &main_frame, &ref_frame);
320  if (ret < 0)
321  return ret;
322 
323  if (ctx->is_disabled)
324  return ff_filter_frame(outlink, main_frame);
325 
326  ret = filter_frame(ctx, &out_frame, main_frame, ref_frame);
327  if (ret < 0)
328  return ret;
329  av_frame_free(&main_frame);
330 
331  return ff_filter_frame(outlink, out_frame);
332 }
333 
334 static int config_output(AVFilterLink *outlink)
335 {
336  AVFilterContext *ctx = outlink->src;
337  GuidedContext *s = ctx->priv;
338  AVFilterLink *mainlink = ctx->inputs[0];
339  FFFrameSyncIn *in;
340  int w, h, ret;
341 
342  if (s->guidance == ON) {
343  if (ctx->inputs[0]->w != ctx->inputs[1]->w ||
344  ctx->inputs[0]->h != ctx->inputs[1]->h) {
345  av_log(ctx, AV_LOG_ERROR, "Width and height of input videos must be same.\n");
346  return AVERROR(EINVAL);
347  }
348  }
349 
350  outlink->w = w = mainlink->w;
351  outlink->h = h = mainlink->h;
352  outlink->time_base = mainlink->time_base;
353  outlink->sample_aspect_ratio = mainlink->sample_aspect_ratio;
354  outlink->frame_rate = mainlink->frame_rate;
355 
356  s->I = av_calloc(w * h, sizeof(*s->I));
357  s->II = av_calloc(w * h, sizeof(*s->II));
358  s->P = av_calloc(w * h, sizeof(*s->P));
359  s->IP = av_calloc(w * h, sizeof(*s->IP));
360  s->meanI = av_calloc(w * h, sizeof(*s->meanI));
361  s->meanII = av_calloc(w * h, sizeof(*s->meanII));
362  s->meanP = av_calloc(w * h, sizeof(*s->meanP));
363  s->meanIP = av_calloc(w * h, sizeof(*s->meanIP));
364 
365  s->A = av_calloc(w * h, sizeof(*s->A));
366  s->B = av_calloc(w * h, sizeof(*s->B));
367  s->meanA = av_calloc(w * h, sizeof(*s->meanA));
368  s->meanB = av_calloc(w * h, sizeof(*s->meanA));
369 
370  if (!s->I || !s->II || !s->P || !s->IP || !s->meanI || !s->meanII || !s->meanP ||
371  !s->meanIP || !s->A || !s->B || !s->meanA || !s->meanB)
372  return AVERROR(ENOMEM);
373 
374  if (s->guidance == OFF)
375  return 0;
376 
377  if ((ret = ff_framesync_init(&s->fs, ctx, 2)) < 0)
378  return ret;
379 
380  outlink->time_base = s->fs.time_base;
381 
382  in = s->fs.in;
383  in[0].time_base = mainlink->time_base;
384  in[1].time_base = ctx->inputs[1]->time_base;
385  in[0].sync = 2;
386  in[0].before = EXT_INFINITY;
387  in[0].after = EXT_INFINITY;
388  in[1].sync = 1;
389  in[1].before = EXT_INFINITY;
390  in[1].after = EXT_INFINITY;
391  s->fs.opaque = s;
392  s->fs.on_event = process_frame;
393 
394  return ff_framesync_configure(&s->fs);
395 }
396 
398 {
399  GuidedContext *s = ctx->priv;
400  AVFilterLink *outlink = ctx->outputs[0];
401  AVFilterLink *inlink = ctx->inputs[0];
402  AVFrame *frame = NULL;
403  AVFrame *out = NULL;
404  int ret, status;
405  int64_t pts;
406  if (s->guidance)
407  return ff_framesync_activate(&s->fs);
408 
410 
411  if ((ret = ff_inlink_consume_frame(inlink, &frame)) > 0) {
412  if (ctx->is_disabled)
413  return ff_filter_frame(outlink, frame);
414 
417  if (ret < 0)
418  return ret;
419  ret = ff_filter_frame(outlink, out);
420  }
421  if (ret < 0)
422  return ret;
424  ff_outlink_set_status(outlink, status, pts);
425  return 0;
426  }
427  if (ff_outlink_frame_wanted(outlink))
429  return 0;
430 }
431 
433 {
434  GuidedContext *s = ctx->priv;
435  AVFilterPad pad = { 0 };
436  int ret;
437 
438  pad.type = AVMEDIA_TYPE_VIDEO;
439  pad.name = "source";
441 
442  if ((ret = ff_append_inpad(ctx, &pad)) < 0)
443  return ret;
444 
445  if (s->guidance == ON) {
446  pad.type = AVMEDIA_TYPE_VIDEO;
447  pad.name = "guidance";
448  pad.config_props = NULL;
449 
450  if ((ret = ff_append_inpad(ctx, &pad)) < 0)
451  return ret;
452  }
453 
454  return 0;
455 }
456 
458 {
459  GuidedContext *s = ctx->priv;
460  if (s->guidance == ON)
461  ff_framesync_uninit(&s->fs);
462 
463  av_freep(&s->I);
464  av_freep(&s->II);
465  av_freep(&s->P);
466  av_freep(&s->IP);
467  av_freep(&s->meanI);
468  av_freep(&s->meanII);
469  av_freep(&s->meanP);
470  av_freep(&s->meanIP);
471  av_freep(&s->A);
472  av_freep(&s->B);
473  av_freep(&s->meanA);
474  av_freep(&s->meanB);
475 
476  return;
477 }
478 
479 static const AVFilterPad guided_outputs[] = {
480  {
481  .name = "default",
482  .type = AVMEDIA_TYPE_VIDEO,
483  .config_props = config_output,
484  },
485 };
486 
488  .name = "guided",
489  .description = NULL_IF_CONFIG_SMALL("Apply Guided filter."),
490  .init = init,
491  .uninit = uninit,
492  .priv_size = sizeof(GuidedContext),
493  .priv_class = &guided_class,
494  .activate = activate,
495  .inputs = NULL,
500  .process_command = ff_filter_process_command,
501 };
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:112
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:522
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:501
FFFrameSyncIn::time_base
AVRational time_base
Time base for the incoming frames.
Definition: framesync.h:117
ff_framesync_configure
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition: framesync.c:134
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_guided.c:165
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
GuidedContext::meanI
float * meanI
Definition: vf_guided.c:65
ThreadData::dstStride
int dstStride
Definition: vf_guided.c:104
ff_framesync_uninit
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
Definition: framesync.c:304
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:284
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1018
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2962
GuidedContext::meanA
float * meanA
Definition: vf_guided.c:72
GuidedContext::depth
int depth
Definition: vf_guided.c:57
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:162
activate
static int activate(AVFilterContext *ctx)
Definition: vf_guided.c:397
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:160
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:514
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:375
pixdesc.h
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(guided)
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:521
w
uint8_t w
Definition: llviddspenc.c:38
GUIDED
#define GUIDED(type, name)
Definition: vf_guided.c:195
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:516
AVOption
AVOption.
Definition: opt.h:346
GuidedContext::meanII
float * meanII
Definition: vf_guided.c:66
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:478
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:106
guided_outputs
static const AVFilterPad guided_outputs[]
Definition: vf_guided.c:479
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
FFFrameSync
Frame sync structure.
Definition: framesync.h:168
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:517
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:64
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:458
GuidedContext::meanIP
float * meanIP
Definition: vf_guided.c:68
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
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:1445
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3002
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:513
guided_options
static const AVOption guided_options[]
Definition: vf_guided.c:82
GuidedContext::IP
float * IP
Definition: vf_guided.c:64
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:496
ff_append_inpad
int ff_append_inpad(AVFilterContext *f, AVFilterPad *p)
Append a new input/output pad to the filter's list of such pads.
Definition: avfilter.c:126
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:212
GuidedContext::nb_planes
int nb_planes
Definition: vf_guided.c:56
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:494
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:523
FFFrameSyncIn
Input stream structure.
Definition: framesync.h:102
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:476
pts
static int64_t pts
Definition: transcode_aac.c:643
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:462
FFFrameSyncIn::sync
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events.
Definition: framesync.h:160
AVFILTER_FLAG_DYNAMIC_INPUTS
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
Definition: avfilter.h:106
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:33
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:481
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:283
slice_start
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
Definition: vvcdec.c:685
ff_vf_guided
const AVFilter ff_vf_guided
Definition: vf_guided.c:487
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
TFLAGS
#define TFLAGS
Definition: vf_guided.c:79
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:490
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:86
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:498
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:1571
width
#define width
OFFSET
#define OFFSET(x)
Definition: vf_guided.c:78
FilterModes
FilterModes
Definition: af_adynamicequalizer.c:36
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:499
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:108
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:491
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
ThreadData::height
int height
Definition: vf_avgblur.c:63
slice_end
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:1725
filters.h
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:475
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:489
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:461
GuidedContext::II
float * II
Definition: vf_guided.c:62
GuidedContext::planewidth
int planewidth[4]
Definition: vf_guided.c:58
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:73
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:87
frame
static AVFrame * frame
Definition: demux_decode.c:54
arg
const char * arg
Definition: jacosubdec.c:67
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:459
ThreadData::dst
AVFrame * dst
Definition: vf_blend.c:56
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:497
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:709
fs
#define fs(width, name, subs,...)
Definition: cbs_vp9.c:200
ThreadData::src
const uint8_t * src
Definition: vf_bm3d.c:54
BASIC
@ BASIC
Definition: vf_guided.c:31
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:85
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:479
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_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:493
box_slice
static int box_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_guided.c:107
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:1392
GuidedContext::P
float * P
Definition: vf_guided.c:63
GuidedContext::height
int height
Definition: vf_guided.c:54
AVFilterPad::config_props
int(* config_props)(AVFilterLink *link)
Link configuration callback.
Definition: internal.h:113
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:106
ON
@ ON
Definition: vf_guided.c:38
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:483
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:485
OFF
@ OFF
Definition: vf_guided.c:37
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:890
NB_MODES
@ NB_MODES
Definition: vf_guided.c:33
ref_frame
static int ref_frame(VVCFrame *dst, const VVCFrame *src)
Definition: vvcdec.c:552
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:174
GuidedContext::width
int width
Definition: vf_guided.c:53
GuidedContext::mode
int mode
Definition: vf_guided.c:48
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_guided.c:432
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:518
FLAGS
#define FLAGS
Definition: vf_guided.c:80
internal.h
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:238
GuidedContext::eps
float eps
Definition: vf_guided.c:47
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
FAST
@ FAST
Definition: vf_guided.c:32
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:495
ThreadData
Used for passing data between threads.
Definition: dsddec.c:69
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:107
GuidedContext::B
float * B
Definition: vf_guided.c:71
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:39
GuidedContext
Definition: vf_guided.c:42
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:477
ThreadData::srcStride
int srcStride
Definition: vf_guided.c:103
AVFilter
Filter definition.
Definition: avfilter.h:166
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_guided.c:144
GuidedContext::sub
int sub
Definition: vf_guided.c:49
ret
ret
Definition: filter_design.txt:187
AVFilterPad::type
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:44
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:515
ff_framesync_init
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
Definition: framesync.c:86
GuidedContext::meanP
float * meanP
Definition: vf_guided.c:67
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:482
GuidedContext::radius
int radius
Definition: vf_guided.c:46
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:487
FFFrameSyncIn::before
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
Definition: framesync.h:107
GuidedContext::planeheight
int planeheight[4]
Definition: vf_guided.c:59
status
ov_status_e status
Definition: dnn_backend_openvino.c:120
GuidedContext::box_slice
int(* box_slice)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_guided.c:75
framesync.h
mode
mode
Definition: ebur128.h:83
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
GuidedContext::fs
FFFrameSync fs
Definition: vf_guided.c:44
avfilter.h
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_guided.c:457
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
temp
else temp
Definition: vf_mcdeint.c:263
GuidanceModes
GuidanceModes
Definition: vf_guided.c:36
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:78
AVFilterContext
An instance of a filter.
Definition: avfilter.h:407
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:165
GuidedContext::planes
int planes
Definition: vf_guided.c:51
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:75
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:77
GuidedContext::guidance
int guidance
Definition: vf_guided.c:50
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
planes
static const struct @386 planes[]
NB_GUIDANCE_MODES
@ NB_GUIDANCE_MODES
Definition: vf_guided.c:39
GuidedContext::A
float * A
Definition: vf_guided.c:70
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:183
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
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:80
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_guided.c:334
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
#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:155
imgutils.h
GuidedContext::meanB
float * meanB
Definition: vf_guided.c:73
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:79
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
FFFrameSyncIn::after
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
Definition: framesync.h:112
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:484
h
h
Definition: vp9dsp_template.c:2038
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:488
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:355
ff_framesync_dualinput_get
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
Definition: framesync.c:393
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:460
int
int
Definition: ffmpeg_filter.c:409
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:244
process_frame
static int process_frame(FFFrameSync *fs)
Definition: vf_guided.c:313
GuidedContext::I
float * I
Definition: vf_guided.c:61
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:173
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:486