#include "libavutil/imgutils.h"
#include "avfilter.h"
#include "bbox.h"
#include "lavfutils.h"
#include "lswsutils.h"
Go to the source code of this file.
Data Structures | |
struct | RemovelogoContext |
This code implements a filter to remove annoying TV logos and other annoying images placed onto a video stream. More... | |
Defines | |
#define | apply_mask_fudge_factor(x) (((x) >> 2) + x) |
Choose a slightly larger mask size to improve performance. | |
#define | SHOW_LOGO_INFO(mask_type) |
Functions | |
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 int | query_formats (AVFilterContext *ctx) |
static int | load_mask (uint8_t **mask, int *w, int *h, const char *filename, void *log_ctx) |
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 av_cold int | init (AVFilterContext *ctx, const char *args, void *opaque) |
static int | config_props_input (AVFilterLink *inlink) |
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. | |
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. | |
static void | start_frame (AVFilterLink *inlink, AVFilterBufferRef *inpicref) |
static void | end_frame (AVFilterLink *inlink) |
static void | uninit (AVFilterContext *ctx) |
static void | null_draw_slice (AVFilterLink *link, int y, int h, int slice_dir) |
Variables | |
AVFilter | avfilter_vf_removelogo |
This filter loads an image mask file showing where a logo is and uses a blur transform to remove the logo.
Based on the libmpcodecs remove-logo filter by Robert Edele.
Definition in file vf_removelogo.c.
#define apply_mask_fudge_factor | ( | x | ) | (((x) >> 2) + x) |
Choose a slightly larger mask size to improve performance.
This function maps the absolute minimum mask size needed to the mask size we'll actually use. f(x) = x (the smallest that will work) will produce the sharpest results, but will be quite jittery. f(x) = 1.25x (what I'm using) is a good tradeoff in my opinion. This will calculate only at init-time, so you can put a long expression here without effecting performance.
Definition at line 101 of file vf_removelogo.c.
Referenced by convert_mask_to_strength_mask().
#define SHOW_LOGO_INFO | ( | mask_type | ) |
Value:
av_log(ctx, AV_LOG_INFO, #mask_type " x1:%d x2:%d y1:%d y2:%d max_mask_size:%d\n", \ removelogo->mask_type##_mask_bbox.x1, removelogo->mask_type##_mask_bbox.x2, \ removelogo->mask_type##_mask_bbox.y1, removelogo->mask_type##_mask_bbox.y2, \ mask_type##_max_mask_size);
Referenced by init().
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 | |||
) | [static] |
Blur image plane using a mask.
source | The image to have it's logo removed. | |
destination | Where the output image will be stored. | |
source_stride | How far apart (in memory) two consecutive lines are. | |
destination | Same as source_stride, but for the destination image. | |
width | Width of the image. This is the same for source and destination. | |
height | Height of the image. This is the same for source and destination. | |
is_image_direct | If the image is direct, then source and destination are the same and we can save a lot of time by not copying pixels that haven't changed. | |
filter | The image that stores the distance to the edge of the logo for each pixel. | |
logo_start_x | smallest x-coordinate that contains at least 1 logo pixel. | |
logo_start_y | smallest y-coordinate that contains at least 1 logo pixel. | |
logo_end_x | largest x-coordinate that contains at least 1 logo pixel. | |
logo_end_y | largest y-coordinate that contains at least 1 logo pixel. |
Definition at line 439 of file vf_removelogo.c.
Referenced by end_frame().
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 | |||
) | [static] |
Blur image.
It takes a pixel that is inside the mask and blurs it. It does so by finding the average of all the pixels within the mask and outside of the mask.
mask_data | the mask plane to use for averaging | |
image_data | the image plane to blur | |
w | width of the image | |
h | height of the image | |
x | x-coordinate of the pixel to blur | |
y | y-coordinate of the pixel to blur |
Definition at line 366 of file vf_removelogo.c.
Referenced by blur_image().
static int config_props_input | ( | AVFilterLink * | inlink | ) | [static] |
Definition at line 337 of file vf_removelogo.c.
static void convert_mask_to_strength_mask | ( | uint8_t * | data, | |
int | linesize, | |||
int | w, | |||
int | h, | |||
int | min_val, | |||
int * | max_mask_size | |||
) | [static] |
Pre-process an image to give distance information.
This function takes a bitmap image and converts it in place into a distance image. A distance image is zero for pixels outside of the logo and is the Manhattan distance (|dx| + |dy|) from the logo edge for pixels inside of the logo. This will overestimate the distance, but that is safe, and is far easier to implement than a proper pythagorean distance since I'm using a modified erosion algorithm to compute the distances.
mask | image which will be converted from a greyscale image into a distance image. |
Definition at line 117 of file vf_removelogo.c.
Referenced by generate_half_size_image(), and init().
static void end_frame | ( | AVFilterLink * | inlink | ) | [static] |
Definition at line 491 of file vf_removelogo.c.
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 | |||
) | [static] |
Generate a scaled down image with half width, height, and intensity.
This function not only scales down an image, but halves the value in each pixel too. The purpose of this is to produce a chroma filter image out of a luma filter image. The pixel values store the distance to the edge of the logo and halving the dimensions halves the distance. This function rounds up, because a downwards rounding error could cause the filter to fail, but an upwards rounding error will only cause a minor amount of excess blur in the chroma planes.
Definition at line 238 of file vf_removelogo.c.
Referenced by init().
static av_cold int init | ( | AVFilterContext * | ctx, | |
const char * | args, | |||
void * | opaque | |||
) | [static] |
Definition at line 264 of file vf_removelogo.c.
static int load_mask | ( | uint8_t ** | mask, | |
int * | w, | |||
int * | h, | |||
const char * | filename, | |||
void * | log_ctx | |||
) | [static] |
static void null_draw_slice | ( | AVFilterLink * | link, | |
int | y, | |||
int | h, | |||
int | slice_dir | |||
) | [static] |
Definition at line 544 of file vf_removelogo.c.
static int query_formats | ( | AVFilterContext * | ctx | ) | [static] |
Definition at line 190 of file vf_removelogo.c.
static void start_frame | ( | AVFilterLink * | inlink, | |
AVFilterBufferRef * | inpicref | |||
) | [static] |
Definition at line 473 of file vf_removelogo.c.
static void uninit | ( | AVFilterContext * | ctx | ) | [static] |
Definition at line 522 of file vf_removelogo.c.
Initial value:
{ .name = "removelogo", .description = NULL_IF_CONFIG_SMALL("Remove a TV logo based on a mask image."), .priv_size = sizeof(RemovelogoContext), .init = init, .uninit = uninit, .query_formats = query_formats, .inputs = (const AVFilterPad[]) { { .name = "default", .type = AVMEDIA_TYPE_VIDEO, .get_video_buffer = avfilter_null_get_video_buffer, .config_props = config_props_input, .draw_slice = null_draw_slice, .start_frame = start_frame, .end_frame = end_frame, .min_perms = AV_PERM_WRITE | AV_PERM_READ, .rej_perms = AV_PERM_PRESERVE }, { .name = NULL } }, .outputs = (const AVFilterPad[]) { { .name = "default", .type = AVMEDIA_TYPE_VIDEO, }, { .name = NULL } }, }
Definition at line 546 of file vf_removelogo.c.