2011-08-10 19:58:49 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2002 Jindrich Makovicka <makovick@gmail.com>
|
|
|
|
* Copyright (c) 2011 Stefano Sabatini
|
lavfi/delogo: use weighted interpolation
The original delogo algorithm interpolates both horizontally and
vertically and uses the average to compute the resulting sample. This
works reasonably well when the logo area is almost square. However
when the logo area is significantly larger than high or higher than
large, the result is largely suboptimal.
The issue can be clearly seen by testing the delogo filter with a fake
logo area that is 200 pixels large and 2 pixels high. Vertical
interpolation gives a very good result in that case, horizontal
interpolation gives a very bad result, and the overall result is poor,
because both are given the same weight.
Even when the logo is roughly square, the current algorithm gives poor
results on the borders of the logo area, because it always gives
horizontal and vertical interpolations an equal weight, and this is
suboptimal on borders. For example, in the middle of the left hand
side border of the logo, you want to trust the left known point much
more than the right known point (which the current algorithm already
does) but also much more than the top and bottom known points (which
the current algorithm doesn't do.)
By properly weighting each known point when computing the value of
each interpolated pixel, the visual result is much better, especially
on borders and/or for high or large logo areas.
The algorithm I implemented guarantees that the weight of each of the
4 known points directly depends on its distance to the interpolated
point. It is largely inspired from the original algorithm, the key
difference being that it computes the relative weights globally
instead of separating the vertical and horizontal interpolations and
combining them afterward.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
2013-06-26 15:50:37 +03:00
|
|
|
* Copyright (c) 2013 Jean Delvare <khali@linux-fr.org>
|
2011-08-10 19:58:49 +03:00
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with FFmpeg; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* A very simple tv station logo remover
|
lavfi/delogo: use weighted interpolation
The original delogo algorithm interpolates both horizontally and
vertically and uses the average to compute the resulting sample. This
works reasonably well when the logo area is almost square. However
when the logo area is significantly larger than high or higher than
large, the result is largely suboptimal.
The issue can be clearly seen by testing the delogo filter with a fake
logo area that is 200 pixels large and 2 pixels high. Vertical
interpolation gives a very good result in that case, horizontal
interpolation gives a very bad result, and the overall result is poor,
because both are given the same weight.
Even when the logo is roughly square, the current algorithm gives poor
results on the borders of the logo area, because it always gives
horizontal and vertical interpolations an equal weight, and this is
suboptimal on borders. For example, in the middle of the left hand
side border of the logo, you want to trust the left known point much
more than the right known point (which the current algorithm already
does) but also much more than the top and bottom known points (which
the current algorithm doesn't do.)
By properly weighting each known point when computing the value of
each interpolated pixel, the visual result is much better, especially
on borders and/or for high or large logo areas.
The algorithm I implemented guarantees that the weight of each of the
4 known points directly depends on its distance to the interpolated
point. It is largely inspired from the original algorithm, the key
difference being that it computes the relative weights globally
instead of separating the vertical and horizontal interpolations and
combining them afterward.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
2013-06-26 15:50:37 +03:00
|
|
|
* Originally imported from MPlayer libmpcodecs/vf_delogo.c,
|
|
|
|
* the algorithm was later improved.
|
2011-08-10 19:58:49 +03:00
|
|
|
*/
|
|
|
|
|
2012-08-06 16:49:32 +03:00
|
|
|
#include "libavutil/common.h"
|
2011-08-10 19:58:49 +03:00
|
|
|
#include "libavutil/imgutils.h"
|
|
|
|
#include "libavutil/opt.h"
|
|
|
|
#include "libavutil/pixdesc.h"
|
|
|
|
#include "avfilter.h"
|
2012-05-30 11:12:55 +03:00
|
|
|
#include "formats.h"
|
2012-06-12 21:12:42 +03:00
|
|
|
#include "internal.h"
|
2012-05-19 11:37:56 +03:00
|
|
|
#include "video.h"
|
2011-08-10 19:58:49 +03:00
|
|
|
|
|
|
|
/**
|
2013-06-19 17:07:09 +03:00
|
|
|
* Apply a simple delogo algorithm to the image in src and put the
|
|
|
|
* result in dst.
|
2011-08-10 19:58:49 +03:00
|
|
|
*
|
|
|
|
* The algorithm is only applied to the region specified by the logo
|
|
|
|
* parameters.
|
|
|
|
*
|
|
|
|
* @param w width of the input image
|
|
|
|
* @param h height of the input image
|
|
|
|
* @param logo_x x coordinate of the top left corner of the logo region
|
|
|
|
* @param logo_y y coordinate of the top left corner of the logo region
|
|
|
|
* @param logo_w width of the logo
|
|
|
|
* @param logo_h height of the logo
|
|
|
|
* @param band the size of the band around the processed area
|
|
|
|
* @param show show a rectangle around the processed area, useful for
|
|
|
|
* parameters tweaking
|
|
|
|
* @param direct if non-zero perform in-place processing
|
|
|
|
*/
|
|
|
|
static void apply_delogo(uint8_t *dst, int dst_linesize,
|
|
|
|
uint8_t *src, int src_linesize,
|
2013-07-01 17:28:59 +03:00
|
|
|
int w, int h, AVRational sar,
|
2011-08-10 19:58:49 +03:00
|
|
|
int logo_x, int logo_y, int logo_w, int logo_h,
|
|
|
|
int band, int show, int direct)
|
|
|
|
{
|
lavfi/delogo: use weighted interpolation
The original delogo algorithm interpolates both horizontally and
vertically and uses the average to compute the resulting sample. This
works reasonably well when the logo area is almost square. However
when the logo area is significantly larger than high or higher than
large, the result is largely suboptimal.
The issue can be clearly seen by testing the delogo filter with a fake
logo area that is 200 pixels large and 2 pixels high. Vertical
interpolation gives a very good result in that case, horizontal
interpolation gives a very bad result, and the overall result is poor,
because both are given the same weight.
Even when the logo is roughly square, the current algorithm gives poor
results on the borders of the logo area, because it always gives
horizontal and vertical interpolations an equal weight, and this is
suboptimal on borders. For example, in the middle of the left hand
side border of the logo, you want to trust the left known point much
more than the right known point (which the current algorithm already
does) but also much more than the top and bottom known points (which
the current algorithm doesn't do.)
By properly weighting each known point when computing the value of
each interpolated pixel, the visual result is much better, especially
on borders and/or for high or large logo areas.
The algorithm I implemented guarantees that the weight of each of the
4 known points directly depends on its distance to the interpolated
point. It is largely inspired from the original algorithm, the key
difference being that it computes the relative weights globally
instead of separating the vertical and horizontal interpolations and
combining them afterward.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
2013-06-26 15:50:37 +03:00
|
|
|
int x, y, dist;
|
|
|
|
uint64_t interp, weightl, weightr, weightt, weightb;
|
2011-08-10 19:58:49 +03:00
|
|
|
uint8_t *xdst, *xsrc;
|
|
|
|
|
|
|
|
uint8_t *topleft, *botleft, *topright;
|
|
|
|
int xclipl, xclipr, yclipt, yclipb;
|
|
|
|
int logo_x1, logo_x2, logo_y1, logo_y2;
|
|
|
|
|
|
|
|
xclipl = FFMAX(-logo_x, 0);
|
|
|
|
xclipr = FFMAX(logo_x+logo_w-w, 0);
|
|
|
|
yclipt = FFMAX(-logo_y, 0);
|
|
|
|
yclipb = FFMAX(logo_y+logo_h-h, 0);
|
|
|
|
|
|
|
|
logo_x1 = logo_x + xclipl;
|
|
|
|
logo_x2 = logo_x + logo_w - xclipr;
|
|
|
|
logo_y1 = logo_y + yclipt;
|
|
|
|
logo_y2 = logo_y + logo_h - yclipb;
|
|
|
|
|
|
|
|
topleft = src+logo_y1 * src_linesize+logo_x1;
|
|
|
|
topright = src+logo_y1 * src_linesize+logo_x2-1;
|
|
|
|
botleft = src+(logo_y2-1) * src_linesize+logo_x1;
|
|
|
|
|
|
|
|
if (!direct)
|
|
|
|
av_image_copy_plane(dst, dst_linesize, src, src_linesize, w, h);
|
|
|
|
|
2013-01-21 23:48:49 +03:00
|
|
|
dst += (logo_y1 + 1) * dst_linesize;
|
|
|
|
src += (logo_y1 + 1) * src_linesize;
|
2012-11-28 20:03:03 +03:00
|
|
|
|
2011-08-10 19:58:49 +03:00
|
|
|
for (y = logo_y1+1; y < logo_y2-1; y++) {
|
|
|
|
for (x = logo_x1+1,
|
|
|
|
xdst = dst+logo_x1+1,
|
|
|
|
xsrc = src+logo_x1+1; x < logo_x2-1; x++, xdst++, xsrc++) {
|
lavfi/delogo: use weighted interpolation
The original delogo algorithm interpolates both horizontally and
vertically and uses the average to compute the resulting sample. This
works reasonably well when the logo area is almost square. However
when the logo area is significantly larger than high or higher than
large, the result is largely suboptimal.
The issue can be clearly seen by testing the delogo filter with a fake
logo area that is 200 pixels large and 2 pixels high. Vertical
interpolation gives a very good result in that case, horizontal
interpolation gives a very bad result, and the overall result is poor,
because both are given the same weight.
Even when the logo is roughly square, the current algorithm gives poor
results on the borders of the logo area, because it always gives
horizontal and vertical interpolations an equal weight, and this is
suboptimal on borders. For example, in the middle of the left hand
side border of the logo, you want to trust the left known point much
more than the right known point (which the current algorithm already
does) but also much more than the top and bottom known points (which
the current algorithm doesn't do.)
By properly weighting each known point when computing the value of
each interpolated pixel, the visual result is much better, especially
on borders and/or for high or large logo areas.
The algorithm I implemented guarantees that the weight of each of the
4 known points directly depends on its distance to the interpolated
point. It is largely inspired from the original algorithm, the key
difference being that it computes the relative weights globally
instead of separating the vertical and horizontal interpolations and
combining them afterward.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
2013-06-26 15:50:37 +03:00
|
|
|
|
2013-07-01 17:28:59 +03:00
|
|
|
/* Weighted interpolation based on relative distances, taking SAR into account */
|
|
|
|
weightl = (uint64_t) (logo_x2-1-x) * (y-logo_y1) * (logo_y2-1-y) * sar.den;
|
|
|
|
weightr = (uint64_t)(x-logo_x1) * (y-logo_y1) * (logo_y2-1-y) * sar.den;
|
|
|
|
weightt = (uint64_t)(x-logo_x1) * (logo_x2-1-x) * (logo_y2-1-y) * sar.num;
|
|
|
|
weightb = (uint64_t)(x-logo_x1) * (logo_x2-1-x) * (y-logo_y1) * sar.num;
|
lavfi/delogo: use weighted interpolation
The original delogo algorithm interpolates both horizontally and
vertically and uses the average to compute the resulting sample. This
works reasonably well when the logo area is almost square. However
when the logo area is significantly larger than high or higher than
large, the result is largely suboptimal.
The issue can be clearly seen by testing the delogo filter with a fake
logo area that is 200 pixels large and 2 pixels high. Vertical
interpolation gives a very good result in that case, horizontal
interpolation gives a very bad result, and the overall result is poor,
because both are given the same weight.
Even when the logo is roughly square, the current algorithm gives poor
results on the borders of the logo area, because it always gives
horizontal and vertical interpolations an equal weight, and this is
suboptimal on borders. For example, in the middle of the left hand
side border of the logo, you want to trust the left known point much
more than the right known point (which the current algorithm already
does) but also much more than the top and bottom known points (which
the current algorithm doesn't do.)
By properly weighting each known point when computing the value of
each interpolated pixel, the visual result is much better, especially
on borders and/or for high or large logo areas.
The algorithm I implemented guarantees that the weight of each of the
4 known points directly depends on its distance to the interpolated
point. It is largely inspired from the original algorithm, the key
difference being that it computes the relative weights globally
instead of separating the vertical and horizontal interpolations and
combining them afterward.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
2013-06-26 15:50:37 +03:00
|
|
|
|
2011-08-10 19:58:49 +03:00
|
|
|
interp =
|
2013-07-05 11:23:18 +03:00
|
|
|
(topleft[src_linesize*(y-logo_y1)] +
|
|
|
|
topleft[src_linesize*(y-logo_y1-1)] +
|
|
|
|
topleft[src_linesize*(y-logo_y1+1)]) * weightl
|
2011-08-10 19:58:49 +03:00
|
|
|
+
|
2013-07-05 11:23:18 +03:00
|
|
|
(topright[src_linesize*(y-logo_y1)] +
|
|
|
|
topright[src_linesize*(y-logo_y1-1)] +
|
|
|
|
topright[src_linesize*(y-logo_y1+1)]) * weightr
|
2011-08-10 19:58:49 +03:00
|
|
|
+
|
2013-07-05 11:23:18 +03:00
|
|
|
(topleft[x-logo_x1] +
|
|
|
|
topleft[x-logo_x1-1] +
|
|
|
|
topleft[x-logo_x1+1]) * weightt
|
2011-08-10 19:58:49 +03:00
|
|
|
+
|
2013-07-05 11:23:18 +03:00
|
|
|
(botleft[x-logo_x1] +
|
|
|
|
botleft[x-logo_x1-1] +
|
|
|
|
botleft[x-logo_x1+1]) * weightb;
|
lavfi/delogo: use weighted interpolation
The original delogo algorithm interpolates both horizontally and
vertically and uses the average to compute the resulting sample. This
works reasonably well when the logo area is almost square. However
when the logo area is significantly larger than high or higher than
large, the result is largely suboptimal.
The issue can be clearly seen by testing the delogo filter with a fake
logo area that is 200 pixels large and 2 pixels high. Vertical
interpolation gives a very good result in that case, horizontal
interpolation gives a very bad result, and the overall result is poor,
because both are given the same weight.
Even when the logo is roughly square, the current algorithm gives poor
results on the borders of the logo area, because it always gives
horizontal and vertical interpolations an equal weight, and this is
suboptimal on borders. For example, in the middle of the left hand
side border of the logo, you want to trust the left known point much
more than the right known point (which the current algorithm already
does) but also much more than the top and bottom known points (which
the current algorithm doesn't do.)
By properly weighting each known point when computing the value of
each interpolated pixel, the visual result is much better, especially
on borders and/or for high or large logo areas.
The algorithm I implemented guarantees that the weight of each of the
4 known points directly depends on its distance to the interpolated
point. It is largely inspired from the original algorithm, the key
difference being that it computes the relative weights globally
instead of separating the vertical and horizontal interpolations and
combining them afterward.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Stefano Sabatini <stefasab@gmail.com>
2013-06-26 15:50:37 +03:00
|
|
|
interp /= (weightl + weightr + weightt + weightb) * 3U;
|
2011-08-10 19:58:49 +03:00
|
|
|
|
|
|
|
if (y >= logo_y+band && y < logo_y+logo_h-band &&
|
|
|
|
x >= logo_x+band && x < logo_x+logo_w-band) {
|
|
|
|
*xdst = interp;
|
|
|
|
} else {
|
|
|
|
dist = 0;
|
|
|
|
if (x < logo_x+band)
|
|
|
|
dist = FFMAX(dist, logo_x-x+band);
|
|
|
|
else if (x >= logo_x+logo_w-band)
|
|
|
|
dist = FFMAX(dist, x-(logo_x+logo_w-1-band));
|
|
|
|
|
|
|
|
if (y < logo_y+band)
|
|
|
|
dist = FFMAX(dist, logo_y-y+band);
|
|
|
|
else if (y >= logo_y+logo_h-band)
|
|
|
|
dist = FFMAX(dist, y-(logo_y+logo_h-1-band));
|
|
|
|
|
|
|
|
*xdst = (*xsrc*dist + interp*(band-dist))/band;
|
|
|
|
if (show && (dist == band-1))
|
|
|
|
*xdst = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dst += dst_linesize;
|
|
|
|
src += src_linesize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const AVClass *class;
|
|
|
|
int x, y, w, h, band, show;
|
|
|
|
} DelogoContext;
|
|
|
|
|
|
|
|
#define OFFSET(x) offsetof(DelogoContext, x)
|
2012-08-13 14:40:01 +03:00
|
|
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
|
2011-08-10 19:58:49 +03:00
|
|
|
|
|
|
|
static const AVOption delogo_options[]= {
|
2013-02-25 23:21:29 +03:00
|
|
|
{ "x", "set logo x position", OFFSET(x), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
|
|
|
|
{ "y", "set logo y position", OFFSET(y), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
|
|
|
|
{ "w", "set logo width", OFFSET(w), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
|
|
|
|
{ "h", "set logo height", OFFSET(h), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, FLAGS },
|
|
|
|
{ "band", "set delogo area band size", OFFSET(band), AV_OPT_TYPE_INT, { .i64 = 4 }, -1, INT_MAX, FLAGS },
|
|
|
|
{ "t", "set delogo area band size", OFFSET(band), AV_OPT_TYPE_INT, { .i64 = 4 }, -1, INT_MAX, FLAGS },
|
|
|
|
{ "show", "show delogo area", OFFSET(show), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
|
|
|
|
{ NULL },
|
2011-08-10 19:58:49 +03:00
|
|
|
};
|
|
|
|
|
2012-06-22 15:33:09 +03:00
|
|
|
AVFILTER_DEFINE_CLASS(delogo);
|
2011-08-10 19:58:49 +03:00
|
|
|
|
|
|
|
static int query_formats(AVFilterContext *ctx)
|
|
|
|
{
|
2012-12-22 01:38:59 +03:00
|
|
|
static const enum AVPixelFormat pix_fmts[] = {
|
2012-10-06 13:10:34 +03:00
|
|
|
AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV420P,
|
|
|
|
AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV440P,
|
|
|
|
AV_PIX_FMT_YUVA420P, AV_PIX_FMT_GRAY8,
|
|
|
|
AV_PIX_FMT_NONE
|
2011-08-10 19:58:49 +03:00
|
|
|
};
|
|
|
|
|
2012-05-30 11:12:55 +03:00
|
|
|
ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
|
2011-08-10 19:58:49 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-13 10:26:39 +03:00
|
|
|
static av_cold int init(AVFilterContext *ctx)
|
2011-08-10 19:58:49 +03:00
|
|
|
{
|
2013-03-18 22:44:36 +03:00
|
|
|
DelogoContext *s = ctx->priv;
|
2011-08-10 19:58:49 +03:00
|
|
|
|
|
|
|
#define CHECK_UNSET_OPT(opt) \
|
2013-03-18 22:44:36 +03:00
|
|
|
if (s->opt == -1) { \
|
|
|
|
av_log(s, AV_LOG_ERROR, "Option %s was not set.\n", #opt); \
|
2011-08-10 19:58:49 +03:00
|
|
|
return AVERROR(EINVAL); \
|
|
|
|
}
|
|
|
|
CHECK_UNSET_OPT(x);
|
|
|
|
CHECK_UNSET_OPT(y);
|
|
|
|
CHECK_UNSET_OPT(w);
|
|
|
|
CHECK_UNSET_OPT(h);
|
|
|
|
|
2013-05-16 11:14:00 +03:00
|
|
|
if (s->band < 0 || s->show) {
|
|
|
|
s->show = 1;
|
2013-03-18 22:44:36 +03:00
|
|
|
s->band = 4;
|
2013-03-13 06:21:53 +03:00
|
|
|
}
|
2011-08-10 19:58:49 +03:00
|
|
|
|
2012-07-14 19:26:04 +03:00
|
|
|
av_log(ctx, AV_LOG_VERBOSE, "x:%d y:%d, w:%d h:%d band:%d show:%d\n",
|
2013-03-18 22:44:36 +03:00
|
|
|
s->x, s->y, s->w, s->h, s->band, s->show);
|
2011-08-10 19:58:49 +03:00
|
|
|
|
2013-03-18 22:44:36 +03:00
|
|
|
s->w += s->band*2;
|
|
|
|
s->h += s->band*2;
|
|
|
|
s->x -= s->band;
|
|
|
|
s->y -= s->band;
|
2011-08-10 19:58:49 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-28 10:41:07 +03:00
|
|
|
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
2011-08-10 19:58:49 +03:00
|
|
|
{
|
2013-03-18 22:44:36 +03:00
|
|
|
DelogoContext *s = inlink->dst->priv;
|
2011-08-10 19:58:49 +03:00
|
|
|
AVFilterLink *outlink = inlink->dst->outputs[0];
|
2012-10-06 14:29:37 +03:00
|
|
|
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
|
2012-11-28 10:41:07 +03:00
|
|
|
AVFrame *out;
|
2012-10-06 14:29:37 +03:00
|
|
|
int hsub0 = desc->log2_chroma_w;
|
|
|
|
int vsub0 = desc->log2_chroma_h;
|
2012-11-28 20:05:40 +03:00
|
|
|
int direct = 0;
|
2011-08-10 19:58:49 +03:00
|
|
|
int plane;
|
2013-07-01 17:28:59 +03:00
|
|
|
AVRational sar;
|
2011-08-10 19:58:49 +03:00
|
|
|
|
2012-11-28 10:41:07 +03:00
|
|
|
if (av_frame_is_writable(in)) {
|
2012-11-28 20:05:40 +03:00
|
|
|
direct = 1;
|
|
|
|
out = in;
|
|
|
|
} else {
|
2012-11-28 10:41:07 +03:00
|
|
|
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
|
2012-11-28 20:05:40 +03:00
|
|
|
if (!out) {
|
2012-11-28 10:41:07 +03:00
|
|
|
av_frame_free(&in);
|
2012-11-28 20:05:40 +03:00
|
|
|
return AVERROR(ENOMEM);
|
|
|
|
}
|
2012-11-27 09:49:45 +03:00
|
|
|
|
2012-11-28 10:41:07 +03:00
|
|
|
av_frame_copy_props(out, in);
|
2012-11-28 20:05:40 +03:00
|
|
|
}
|
|
|
|
|
2013-07-01 17:28:59 +03:00
|
|
|
sar = in->sample_aspect_ratio;
|
|
|
|
/* Assume square pixels if SAR is unknown */
|
|
|
|
if (!sar.num)
|
|
|
|
sar.num = sar.den = 1;
|
|
|
|
|
2012-11-28 20:05:40 +03:00
|
|
|
for (plane = 0; plane < 4 && in->data[plane]; plane++) {
|
2011-08-10 19:58:49 +03:00
|
|
|
int hsub = plane == 1 || plane == 2 ? hsub0 : 0;
|
|
|
|
int vsub = plane == 1 || plane == 2 ? vsub0 : 0;
|
|
|
|
|
2012-11-28 20:05:40 +03:00
|
|
|
apply_delogo(out->data[plane], out->linesize[plane],
|
|
|
|
in ->data[plane], in ->linesize[plane],
|
2013-05-09 18:59:38 +03:00
|
|
|
FF_CEIL_RSHIFT(inlink->w, hsub),
|
|
|
|
FF_CEIL_RSHIFT(inlink->h, vsub),
|
2013-07-01 17:28:59 +03:00
|
|
|
sar, s->x>>hsub, s->y>>vsub,
|
2013-07-02 14:50:02 +03:00
|
|
|
/* Up and left borders were rounded down, inject lost bits
|
|
|
|
* into width and height to avoid error accumulation */
|
|
|
|
FF_CEIL_RSHIFT(s->w + (s->x & ((1<<hsub)-1)), hsub),
|
|
|
|
FF_CEIL_RSHIFT(s->h + (s->y & ((1<<vsub)-1)), vsub),
|
2013-03-18 22:44:36 +03:00
|
|
|
s->band>>FFMIN(hsub, vsub),
|
|
|
|
s->show, direct);
|
2011-08-10 19:58:49 +03:00
|
|
|
}
|
|
|
|
|
2012-11-28 20:05:40 +03:00
|
|
|
if (!direct)
|
2012-11-28 10:41:07 +03:00
|
|
|
av_frame_free(&in);
|
2012-11-28 20:05:40 +03:00
|
|
|
|
|
|
|
return ff_filter_frame(outlink, out);
|
2011-08-10 19:58:49 +03:00
|
|
|
}
|
|
|
|
|
2012-07-24 16:14:01 +03:00
|
|
|
static const AVFilterPad avfilter_vf_delogo_inputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
.get_video_buffer = ff_null_get_video_buffer,
|
2012-11-28 20:05:40 +03:00
|
|
|
.filter_frame = filter_frame,
|
2012-07-24 16:14:01 +03:00
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVFilterPad avfilter_vf_delogo_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2011-08-10 19:58:49 +03:00
|
|
|
AVFilter avfilter_vf_delogo = {
|
|
|
|
.name = "delogo",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Remove logo from input video."),
|
|
|
|
.priv_size = sizeof(DelogoContext),
|
2013-02-25 23:21:29 +03:00
|
|
|
.priv_class = &delogo_class,
|
2011-08-10 19:58:49 +03:00
|
|
|
.init = init,
|
|
|
|
.query_formats = query_formats,
|
|
|
|
|
2012-07-24 16:14:01 +03:00
|
|
|
.inputs = avfilter_vf_delogo_inputs,
|
|
|
|
.outputs = avfilter_vf_delogo_outputs,
|
2013-05-09 02:04:41 +03:00
|
|
|
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
|
2011-11-05 16:39:24 +03:00
|
|
|
};
|