FFmpeg
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 "internal.h"
76 #include "video.h"
77 #include "bbox.h"
78 #include "lavfutils.h"
79 #include "lswsutils.h"
80 
81 typedef struct RemovelogoContext {
82  const AVClass *class;
83  char *filename;
84  /* Stores our collection of masks. The first is for an array of
85  the second for the y axis, and the third for the x axis. */
86  int ***mask;
88  int mask_w, mask_h;
89 
90  uint8_t *full_mask_data;
92  uint8_t *half_mask_data;
95 
96 #define OFFSET(x) offsetof(RemovelogoContext, x)
97 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
98 static const AVOption removelogo_options[] = {
99  { "filename", "set bitmap filename", OFFSET(filename), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
100  { "f", "set bitmap filename", OFFSET(filename), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
101  { NULL }
102 };
103 
104 AVFILTER_DEFINE_CLASS(removelogo);
105 
106 /**
107  * Choose a slightly larger mask size to improve performance.
108  *
109  * This function maps the absolute minimum mask size needed to the
110  * mask size we'll actually use. f(x) = x (the smallest that will
111  * work) will produce the sharpest results, but will be quite
112  * jittery. f(x) = 1.25x (what I'm using) is a good tradeoff in my
113  * opinion. This will calculate only at init-time, so you can put a
114  * long expression here without effecting performance.
115  */
116 #define apply_mask_fudge_factor(x) (((x) >> 2) + (x))
117 
118 /**
119  * Pre-process an image to give distance information.
120  *
121  * This function takes a bitmap image and converts it in place into a
122  * distance image. A distance image is zero for pixels outside of the
123  * logo and is the Manhattan distance (|dx| + |dy|) from the logo edge
124  * for pixels inside of the logo. This will overestimate the distance,
125  * but that is safe, and is far easier to implement than a proper
126  * pythagorean distance since I'm using a modified erosion algorithm
127  * to compute the distances.
128  *
129  * @param mask image which will be converted from a greyscale image
130  * into a distance image.
131  */
132 static void convert_mask_to_strength_mask(uint8_t *data, int linesize,
133  int w, int h, int min_val,
134  int *max_mask_size)
135 {
136  int x, y;
137 
138  /* How many times we've gone through the loop. Used in the
139  in-place erosion algorithm and to get us max_mask_size later on. */
140  int current_pass = 0;
141 
142  /* set all non-zero values to 1 */
143  for (y = 0; y < h; y++)
144  for (x = 0; x < w; x++)
145  data[y*linesize + x] = data[y*linesize + x] > min_val;
146 
147  /* For each pass, if a pixel is itself the same value as the
148  current pass, and its four neighbors are too, then it is
149  incremented. If no pixels are incremented by the end of the
150  pass, then we go again. Edge pixels are counted as always
151  excluded (this should be true anyway for any sane mask, but if
152  it isn't this will ensure that we eventually exit). */
153  while (1) {
154  /* If this doesn't get set by the end of this pass, then we're done. */
155  int has_anything_changed = 0;
156  uint8_t *current_pixel0 = data + 1 + linesize, *current_pixel;
157  current_pass++;
158 
159  for (y = 1; y < h-1; y++) {
160  current_pixel = current_pixel0;
161  for (x = 1; x < w-1; x++) {
162  /* Apply the in-place erosion transform. It is based
163  on the following two premises:
164  1 - Any pixel that fails 1 erosion will fail all
165  future erosions.
166 
167  2 - Only pixels having survived all erosions up to
168  the present will be >= to current_pass.
169  It doesn't matter if it survived the current pass,
170  failed it, or hasn't been tested yet. By using >=
171  instead of ==, we allow the algorithm to work in
172  place. */
173  if ( *current_pixel >= current_pass &&
174  *(current_pixel + 1) >= current_pass &&
175  *(current_pixel - 1) >= current_pass &&
176  *(current_pixel + linesize) >= current_pass &&
177  *(current_pixel - linesize) >= current_pass) {
178  /* Increment the value since it still has not been
179  * eroded, as evidenced by the if statement that
180  * just evaluated to true. */
181  (*current_pixel)++;
182  has_anything_changed = 1;
183  }
184  current_pixel++;
185  }
186  current_pixel0 += linesize;
187  }
188  if (!has_anything_changed)
189  break;
190  }
191 
192  /* Apply the fudge factor, which will increase the size of the
193  * mask a little to reduce jitter at the cost of more blur. */
194  for (y = 1; y < h - 1; y++)
195  for (x = 1; x < w - 1; x++)
196  data[(y * linesize) + x] = apply_mask_fudge_factor(data[(y * linesize) + x]);
197 
198  /* As a side-effect, we now know the maximum mask size, which
199  * we'll use to generate our masks. */
200  /* Apply the fudge factor to this number too, since we must ensure
201  * that enough masks are generated. */
202  *max_mask_size = apply_mask_fudge_factor(current_pass + 1);
203 }
204 
205 static int load_mask(uint8_t **mask, int *w, int *h,
206  const char *filename, void *log_ctx)
207 {
208  int ret;
209  enum AVPixelFormat pix_fmt;
210  uint8_t *src_data[4], *gray_data[4];
211  int src_linesize[4], gray_linesize[4];
212 
213  /* load image from file */
214  if ((ret = ff_load_image(src_data, src_linesize, w, h, &pix_fmt, filename, log_ctx)) < 0)
215  return ret;
216 
217  /* convert the image to GRAY8 */
218  if ((ret = ff_scale_image(gray_data, gray_linesize, *w, *h, AV_PIX_FMT_GRAY8,
219  src_data, src_linesize, *w, *h, pix_fmt,
220  log_ctx)) < 0)
221  goto end;
222 
223  /* copy mask to a newly allocated array */
224  *mask = av_malloc(*w * *h);
225  if (!*mask)
226  ret = AVERROR(ENOMEM);
227  av_image_copy_plane(*mask, *w, gray_data[0], gray_linesize[0], *w, *h);
228 
229 end:
230  av_freep(&src_data[0]);
231  av_freep(&gray_data[0]);
232  return ret;
233 }
234 
235 /**
236  * Generate a scaled down image with half width, height, and intensity.
237  *
238  * This function not only scales down an image, but halves the value
239  * in each pixel too. The purpose of this is to produce a chroma
240  * filter image out of a luma filter image. The pixel values store the
241  * distance to the edge of the logo and halving the dimensions halves
242  * the distance. This function rounds up, because a downwards rounding
243  * error could cause the filter to fail, but an upwards rounding error
244  * will only cause a minor amount of excess blur in the chroma planes.
245  */
246 static void generate_half_size_image(const uint8_t *src_data, int src_linesize,
247  uint8_t *dst_data, int dst_linesize,
248  int src_w, int src_h,
249  int *max_mask_size)
250 {
251  int x, y;
252 
253  /* Copy over the image data, using the average of 4 pixels for to
254  * calculate each downsampled pixel. */
255  for (y = 0; y < src_h/2; y++) {
256  for (x = 0; x < src_w/2; x++) {
257  /* Set the pixel if there exists a non-zero value in the
258  * source pixels, else clear it. */
259  dst_data[(y * dst_linesize) + x] =
260  src_data[((y << 1) * src_linesize) + (x << 1)] ||
261  src_data[((y << 1) * src_linesize) + (x << 1) + 1] ||
262  src_data[(((y << 1) + 1) * src_linesize) + (x << 1)] ||
263  src_data[(((y << 1) + 1) * src_linesize) + (x << 1) + 1];
264  dst_data[(y * dst_linesize) + x] = FFMIN(1, dst_data[(y * dst_linesize) + x]);
265  }
266  }
267 
268  convert_mask_to_strength_mask(dst_data, dst_linesize,
269  src_w/2, src_h/2, 0, max_mask_size);
270 }
271 
273 {
274  RemovelogoContext *s = ctx->priv;
275  int ***mask;
276  int ret = 0;
277  int a, b, c, w, h;
278  int full_max_mask_size, half_max_mask_size;
279 
280  if (!s->filename) {
281  av_log(ctx, AV_LOG_ERROR, "The bitmap file name is mandatory\n");
282  return AVERROR(EINVAL);
283  }
284 
285  /* Load our mask image. */
286  if ((ret = load_mask(&s->full_mask_data, &w, &h, s->filename, ctx)) < 0)
287  return ret;
288  s->mask_w = w;
289  s->mask_h = h;
290 
291  convert_mask_to_strength_mask(s->full_mask_data, w, w, h,
292  16, &full_max_mask_size);
293 
294  /* Create the scaled down mask image for the chroma planes. */
295  if (!(s->half_mask_data = av_mallocz(w/2 * h/2)))
296  return AVERROR(ENOMEM);
297  generate_half_size_image(s->full_mask_data, w,
298  s->half_mask_data, w/2,
299  w, h, &half_max_mask_size);
300 
301  s->max_mask_size = FFMAX(full_max_mask_size, half_max_mask_size);
302 
303  /* Create a circular mask for each size up to max_mask_size. When
304  the filter is applied, the mask size is determined on a pixel
305  by pixel basis, with pixels nearer the edge of the logo getting
306  smaller mask sizes. */
307  mask = (int ***)av_malloc_array(s->max_mask_size + 1, sizeof(int **));
308  if (!mask)
309  return AVERROR(ENOMEM);
310 
311  for (a = 0; a <= s->max_mask_size; a++) {
312  mask[a] = (int **)av_malloc_array((a * 2) + 1, sizeof(int *));
313  if (!mask[a]) {
314  av_free(mask);
315  return AVERROR(ENOMEM);
316  }
317  for (b = -a; b <= a; b++) {
318  mask[a][b + a] = (int *)av_malloc_array((a * 2) + 1, sizeof(int));
319  if (!mask[a][b + a]) {
320  av_free(mask);
321  return AVERROR(ENOMEM);
322  }
323  for (c = -a; c <= a; c++) {
324  if ((b * b) + (c * c) <= (a * a)) /* Circular 0/1 mask. */
325  mask[a][b + a][c + a] = 1;
326  else
327  mask[a][b + a][c + a] = 0;
328  }
329  }
330  }
331  s->mask = mask;
332 
333  /* Calculate our bounding rectangles, which determine in what
334  * region the logo resides for faster processing. */
335  ff_calculate_bounding_box(&s->full_mask_bbox, s->full_mask_data, w, w, h, 0, 8);
336  ff_calculate_bounding_box(&s->half_mask_bbox, s->half_mask_data, w/2, w/2, h/2, 0, 8);
337 
338 #define SHOW_LOGO_INFO(mask_type) \
339  av_log(ctx, AV_LOG_VERBOSE, #mask_type " x1:%d x2:%d y1:%d y2:%d max_mask_size:%d\n", \
340  s->mask_type##_mask_bbox.x1, s->mask_type##_mask_bbox.x2, \
341  s->mask_type##_mask_bbox.y1, s->mask_type##_mask_bbox.y2, \
342  mask_type##_max_mask_size);
343  SHOW_LOGO_INFO(full);
345 
346  return 0;
347 }
348 
350 {
351  AVFilterContext *ctx = inlink->dst;
352  RemovelogoContext *s = ctx->priv;
353 
354  if (inlink->w != s->mask_w || inlink->h != s->mask_h) {
356  "Mask image size %dx%d does not match with the input video size %dx%d\n",
357  s->mask_w, s->mask_h, inlink->w, inlink->h);
358  return AVERROR(EINVAL);
359  }
360 
361  return 0;
362 }
363 
364 /**
365  * Blur image.
366  *
367  * It takes a pixel that is inside the mask and blurs it. It does so
368  * by finding the average of all the pixels within the mask and
369  * outside of the mask.
370  *
371  * @param mask_data the mask plane to use for averaging
372  * @param image_data the image plane to blur
373  * @param w width of the image
374  * @param h height of the image
375  * @param x x-coordinate of the pixel to blur
376  * @param y y-coordinate of the pixel to blur
377  */
378 static unsigned int blur_pixel(int ***mask,
379  const uint8_t *mask_data, int mask_linesize,
380  uint8_t *image_data, int image_linesize,
381  int w, int h, int x, int y)
382 {
383  /* Mask size tells how large a circle to use. The radius is about
384  * (slightly larger than) mask size. */
385  int mask_size;
386  int start_posx, start_posy, end_posx, end_posy;
387  int i, j;
388  unsigned int accumulator = 0, divisor = 0;
389  /* What pixel we are reading out of the circular blur mask. */
390  const uint8_t *image_read_position;
391  /* What pixel we are reading out of the filter image. */
392  const uint8_t *mask_read_position;
393 
394  /* Prepare our bounding rectangle and clip it if need be. */
395  mask_size = mask_data[y * mask_linesize + x];
396  start_posx = FFMAX(0, x - mask_size);
397  start_posy = FFMAX(0, y - mask_size);
398  end_posx = FFMIN(w - 1, x + mask_size);
399  end_posy = FFMIN(h - 1, y + mask_size);
400 
401  image_read_position = image_data + image_linesize * start_posy + start_posx;
402  mask_read_position = mask_data + mask_linesize * start_posy + start_posx;
403 
404  for (j = start_posy; j <= end_posy; j++) {
405  for (i = start_posx; i <= end_posx; i++) {
406  /* Check if this pixel is in the mask or not. Only use the
407  * pixel if it is not. */
408  if (!(*mask_read_position) && mask[mask_size][i - start_posx][j - start_posy]) {
409  accumulator += *image_read_position;
410  divisor++;
411  }
412 
413  image_read_position++;
414  mask_read_position++;
415  }
416 
417  image_read_position += (image_linesize - ((end_posx + 1) - start_posx));
418  mask_read_position += (mask_linesize - ((end_posx + 1) - start_posx));
419  }
420 
421  /* If divisor is 0, it means that not a single pixel is outside of
422  the logo, so we have no data. Else we need to normalise the
423  data using the divisor. */
424  return divisor == 0 ? 255:
425  (accumulator + (divisor / 2)) / divisor; /* divide, taking into account average rounding error */
426 }
427 
428 /**
429  * Blur image plane using a mask.
430  *
431  * @param source The image to have it's logo removed.
432  * @param destination Where the output image will be stored.
433  * @param source_stride How far apart (in memory) two consecutive lines are.
434  * @param destination Same as source_stride, but for the destination image.
435  * @param width Width of the image. This is the same for source and destination.
436  * @param height Height of the image. This is the same for source and destination.
437  * @param is_image_direct If the image is direct, then source and destination are
438  * the same and we can save a lot of time by not copying pixels that
439  * haven't changed.
440  * @param filter The image that stores the distance to the edge of the logo for
441  * each pixel.
442  * @param logo_start_x smallest x-coordinate that contains at least 1 logo pixel.
443  * @param logo_start_y smallest y-coordinate that contains at least 1 logo pixel.
444  * @param logo_end_x largest x-coordinate that contains at least 1 logo pixel.
445  * @param logo_end_y largest y-coordinate that contains at least 1 logo pixel.
446  *
447  * This function processes an entire plane. Pixels outside of the logo are copied
448  * to the output without change, and pixels inside the logo have the de-blurring
449  * function applied.
450  */
451 static void blur_image(int ***mask,
452  const uint8_t *src_data, int src_linesize,
453  uint8_t *dst_data, int dst_linesize,
454  const uint8_t *mask_data, int mask_linesize,
455  int w, int h, int direct,
456  FFBoundingBox *bbox)
457 {
458  int x, y;
459  uint8_t *dst_line;
460  const uint8_t *src_line;
461 
462  if (!direct)
463  av_image_copy_plane(dst_data, dst_linesize, src_data, src_linesize, w, h);
464 
465  for (y = bbox->y1; y <= bbox->y2; y++) {
466  src_line = src_data + src_linesize * y;
467  dst_line = dst_data + dst_linesize * y;
468 
469  for (x = bbox->x1; x <= bbox->x2; x++) {
470  if (mask_data[y * mask_linesize + x]) {
471  /* Only process if we are in the mask. */
472  dst_line[x] = blur_pixel(mask,
473  mask_data, mask_linesize,
474  dst_data, dst_linesize,
475  w, h, x, y);
476  } else {
477  /* Else just copy the data. */
478  if (!direct)
479  dst_line[x] = src_line[x];
480  }
481  }
482  }
483 }
484 
485 static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
486 {
487  RemovelogoContext *s = inlink->dst->priv;
488  AVFilterLink *outlink = inlink->dst->outputs[0];
489  AVFrame *outpicref;
490  int direct = 0;
491 
492  if (av_frame_is_writable(inpicref)) {
493  direct = 1;
494  outpicref = inpicref;
495  } else {
496  outpicref = ff_get_video_buffer(outlink, outlink->w, outlink->h);
497  if (!outpicref) {
498  av_frame_free(&inpicref);
499  return AVERROR(ENOMEM);
500  }
501  av_frame_copy_props(outpicref, inpicref);
502  }
503 
504  blur_image(s->mask,
505  inpicref ->data[0], inpicref ->linesize[0],
506  outpicref->data[0], outpicref->linesize[0],
507  s->full_mask_data, inlink->w,
508  inlink->w, inlink->h, direct, &s->full_mask_bbox);
509  blur_image(s->mask,
510  inpicref ->data[1], inpicref ->linesize[1],
511  outpicref->data[1], outpicref->linesize[1],
512  s->half_mask_data, inlink->w/2,
513  inlink->w/2, inlink->h/2, direct, &s->half_mask_bbox);
514  blur_image(s->mask,
515  inpicref ->data[2], inpicref ->linesize[2],
516  outpicref->data[2], outpicref->linesize[2],
517  s->half_mask_data, inlink->w/2,
518  inlink->w/2, inlink->h/2, direct, &s->half_mask_bbox);
519 
520  if (!direct)
521  av_frame_free(&inpicref);
522 
523  return ff_filter_frame(outlink, outpicref);
524 }
525 
527 {
528  RemovelogoContext *s = ctx->priv;
529  int a, b;
530 
531  av_freep(&s->full_mask_data);
532  av_freep(&s->half_mask_data);
533 
534  if (s->mask) {
535  /* Loop through each mask. */
536  for (a = 0; a <= s->max_mask_size; a++) {
537  /* Loop through each scanline in a mask. */
538  for (b = -a; b <= a; b++) {
539  av_freep(&s->mask[a][b + a]); /* Free a scanline. */
540  }
541  av_freep(&s->mask[a]);
542  }
543  /* Free the array of pointers pointing to the masks. */
544  av_freep(&s->mask);
545  }
546 }
547 
548 static const AVFilterPad removelogo_inputs[] = {
549  {
550  .name = "default",
551  .type = AVMEDIA_TYPE_VIDEO,
552  .config_props = config_props_input,
553  .filter_frame = filter_frame,
554  },
555 };
556 
558  .name = "removelogo",
559  .description = NULL_IF_CONFIG_SMALL("Remove a TV logo based on a mask image."),
560  .priv_size = sizeof(RemovelogoContext),
561  .init = init,
562  .uninit = uninit,
566  .priv_class = &removelogo_class,
568 };
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
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(removelogo)
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
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
bbox.h
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1018
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:130
removelogo_inputs
static const AVFilterPad removelogo_inputs[]
Definition: vf_removelogo.c:548
RemovelogoContext::full_mask_bbox
FFBoundingBox full_mask_bbox
Definition: vf_removelogo.c:91
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
ff_calculate_bounding_box
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
w
uint8_t w
Definition: llviddspenc.c:38
OFFSET
#define OFFSET(x)
Definition: vf_removelogo.c:96
RemovelogoContext::mask_w
int mask_w
Definition: vf_removelogo.c:88
convert_mask_to_strength_mask
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.
Definition: vf_removelogo.c:132
AVOption
AVOption.
Definition: opt.h:346
b
#define b
Definition: input.c:41
data
const char data[16]
Definition: mxf.c:148
half
static uint8_t half(int a, int b)
Definition: mobiclip.c:538
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
Definition: vf_removelogo.c:485
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
video.h
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:365
config_props_input
static int config_props_input(AVFilterLink *inlink)
Definition: vf_removelogo.c:349
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
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
blur_pixel
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.
Definition: vf_removelogo.c:378
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:33
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
ff_video_default_filterpad
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition: video.c:37
mask
static const uint16_t mask[17]
Definition: lzw.c:38
s
#define s(width, name)
Definition: cbs_vp9.c:198
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demux_decode.c:41
ctx
AVFormatContext * ctx
Definition: movenc.c:48
removelogo_options
static const AVOption removelogo_options[]
Definition: vf_removelogo.c:98
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
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:182
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:679
RemovelogoContext::mask_h
int mask_h
Definition: vf_removelogo.c:88
apply_mask_fudge_factor
#define apply_mask_fudge_factor(x)
Choose a slightly larger mask size to improve performance.
Definition: vf_removelogo.c:116
RemovelogoContext::half_mask_data
uint8_t * half_mask_data
Definition: vf_removelogo.c:92
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
accumulator
#define accumulator
Definition: phase_template.c:33
RemovelogoContext::half_mask_bbox
FFBoundingBox half_mask_bbox
Definition: vf_removelogo.c:93
FFBoundingBox::x1
int x1
Definition: bbox.h:27
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
RemovelogoContext::max_mask_size
int max_mask_size
Definition: vf_removelogo.c:87
SHOW_LOGO_INFO
#define SHOW_LOGO_INFO(mask_type)
blur_image
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.
Definition: vf_removelogo.c:451
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:615
ff_load_image
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:34
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
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:147
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: internal.h:172
FFBoundingBox::y1
int y1
Definition: bbox.h:27
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
RemovelogoContext::mask
int *** mask
Definition: vf_removelogo.c:86
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_removelogo.c:526
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
ff_vf_removelogo
const AVFilter ff_vf_removelogo
Definition: vf_removelogo.c:557
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:39
AVFilter
Filter definition.
Definition: avfilter.h:166
ret
ret
Definition: filter_design.txt:187
generate_half_size_image
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.
Definition: vf_removelogo.c:246
RemovelogoContext
This code implements a filter to remove annoying TV logos and other annoying images placed onto a vid...
Definition: vf_removelogo.c:81
avfilter.h
lavfutils.h
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_removelogo.c:272
AVFilterContext
An instance of a filter.
Definition: avfilter.h:407
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
FFBoundingBox
Definition: bbox.h:26
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:183
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
imgutils.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:389
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
RemovelogoContext::filename
char * filename
Definition: vf_removelogo.c:83
load_mask
static int load_mask(uint8_t **mask, int *w, int *h, const char *filename, void *log_ctx)
Definition: vf_removelogo.c:205
FLAGS
#define FLAGS
Definition: vf_removelogo.c:97
h
h
Definition: vp9dsp_template.c:2038
RemovelogoContext::full_mask_data
uint8_t * full_mask_data
Definition: vf_removelogo.c:90
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:239
int
int
Definition: ffmpeg_filter.c:409
ff_scale_image
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
lswsutils.h