FFmpeg  4.4.9
vf_removelogo.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005 Robert Edele <yartrebo@earthlink.net>
3  * Copyright (c) 2012 Stefano Sabatini
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * Advanced blur-based logo removing filter
25  *
26  * This filter loads an image mask file showing where a logo is and
27  * uses a blur transform to remove the logo.
28  *
29  * Based on the libmpcodecs remove-logo filter by Robert Edele.
30  */
31 
32 /**
33  * This code implements a filter to remove annoying TV logos and other annoying
34  * images placed onto a video stream. It works by filling in the pixels that
35  * comprise the logo with neighboring pixels. The transform is very loosely
36  * based on a gaussian blur, but it is different enough to merit its own
37  * paragraph later on. It is a major improvement on the old delogo filter as it
38  * both uses a better blurring algorithm and uses a bitmap to use an arbitrary
39  * and generally much tighter fitting shape than a rectangle.
40  *
41  * The logo removal algorithm has two key points. The first is that it
42  * distinguishes between pixels in the logo and those not in the logo by using
43  * the passed-in bitmap. Pixels not in the logo are copied over directly without
44  * being modified and they also serve as source pixels for the logo
45  * fill-in. Pixels inside the logo have the mask applied.
46  *
47  * At init-time the bitmap is reprocessed internally, and the distance to the
48  * nearest edge of the logo (Manhattan distance), along with a little extra to
49  * remove rough edges, is stored in each pixel. This is done using an in-place
50  * erosion algorithm, and incrementing each pixel that survives any given
51  * erosion. Once every pixel is eroded, the maximum value is recorded, and a
52  * set of masks from size 0 to this size are generaged. The masks are circular
53  * binary masks, where each pixel within a radius N (where N is the size of the
54  * mask) is a 1, and all other pixels are a 0. Although a gaussian mask would be
55  * more mathematically accurate, a binary mask works better in practice because
56  * we generally do not use the central pixels in the mask (because they are in
57  * the logo region), and thus a gaussian mask will cause too little blur and
58  * thus a very unstable image.
59  *
60  * The mask is applied in a special way. Namely, only pixels in the mask that
61  * line up to pixels outside the logo are used. The dynamic mask size means that
62  * the mask is just big enough so that the edges touch pixels outside the logo,
63  * so the blurring is kept to a minimum and at least the first boundary
64  * condition is met (that the image function itself is continuous), even if the
65  * second boundary condition (that the derivative of the image function is
66  * continuous) is not met. A masking algorithm that does preserve the second
67  * boundary coundition (perhaps something based on a highly-modified bi-cubic
68  * algorithm) should offer even better results on paper, but the noise in a
69  * typical TV signal should make anything based on derivatives hopelessly noisy.
70  */
71 
72 #include "libavutil/imgutils.h"
73 #include "libavutil/opt.h"
74 #include "avfilter.h"
75 #include "formats.h"
76 #include "internal.h"
77 #include "video.h"
78 #include "bbox.h"
79 #include "lavfutils.h"
80 #include "lswsutils.h"
81 
82 typedef struct RemovelogoContext {
83  const AVClass *class;
84  char *filename;
85  /* Stores our collection of masks. The first is for an array of
86  the second for the y axis, and the third for the x axis. */
87  int ***mask;
89  int mask_w, mask_h;
90 
96 
97 #define OFFSET(x) offsetof(RemovelogoContext, x)
98 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
99 static const AVOption removelogo_options[] = {
100  { "filename", "set bitmap filename", OFFSET(filename), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
101  { "f", "set bitmap filename", OFFSET(filename), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
102  { NULL }
103 };
104 
106 
107 /**
108  * Choose a slightly larger mask size to improve performance.
109  *
110  * This function maps the absolute minimum mask size needed to the
111  * mask size we'll actually use. f(x) = x (the smallest that will
112  * work) will produce the sharpest results, but will be quite
113  * jittery. f(x) = 1.25x (what I'm using) is a good tradeoff in my
114  * opinion. This will calculate only at init-time, so you can put a
115  * long expression here without effecting performance.
116  */
117 #define apply_mask_fudge_factor(x) (((x) >> 2) + (x))
118 
119 /**
120  * Pre-process an image to give distance information.
121  *
122  * This function takes a bitmap image and converts it in place into a
123  * distance image. A distance image is zero for pixels outside of the
124  * logo and is the Manhattan distance (|dx| + |dy|) from the logo edge
125  * for pixels inside of the logo. This will overestimate the distance,
126  * but that is safe, and is far easier to implement than a proper
127  * pythagorean distance since I'm using a modified erosion algorithm
128  * to compute the distances.
129  *
130  * @param mask image which will be converted from a greyscale image
131  * into a distance image.
132  */
133 static void convert_mask_to_strength_mask(uint8_t *data, int linesize,
134  int w, int h, int min_val,
135  int *max_mask_size)
136 {
137  int x, y;
138 
139  /* How many times we've gone through the loop. Used in the
140  in-place erosion algorithm and to get us max_mask_size later on. */
141  int current_pass = 0;
142 
143  /* set all non-zero values to 1 */
144  for (y = 0; y < h; y++)
145  for (x = 0; x < w; x++)
146  data[y*linesize + x] = data[y*linesize + x] > min_val;
147 
148  /* For each pass, if a pixel is itself the same value as the
149  current pass, and its four neighbors are too, then it is
150  incremented. If no pixels are incremented by the end of the
151  pass, then we go again. Edge pixels are counted as always
152  excluded (this should be true anyway for any sane mask, but if
153  it isn't this will ensure that we eventually exit). */
154  while (1) {
155  /* If this doesn't get set by the end of this pass, then we're done. */
156  int has_anything_changed = 0;
157  uint8_t *current_pixel0 = data + 1 + linesize, *current_pixel;
158  current_pass++;
159 
160  for (y = 1; y < h-1; y++) {
161  current_pixel = current_pixel0;
162  for (x = 1; x < w-1; x++) {
163  /* Apply the in-place erosion transform. It is based
164  on the following two premises:
165  1 - Any pixel that fails 1 erosion will fail all
166  future erosions.
167 
168  2 - Only pixels having survived all erosions up to
169  the present will be >= to current_pass.
170  It doesn't matter if it survived the current pass,
171  failed it, or hasn't been tested yet. By using >=
172  instead of ==, we allow the algorithm to work in
173  place. */
174  if ( *current_pixel >= current_pass &&
175  *(current_pixel + 1) >= current_pass &&
176  *(current_pixel - 1) >= current_pass &&
177  *(current_pixel + linesize) >= current_pass &&
178  *(current_pixel - linesize) >= current_pass) {
179  /* Increment the value since it still has not been
180  * eroded, as evidenced by the if statement that
181  * just evaluated to true. */
182  (*current_pixel)++;
183  has_anything_changed = 1;
184  }
185  current_pixel++;
186  }
187  current_pixel0 += linesize;
188  }
189  if (!has_anything_changed)
190  break;
191  }
192 
193  /* Apply the fudge factor, which will increase the size of the
194  * mask a little to reduce jitter at the cost of more blur. */
195  for (y = 1; y < h - 1; y++)
196  for (x = 1; x < w - 1; x++)
197  data[(y * linesize) + x] = apply_mask_fudge_factor(data[(y * linesize) + x]);
198 
199  /* As a side-effect, we now know the maximum mask size, which
200  * we'll use to generate our masks. */
201  /* Apply the fudge factor to this number too, since we must ensure
202  * that enough masks are generated. */
203  *max_mask_size = apply_mask_fudge_factor(current_pass + 1);
204 }
205 
207 {
208  static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE };
210  if (!fmts_list)
211  return AVERROR(ENOMEM);
212  return ff_set_common_formats(ctx, fmts_list);
213 }
214 
215 static int load_mask(uint8_t **mask, int *w, int *h,
216  const char *filename, void *log_ctx)
217 {
218  int ret;
219  enum AVPixelFormat pix_fmt;
220  uint8_t *src_data[4], *gray_data[4];
221  int src_linesize[4], gray_linesize[4];
222 
223  /* load image from file */
224  if ((ret = ff_load_image(src_data, src_linesize, w, h, &pix_fmt, filename, log_ctx)) < 0)
225  return ret;
226 
227  /* convert the image to GRAY8 */
228  if ((ret = ff_scale_image(gray_data, gray_linesize, *w, *h, AV_PIX_FMT_GRAY8,
229  src_data, src_linesize, *w, *h, pix_fmt,
230  log_ctx)) < 0)
231  goto end;
232 
233  /* copy mask to a newly allocated array */
234  *mask = av_malloc(*w * *h);
235  if (!*mask) {
236  ret = AVERROR(ENOMEM);
237  goto end;
238  }
239  av_image_copy_plane(*mask, *w, gray_data[0], gray_linesize[0], *w, *h);
240 
241 end:
242  av_freep(&src_data[0]);
243  av_freep(&gray_data[0]);
244  return ret;
245 }
246 
247 /**
248  * Generate a scaled down image with half width, height, and intensity.
249  *
250  * This function not only scales down an image, but halves the value
251  * in each pixel too. The purpose of this is to produce a chroma
252  * filter image out of a luma filter image. The pixel values store the
253  * distance to the edge of the logo and halving the dimensions halves
254  * the distance. This function rounds up, because a downwards rounding
255  * error could cause the filter to fail, but an upwards rounding error
256  * will only cause a minor amount of excess blur in the chroma planes.
257  */
258 static void generate_half_size_image(const uint8_t *src_data, int src_linesize,
259  uint8_t *dst_data, int dst_linesize,
260  int src_w, int src_h,
261  int *max_mask_size)
262 {
263  int x, y;
264 
265  /* Copy over the image data, using the average of 4 pixels for to
266  * calculate each downsampled pixel. */
267  for (y = 0; y < src_h/2; y++) {
268  for (x = 0; x < src_w/2; x++) {
269  /* Set the pixel if there exists a non-zero value in the
270  * source pixels, else clear it. */
271  dst_data[(y * dst_linesize) + x] =
272  src_data[((y << 1) * src_linesize) + (x << 1)] ||
273  src_data[((y << 1) * src_linesize) + (x << 1) + 1] ||
274  src_data[(((y << 1) + 1) * src_linesize) + (x << 1)] ||
275  src_data[(((y << 1) + 1) * src_linesize) + (x << 1) + 1];
276  dst_data[(y * dst_linesize) + x] = FFMIN(1, dst_data[(y * dst_linesize) + x]);
277  }
278  }
279 
280  convert_mask_to_strength_mask(dst_data, dst_linesize,
281  src_w/2, src_h/2, 0, max_mask_size);
282 }
283 
285 {
286  RemovelogoContext *s = ctx->priv;
287  int ***mask;
288  int ret = 0;
289  int a, b, c, w, h;
290  int full_max_mask_size, half_max_mask_size;
291 
292  if (!s->filename) {
293  av_log(ctx, AV_LOG_ERROR, "The bitmap file name is mandatory\n");
294  return AVERROR(EINVAL);
295  }
296 
297  /* Load our mask image. */
298  if ((ret = load_mask(&s->full_mask_data, &w, &h, s->filename, ctx)) < 0)
299  return ret;
300  s->mask_w = w;
301  s->mask_h = h;
302 
303  convert_mask_to_strength_mask(s->full_mask_data, w, w, h,
304  16, &full_max_mask_size);
305 
306  /* Create the scaled down mask image for the chroma planes. */
307  if (!(s->half_mask_data = av_mallocz(w/2 * h/2)))
308  return AVERROR(ENOMEM);
309  generate_half_size_image(s->full_mask_data, w,
310  s->half_mask_data, w/2,
311  w, h, &half_max_mask_size);
312 
313  s->max_mask_size = FFMAX(full_max_mask_size, half_max_mask_size);
314 
315  /* Create a circular mask for each size up to max_mask_size. When
316  the filter is applied, the mask size is determined on a pixel
317  by pixel basis, with pixels nearer the edge of the logo getting
318  smaller mask sizes. */
319  mask = av_calloc(s->max_mask_size + 1, sizeof(*mask));
320  if (!mask)
321  return AVERROR(ENOMEM);
322 
323  for (a = 0; a <= s->max_mask_size; a++) {
324  mask[a] = av_calloc((a * 2) + 1, sizeof(*mask[a]));
325  if (!mask[a])
326  goto mask_fail;
327  for (b = -a; b <= a; b++) {
328  mask[a][b + a] = av_malloc_array((a * 2) + 1, sizeof(*mask[a][b + a]));
329  if (!mask[a][b + a])
330  goto mask_fail;
331  for (c = -a; c <= a; c++) {
332  if ((b * b) + (c * c) <= (a * a)) /* Circular 0/1 mask. */
333  mask[a][b + a][c + a] = 1;
334  else
335  mask[a][b + a][c + a] = 0;
336  }
337  }
338  }
339  s->mask = mask;
340 
341  /* Calculate our bounding rectangles, which determine in what
342  * region the logo resides for faster processing. */
343  ff_calculate_bounding_box(&s->full_mask_bbox, s->full_mask_data, w, w, h, 0, 8);
344  ff_calculate_bounding_box(&s->half_mask_bbox, s->half_mask_data, w/2, w/2, h/2, 0, 8);
345 
346 #define SHOW_LOGO_INFO(mask_type) \
347  av_log(ctx, AV_LOG_VERBOSE, #mask_type " x1:%d x2:%d y1:%d y2:%d max_mask_size:%d\n", \
348  s->mask_type##_mask_bbox.x1, s->mask_type##_mask_bbox.x2, \
349  s->mask_type##_mask_bbox.y1, s->mask_type##_mask_bbox.y2, \
350  mask_type##_max_mask_size);
351  SHOW_LOGO_INFO(full);
353 
354  return 0;
355 
356 mask_fail:
357  for (a = 0; a <= s->max_mask_size; a++) {
358  if (mask[a])
359  for (b = 0; b < (a * 2) + 1; b++)
360  av_free(mask[a][b]);
361  av_free(mask[a]);
362  }
363  av_free(mask);
364  return AVERROR(ENOMEM);
365 }
366 
367 static int config_props_input(AVFilterLink *inlink)
368 {
369  AVFilterContext *ctx = inlink->dst;
370  RemovelogoContext *s = ctx->priv;
371 
372  if (inlink->w != s->mask_w || inlink->h != s->mask_h) {
374  "Mask image size %dx%d does not match with the input video size %dx%d\n",
375  s->mask_w, s->mask_h, inlink->w, inlink->h);
376  return AVERROR(EINVAL);
377  }
378 
379  return 0;
380 }
381 
382 /**
383  * Blur image.
384  *
385  * It takes a pixel that is inside the mask and blurs it. It does so
386  * by finding the average of all the pixels within the mask and
387  * outside of the mask.
388  *
389  * @param mask_data the mask plane to use for averaging
390  * @param image_data the image plane to blur
391  * @param w width of the image
392  * @param h height of the image
393  * @param x x-coordinate of the pixel to blur
394  * @param y y-coordinate of the pixel to blur
395  */
396 static unsigned int blur_pixel(int ***mask,
397  const uint8_t *mask_data, int mask_linesize,
398  uint8_t *image_data, int image_linesize,
399  int w, int h, int x, int y)
400 {
401  /* Mask size tells how large a circle to use. The radius is about
402  * (slightly larger than) mask size. */
403  int mask_size;
404  int start_posx, start_posy, end_posx, end_posy;
405  int i, j;
406  unsigned int accumulator = 0, divisor = 0;
407  /* What pixel we are reading out of the circular blur mask. */
408  const uint8_t *image_read_position;
409  /* What pixel we are reading out of the filter image. */
410  const uint8_t *mask_read_position;
411 
412  /* Prepare our bounding rectangle and clip it if need be. */
413  mask_size = mask_data[y * mask_linesize + x];
414  start_posx = FFMAX(0, x - mask_size);
415  start_posy = FFMAX(0, y - mask_size);
416  end_posx = FFMIN(w - 1, x + mask_size);
417  end_posy = FFMIN(h - 1, y + mask_size);
418 
419  image_read_position = image_data + image_linesize * start_posy + start_posx;
420  mask_read_position = mask_data + mask_linesize * start_posy + start_posx;
421 
422  for (j = start_posy; j <= end_posy; j++) {
423  for (i = start_posx; i <= end_posx; i++) {
424  /* Check if this pixel is in the mask or not. Only use the
425  * pixel if it is not. */
426  if (!(*mask_read_position) && mask[mask_size][i - start_posx][j - start_posy]) {
427  accumulator += *image_read_position;
428  divisor++;
429  }
430 
431  image_read_position++;
432  mask_read_position++;
433  }
434 
435  image_read_position += (image_linesize - ((end_posx + 1) - start_posx));
436  mask_read_position += (mask_linesize - ((end_posx + 1) - start_posx));
437  }
438 
439  /* If divisor is 0, it means that not a single pixel is outside of
440  the logo, so we have no data. Else we need to normalise the
441  data using the divisor. */
442  return divisor == 0 ? 255:
443  (accumulator + (divisor / 2)) / divisor; /* divide, taking into account average rounding error */
444 }
445 
446 /**
447  * Blur image plane using a mask.
448  *
449  * @param source The image to have it's logo removed.
450  * @param destination Where the output image will be stored.
451  * @param source_stride How far apart (in memory) two consecutive lines are.
452  * @param destination Same as source_stride, but for the destination image.
453  * @param width Width of the image. This is the same for source and destination.
454  * @param height Height of the image. This is the same for source and destination.
455  * @param is_image_direct If the image is direct, then source and destination are
456  * the same and we can save a lot of time by not copying pixels that
457  * haven't changed.
458  * @param filter The image that stores the distance to the edge of the logo for
459  * each pixel.
460  * @param logo_start_x smallest x-coordinate that contains at least 1 logo pixel.
461  * @param logo_start_y smallest y-coordinate that contains at least 1 logo pixel.
462  * @param logo_end_x largest x-coordinate that contains at least 1 logo pixel.
463  * @param logo_end_y largest y-coordinate that contains at least 1 logo pixel.
464  *
465  * This function processes an entire plane. Pixels outside of the logo are copied
466  * to the output without change, and pixels inside the logo have the de-blurring
467  * function applied.
468  */
469 static void blur_image(int ***mask,
470  const uint8_t *src_data, int src_linesize,
471  uint8_t *dst_data, int dst_linesize,
472  const uint8_t *mask_data, int mask_linesize,
473  int w, int h, int direct,
474  FFBoundingBox *bbox)
475 {
476  int x, y;
477  uint8_t *dst_line;
478  const uint8_t *src_line;
479 
480  if (!direct)
481  av_image_copy_plane(dst_data, dst_linesize, src_data, src_linesize, w, h);
482 
483  for (y = bbox->y1; y <= bbox->y2; y++) {
484  src_line = src_data + src_linesize * y;
485  dst_line = dst_data + dst_linesize * y;
486 
487  for (x = bbox->x1; x <= bbox->x2; x++) {
488  if (mask_data[y * mask_linesize + x]) {
489  /* Only process if we are in the mask. */
490  dst_line[x] = blur_pixel(mask,
491  mask_data, mask_linesize,
492  dst_data, dst_linesize,
493  w, h, x, y);
494  } else {
495  /* Else just copy the data. */
496  if (!direct)
497  dst_line[x] = src_line[x];
498  }
499  }
500  }
501 }
502 
503 static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
504 {
505  RemovelogoContext *s = inlink->dst->priv;
506  AVFilterLink *outlink = inlink->dst->outputs[0];
507  AVFrame *outpicref;
508  int direct = 0;
509 
510  if (av_frame_is_writable(inpicref)) {
511  direct = 1;
512  outpicref = inpicref;
513  } else {
514  outpicref = ff_get_video_buffer(outlink, outlink->w, outlink->h);
515  if (!outpicref) {
516  av_frame_free(&inpicref);
517  return AVERROR(ENOMEM);
518  }
519  av_frame_copy_props(outpicref, inpicref);
520  }
521 
522  blur_image(s->mask,
523  inpicref ->data[0], inpicref ->linesize[0],
524  outpicref->data[0], outpicref->linesize[0],
525  s->full_mask_data, inlink->w,
526  inlink->w, inlink->h, direct, &s->full_mask_bbox);
527  blur_image(s->mask,
528  inpicref ->data[1], inpicref ->linesize[1],
529  outpicref->data[1], outpicref->linesize[1],
530  s->half_mask_data, inlink->w/2,
531  inlink->w/2, inlink->h/2, direct, &s->half_mask_bbox);
532  blur_image(s->mask,
533  inpicref ->data[2], inpicref ->linesize[2],
534  outpicref->data[2], outpicref->linesize[2],
535  s->half_mask_data, inlink->w/2,
536  inlink->w/2, inlink->h/2, direct, &s->half_mask_bbox);
537 
538  if (!direct)
539  av_frame_free(&inpicref);
540 
541  return ff_filter_frame(outlink, outpicref);
542 }
543 
545 {
546  RemovelogoContext *s = ctx->priv;
547  int a, b;
548 
549  av_freep(&s->full_mask_data);
550  av_freep(&s->half_mask_data);
551 
552  if (s->mask) {
553  /* Loop through each mask. */
554  for (a = 0; a <= s->max_mask_size; a++) {
555  /* Loop through each scanline in a mask. */
556  for (b = -a; b <= a; b++) {
557  av_freep(&s->mask[a][b + a]); /* Free a scanline. */
558  }
559  av_freep(&s->mask[a]);
560  }
561  /* Free the array of pointers pointing to the masks. */
562  av_freep(&s->mask);
563  }
564 }
565 
566 static const AVFilterPad removelogo_inputs[] = {
567  {
568  .name = "default",
569  .type = AVMEDIA_TYPE_VIDEO,
570  .config_props = config_props_input,
571  .filter_frame = filter_frame,
572  },
573  { NULL }
574 };
575 
576 static const AVFilterPad removelogo_outputs[] = {
577  {
578  .name = "default",
579  .type = AVMEDIA_TYPE_VIDEO,
580  },
581  { NULL }
582 };
583 
585  .name = "removelogo",
586  .description = NULL_IF_CONFIG_SMALL("Remove a TV logo based on a mask image."),
587  .priv_size = sizeof(RemovelogoContext),
588  .init = init,
589  .uninit = uninit,
593  .priv_class = &removelogo_class,
595 };
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
#define av_cold
Definition: attributes.h:88
uint8_t
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1099
Main libavfilter public API header.
int ff_calculate_bounding_box(FFBoundingBox *bbox, const uint8_t *data, int linesize, int w, int h, int min_val, int depth)
Calculate the smallest rectangle that will encompass the region with values > min_val.
Definition: bbox.c:81
#define flags(name, subs,...)
Definition: cbs_av1.c:572
#define s(width, name)
Definition: cbs_vp9.c:257
#define FFMIN(a, b)
Definition: common.h:105
#define FFMAX(a, b)
Definition: common.h:103
#define NULL
Definition: coverity.c:32
static enum AVPixelFormat pix_fmt
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:587
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:286
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
#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
#define AVERROR(e)
Definition: error.h:43
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:594
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:658
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:245
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
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:376
misc image utilities
int i
Definition: input.c:407
int ff_load_image(uint8_t *data[4], int linesize[4], int *w, int *h, enum AVPixelFormat *pix_fmt, const char *filename, void *log_ctx)
Load image from filename and put the resulting image in data.
Definition: lavfutils.c:25
Miscellaneous utilities which make use of the libavformat library.
static void direct(const float *in, const FFTComplex *ir, int len, float *out)
Definition: af_afir.c:60
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
uint8_t w
Definition: llviddspenc.c:39
int ff_scale_image(uint8_t *dst_data[4], int dst_linesize[4], int dst_w, int dst_h, enum AVPixelFormat dst_pix_fmt, uint8_t *const src_data[4], int src_linesize[4], int src_w, int src_h, enum AVPixelFormat src_pix_fmt, void *log_ctx)
Scale image using libswscale.
Definition: lswsutils.c:22
Miscellaneous utilities which make use of the libswscale library.
static const uint16_t mask[17]
Definition: lzw.c:38
static uint8_t half(int a, int b)
Definition: mobiclip.c:541
const char data[16]
Definition: mxf.c:142
AVOptions.
#define accumulator
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ 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_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
Describe the class of an AVClass context structure.
Definition: log.h:67
An instance of a filter.
Definition: avfilter.h:341
void * priv
private data for use by the filter
Definition: avfilter.h:356
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:353
A list of supported formats for one end of a filter link.
Definition: formats.h:65
A filter pad used for either input or output.
Definition: internal.h:54
const char * name
Pad name.
Definition: internal.h:60
Filter definition.
Definition: avfilter.h:145
const char * name
Filter name.
Definition: avfilter.h:149
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
AVOption.
Definition: opt.h:248
int y1
Definition: bbox.h:27
int x1
Definition: bbox.h:27
This code implements a filter to remove annoying TV logos and other annoying images placed onto a vid...
Definition: vf_removelogo.c:82
uint8_t * full_mask_data
Definition: vf_removelogo.c:91
uint8_t * half_mask_data
Definition: vf_removelogo.c:93
FFBoundingBox full_mask_bbox
Definition: vf_removelogo.c:92
FFBoundingBox half_mask_bbox
Definition: vf_removelogo.c:94
#define av_free(p)
#define av_malloc_array(a, b)
#define av_freep(p)
#define av_malloc(s)
#define av_log(a,...)
AVFormatContext * ctx
Definition: movenc.c:48
const char * b
Definition: vf_curves.c:119
AVFilter ff_vf_removelogo
static void blur_image(int ***mask, const uint8_t *src_data, int src_linesize, uint8_t *dst_data, int dst_linesize, const uint8_t *mask_data, int mask_linesize, int w, int h, int direct, FFBoundingBox *bbox)
Blur image plane using a mask.
AVFILTER_DEFINE_CLASS(removelogo)
static void generate_half_size_image(const uint8_t *src_data, int src_linesize, uint8_t *dst_data, int dst_linesize, int src_w, int src_h, int *max_mask_size)
Generate a scaled down image with half width, height, and intensity.
static const AVFilterPad removelogo_outputs[]
static int query_formats(AVFilterContext *ctx)
static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
#define FLAGS
Definition: vf_removelogo.c:98
static int load_mask(uint8_t **mask, int *w, int *h, const char *filename, void *log_ctx)
static void convert_mask_to_strength_mask(uint8_t *data, int linesize, int w, int h, int min_val, int *max_mask_size)
Pre-process an image to give distance information.
static const AVOption removelogo_options[]
Definition: vf_removelogo.c:99
static av_cold int init(AVFilterContext *ctx)
#define apply_mask_fudge_factor(x)
Choose a slightly larger mask size to improve performance.
static av_cold void uninit(AVFilterContext *ctx)
static const AVFilterPad removelogo_inputs[]
#define OFFSET(x)
Definition: vf_removelogo.c:97
static unsigned int blur_pixel(int ***mask, const uint8_t *mask_data, int mask_linesize, uint8_t *image_data, int image_linesize, int w, int h, int x, int y)
Blur image.
#define SHOW_LOGO_INFO(mask_type)
static int config_props_input(AVFilterLink *inlink)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:104
static double c[64]