vf_removelogo.c 23 KB

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