97 #define OFFSET(x) offsetof(RemovelogoContext, x)
98 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
117 #define apply_mask_fudge_factor(x) (((x) >> 2) + (x))
134 int w,
int h,
int min_val,
141 int current_pass = 0;
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;
156 int has_anything_changed = 0;
157 uint8_t *current_pixel0 = data + 1 + linesize, *current_pixel;
160 for (y = 1; y < h-1; y++) {
161 current_pixel = current_pixel0;
162 for (x = 1; x < w-1; x++) {
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) {
183 has_anything_changed = 1;
187 current_pixel0 += linesize;
189 if (!has_anything_changed)
195 for (y = 1; y < h - 1; y++)
196 for (x = 1; x < w - 1; x++)
214 const char *filename,
void *log_ctx)
218 uint8_t *src_data[4], *gray_data[4];
219 int src_linesize[4], gray_linesize[4];
222 if ((ret =
ff_load_image(src_data, src_linesize, w, h, &pix_fmt, filename, log_ctx)) < 0)
227 src_data, src_linesize, *w, *h, pix_fmt,
255 uint8_t *dst_data,
int dst_linesize,
256 int src_w,
int src_h,
263 for (y = 0; y < src_h/2; y++) {
264 for (x = 0; x < src_w/2; x++) {
267 dst_data[(y * dst_linesize) + x] =
268 src_data[((y << 1) * src_linesize) + (x << 1)] ||
269 src_data[((y << 1) * src_linesize) + (x << 1) + 1] ||
270 src_data[(((y << 1) + 1) * src_linesize) + (x << 1)] ||
271 src_data[(((y << 1) + 1) * src_linesize) + (x << 1) + 1];
272 dst_data[(y * dst_linesize) + x] =
FFMIN(1, dst_data[(y * dst_linesize) + x]);
277 src_w/2, src_h/2, 0, max_mask_size);
286 int full_max_mask_size, half_max_mask_size;
300 16, &full_max_mask_size);
307 w, h, &half_max_mask_size);
325 for (b = -a; b <=
a; b++) {
327 if (!mask[a][b + a]) {
331 for (c = -a; c <=
a; c++) {
332 if ((b * b) + (c * c) <= (a * a))
333 mask[
a][b +
a][c +
a] = 1;
335 mask[
a][b +
a][c +
a] = 0;
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);
364 "Mask image size %dx%d does not match with the input video size %dx%d\n",
387 const uint8_t *mask_data,
int mask_linesize,
388 uint8_t *image_data,
int image_linesize,
389 int w,
int h,
int x,
int y)
394 int start_posx, start_posy, end_posx, end_posy;
396 unsigned int accumulator = 0, divisor = 0;
398 const uint8_t *image_read_position;
400 const uint8_t *mask_read_position;
403 mask_size = mask_data[y * mask_linesize + x];
404 start_posx =
FFMAX(0, x - mask_size);
405 start_posy =
FFMAX(0, y - mask_size);
406 end_posx =
FFMIN(w - 1, x + mask_size);
407 end_posy =
FFMIN(h - 1, y + mask_size);
409 image_read_position = image_data + image_linesize * start_posy + start_posx;
410 mask_read_position = mask_data + mask_linesize * start_posy + start_posx;
412 for (j = start_posy; j <= end_posy; j++) {
413 for (i = start_posx; i <= end_posx; i++) {
416 if (!(*mask_read_position) && mask[mask_size][i - start_posx][j - start_posy]) {
417 accumulator += *image_read_position;
421 image_read_position++;
422 mask_read_position++;
425 image_read_position += (image_linesize - ((end_posx + 1) - start_posx));
426 mask_read_position += (mask_linesize - ((end_posx + 1) - start_posx));
432 return divisor == 0 ? 255:
433 (accumulator + (divisor / 2)) / divisor;
460 const uint8_t *src_data,
int src_linesize,
461 uint8_t *dst_data,
int dst_linesize,
462 const uint8_t *mask_data,
int mask_linesize,
463 int w,
int h,
int direct,
473 for (y = bbox->
y1; y <= bbox->y2; y++) {
474 src_line = src_data + src_linesize *
y;
475 dst_line = dst_data + dst_linesize *
y;
477 for (x = bbox->
x1; x <= bbox->x2; x++) {
478 if (mask_data[y * mask_linesize + x]) {
481 mask_data, mask_linesize,
482 dst_data, dst_linesize,
487 dst_line[x] = src_line[x];
502 outpicref = inpicref;
546 for (b = -a; b <=
a; b++) {
575 .
name =
"removelogo",
581 .
inputs = removelogo_inputs,
583 .priv_class = &removelogo_class,
static enum AVPixelFormat pix_fmt
This code implements a filter to remove annoying TV logos and other annoying images placed onto a vid...
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
AVFILTER_DEFINE_CLASS(removelogo)
static const AVFilterPad outputs[]
Main libavfilter public API header.
int h
agreed upon image height
Miscellaneous utilities which make use of the libswscale library.
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.
AVFilter ff_vf_removelogo
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
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)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static av_cold void uninit(AVFilterContext *ctx)
static av_cold int end(AVCodecContext *avctx)
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.
FFBoundingBox full_mask_bbox
A filter pad used for either input or output.
A link between two filters.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const uint16_t mask[17]
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define apply_mask_fudge_factor(x)
Choose a slightly larger mask size to improve performance.
static const AVFilterPad removelogo_outputs[]
static av_cold int init(AVFilterContext *ctx)
int w
agreed upon image width
static const AVOption removelogo_options[]
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.
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.
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.
#define AV_LOG_INFO
Standard information.
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
static const AVFilterPad removelogo_inputs[]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
const char * name
Filter name.
static int config_props_input(AVFilterLink *inlink)
AVFilterLink ** outputs
array of pointers to output links
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
int ff_calculate_bounding_box(FFBoundingBox *bbox, const uint8_t *data, int linesize, int w, int h, int min_val)
Calculate the smallest rectangle that will encompass the region with values > min_val.
static int load_mask(uint8_t **mask, int *w, int *h, const char *filename, void *log_ctx)
AVFilterContext * dst
dest filter
static int query_formats(AVFilterContext *ctx)
#define av_malloc_array(a, b)
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.
FFBoundingBox half_mask_bbox
AVPixelFormat
Pixel format.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Miscellaneous utilities which make use of the libavformat library.