vf_boxblur.c File Reference

Apply a boxblur filter to the input video. More...

#include "libavutil/avstring.h"
#include "libavutil/common.h"
#include "libavutil/eval.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "formats.h"
#include "internal.h"
#include "video.h"
Include dependency graph for vf_boxblur.c:

Go to the source code of this file.

Data Structures

struct  FilterParam
 
struct  BoxBlurContext
 

Macros

#define Y   0
 
#define U   1
 
#define V   2
 
#define A   3
 
#define EVAL_RADIUS_EXPR(comp)
 
#define CHECK_RADIUS_VAL(w_, h_, comp)
 
#define OFFSET(x)   offsetof(BoxBlurContext, x)
 
#define FLAGS   AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 

Enumerations

enum  var_name {
  VAR_B1, VAR_B2, VAR_S1, VAR_S2,
  VAR_T1, VAR_T2, VAR_NB, VAR_N,
  VAR_T, VAR_S, VAR_VARS_NB, VAR_TB,
  VAR_PTS, VAR_START_PTS, VAR_PREV_PTS, VAR_PREV_SELECTED_PTS,
  VAR_T, VAR_START_T, VAR_PREV_T, VAR_PREV_SELECTED_T,
  VAR_PICT_TYPE, VAR_PICT_TYPE_I, VAR_PICT_TYPE_P, VAR_PICT_TYPE_B,
  VAR_PICT_TYPE_S, VAR_PICT_TYPE_SI, VAR_PICT_TYPE_SP, VAR_PICT_TYPE_BI,
  VAR_INTERLACE_TYPE, VAR_INTERLACE_TYPE_P, VAR_INTERLACE_TYPE_T, VAR_INTERLACE_TYPE_B,
  VAR_CONSUMED_SAMPLES_N, VAR_SAMPLES_N, VAR_SAMPLE_RATE, VAR_N,
  VAR_SELECTED_N, VAR_PREV_SELECTED_N, VAR_KEY, VAR_POS,
  VAR_SCENE, VAR_VARS_NB, VAR_FRAME_RATE, VAR_INTERLACED,
  VAR_N, VAR_NB_CONSUMED_SAMPLES, VAR_NB_SAMPLES, VAR_POS,
  VAR_PREV_INPTS, VAR_PREV_INT, VAR_PREV_OUTPTS, VAR_PREV_OUTT,
  VAR_PTS, VAR_SAMPLE_RATE, VAR_STARTPTS, VAR_STARTT,
  VAR_T, VAR_TB, VAR_RTCTIME, VAR_RTCSTART,
  VAR_VARS_NB, VAR_AVTB, VAR_INTB, VAR_SR,
  VAR_VARS_NB, VAR_W, VAR_H, VAR_CW,
  VAR_CH, VAR_HSUB, VAR_VSUB, VARS_NB,
  VAR_IN_W, VAR_IW, VAR_IN_H, VAR_IH,
  VAR_OUT_W, VAR_OW, VAR_OUT_H, VAR_OH,
  VAR_A, VAR_SAR, VAR_DAR, VAR_HSUB,
  VAR_VSUB, VAR_X, VAR_Y, VAR_N,
  VAR_POS, VAR_T, VAR_VARS_NB, VAR_DAR,
  VAR_HSUB, VAR_VSUB, VAR_LINE_H, VAR_LH,
  VAR_MAIN_H, VAR_h, VAR_H, VAR_MAIN_W,
  VAR_w, VAR_W, VAR_MAX_GLYPH_A, VAR_ASCENT,
  VAR_MAX_GLYPH_D, VAR_DESCENT, VAR_MAX_GLYPH_H, VAR_MAX_GLYPH_W,
  VAR_N, VAR_SAR, VAR_T, VAR_TEXT_H,
  VAR_TH, VAR_TEXT_W, VAR_TW, VAR_X,
  VAR_Y, VAR_VARS_NB, VAR_N, VAR_PTS,
  VAR_R, VAR_T, VAR_TB, VAR_NB,
  VAR_W, VAR_H, VAR_VAL, VAR_MAXVAL,
  VAR_MINVAL, VAR_NEGVAL, VAR_CLIPVAL, VAR_VARS_NB,
  VAR_MAIN_W, VAR_MW, VAR_MAIN_H, VAR_MH,
  VAR_OVERLAY_W, VAR_OW, VAR_OVERLAY_H, VAR_OH,
  VAR_HSUB, VAR_VSUB, VAR_X, VAR_Y,
  VAR_N, VAR_POS, VAR_T, VAR_VARS_NB,
  VAR_IN_W, VAR_IW, VAR_IN_H, VAR_IH,
  VAR_OUT_W, VAR_OW, VAR_OUT_H, VAR_OH,
  VAR_X, VAR_Y, VAR_A, VAR_SAR,
  VAR_DAR, VAR_HSUB, VAR_VSUB, VARS_NB,
  VAR_IN_W, VAR_IW, VAR_IN_H, VAR_IH,
  VAR_OUT_W, VAR_OW, VAR_OUT_H, VAR_OH,
  VAR_A, VAR_SAR, VAR_DAR, VAR_HSUB,
  VAR_VSUB, VARS_NB, VAR_X, VAR_Y,
  VAR_W, VAR_H, VAR_TIME, VAR_SPEED,
  VAR_TEMPO, VAR_ORDER, VAR_PATTERN, VAR_ROW,
  VAR_VARS_NB
}
 

Functions

static av_cold int init (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static int query_formats (AVFilterContext *ctx)
 
static int config_input (AVFilterLink *inlink)
 
static void blur (uint8_t *dst, int dst_step, const uint8_t *src, int src_step, int len, int radius)
 
static void blur_power (uint8_t *dst, int dst_step, const uint8_t *src, int src_step, int len, int radius, int power, uint8_t *temp[2])
 
static void hblur (uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int w, int h, int radius, int power, uint8_t *temp[2])
 
static void vblur (uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int w, int h, int radius, int power, uint8_t *temp[2])
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 
 AVFILTER_DEFINE_CLASS (boxblur)
 

Variables

static const char *const var_names []
 
static const AVOption boxblur_options []
 
static const AVFilterPad avfilter_vf_boxblur_inputs []
 
static const AVFilterPad avfilter_vf_boxblur_outputs []
 
AVFilter avfilter_vf_boxblur
 

Detailed Description

Apply a boxblur filter to the input video.

Ported from MPlayer libmpcodecs/vf_boxblur.c.

Definition in file vf_boxblur.c.

Macro Definition Documentation

#define A   3

Definition at line 79 of file vf_boxblur.c.

Referenced by config_input().

#define CHECK_RADIUS_VAL (   w_,
  h_,
  comp 
)
Value:
if (boxblur->comp##_param.radius < 0 || \
2*boxblur->comp##_param.radius > FFMIN(w_, h_)) { \
"Invalid " #comp " radius value %d, must be >= 0 and <= %d\n", \
boxblur->comp##_param.radius, FFMIN(w_, h_)/2); \
return AVERROR(EINVAL); \
}
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
#define FFMIN(a, b)
Definition: common.h:58
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame This method is called when a frame is wanted on an output For an it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return it should return
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
Definition: eamad.c:71

Referenced by config_input().

#define EVAL_RADIUS_EXPR (   comp)
Value:
expr = boxblur->comp##_param.radius_expr; \
ret = av_expr_parse_and_eval(&res, expr, var_names, var_values, \
NULL, NULL, NULL, NULL, NULL, 0, ctx); \
boxblur->comp##_param.radius = res; \
if (ret < 0) { \
"Error when evaluating " #comp " radius expression '%s'\n", expr); \
}
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
Definition: eval.c:701
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
ret
Definition: avfilter.c:821
static const char *const var_names[]
Definition: vf_boxblur.c:38
NULL
Definition: eval.c:55
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame This method is called when a frame is wanted on an output For an it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return it should return
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
Definition: eamad.c:71

Referenced by config_input().

Definition at line 334 of file vf_boxblur.c.

#define OFFSET (   x)    offsetof(BoxBlurContext, x)

Definition at line 333 of file vf_boxblur.c.

#define U   1

Definition at line 77 of file vf_boxblur.c.

Referenced by config_input().

#define V   2

Definition at line 78 of file vf_boxblur.c.

Referenced by config_input().

Enumeration Type Documentation

enum var_name
Enumerator
VAR_B1 
VAR_B2 
VAR_S1 
VAR_S2 
VAR_T1 
VAR_T2 
VAR_NB 
VAR_N 
VAR_T 
VAR_S 
VAR_VARS_NB 
VAR_TB 
VAR_PTS 
VAR_START_PTS 
VAR_PREV_PTS 
VAR_PREV_SELECTED_PTS 
VAR_T 
VAR_START_T 
VAR_PREV_T 
VAR_PREV_SELECTED_T 
VAR_PICT_TYPE 
VAR_PICT_TYPE_I 
VAR_PICT_TYPE_P 
VAR_PICT_TYPE_B 
VAR_PICT_TYPE_S 
VAR_PICT_TYPE_SI 
VAR_PICT_TYPE_SP 
VAR_PICT_TYPE_BI 
VAR_INTERLACE_TYPE 
VAR_INTERLACE_TYPE_P 
VAR_INTERLACE_TYPE_T 
VAR_INTERLACE_TYPE_B 
VAR_CONSUMED_SAMPLES_N 
VAR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_MW 
VAR_MAIN_H 
VAR_MH 
VAR_OVERLAY_W 
VAR_OW 
VAR_OVERLAY_H 
VAR_OH 
VAR_HSUB 
VAR_VSUB 
VAR_X 
VAR_Y 
VAR_N 
VAR_POS 
VAR_T 
VAR_VARS_NB 
VAR_IN_W 
VAR_IW 
VAR_IN_H 
VAR_IH 
VAR_OUT_W 
VAR_OW 
VAR_OUT_H 
VAR_OH 
VAR_X 
VAR_Y 
VAR_A 
VAR_SAR 
VAR_DAR 
VAR_HSUB 
VAR_VSUB 
VARS_NB 
VAR_IN_W 
VAR_IW 
VAR_IN_H 
VAR_IH 
VAR_OUT_W 
VAR_OW 
VAR_OUT_H 
VAR_OH 
VAR_A 
VAR_SAR 
VAR_DAR 
VAR_HSUB 
VAR_VSUB 
VARS_NB 
VAR_X 
VAR_Y 
VAR_W 
VAR_H 
VAR_TIME 
VAR_SPEED 
VAR_TEMPO 
VAR_ORDER 
VAR_PATTERN 
VAR_ROW 
VAR_VARS_NB 

Definition at line 48 of file vf_boxblur.c.

Function Documentation

AVFILTER_DEFINE_CLASS ( boxblur  )
static void blur ( uint8_t dst,
int  dst_step,
const uint8_t src,
int  src_step,
int  len,
int  radius 
)
inlinestatic

Definition at line 205 of file vf_boxblur.c.

Referenced by blur_power().

static void blur_power ( uint8_t dst,
int  dst_step,
const uint8_t src,
int  src_step,
int  len,
int  radius,
int  power,
uint8_t temp[2] 
)
inlinestatic

Definition at line 246 of file vf_boxblur.c.

Referenced by hblur(), and vblur().

static int config_input ( AVFilterLink inlink)
static

Definition at line 133 of file vf_boxblur.c.

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 298 of file vf_boxblur.c.

static void hblur ( uint8_t dst,
int  dst_linesize,
const uint8_t src,
int  src_linesize,
int  w,
int  h,
int  radius,
int  power,
uint8_t temp[2] 
)
static

Definition at line 272 of file vf_boxblur.c.

Referenced by filter_frame().

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 81 of file vf_boxblur.c.

static int query_formats ( AVFilterContext ctx)
static

Definition at line 118 of file vf_boxblur.c.

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 110 of file vf_boxblur.c.

static void vblur ( uint8_t dst,
int  dst_linesize,
const uint8_t src,
int  src_linesize,
int  w,
int  h,
int  radius,
int  power,
uint8_t temp[2] 
)
static

Definition at line 285 of file vf_boxblur.c.

Referenced by filter_frame().

Variable Documentation

AVFilter avfilter_vf_boxblur
Initial value:
= {
.name = "boxblur",
.description = NULL_IF_CONFIG_SMALL("Blur the input."),
.priv_size = sizeof(BoxBlurContext),
.priv_class = &boxblur_class,
.init = init,
}
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
static av_cold int init(AVFilterContext *ctx)
Definition: vf_boxblur.c:81
static const AVFilterPad avfilter_vf_boxblur_outputs[]
Definition: vf_boxblur.c:367
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int query_formats(AVFilterContext *ctx)
Definition: vf_boxblur.c:118
static const AVFilterPad avfilter_vf_boxblur_inputs[]
Definition: vf_boxblur.c:357
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_boxblur.c:110
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs

Definition at line 375 of file vf_boxblur.c.

const AVFilterPad avfilter_vf_boxblur_inputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_input,
.filter_frame = filter_frame,
},
{ NULL }
}
static int config_input(AVFilterLink *inlink)
Definition: vf_boxblur.c:133
NULL
Definition: eval.c:55
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_boxblur.c:298

Definition at line 357 of file vf_boxblur.c.

const AVFilterPad avfilter_vf_boxblur_outputs[]
static
Initial value:
= {
{
.name = "default",
},
{ NULL }
}
NULL
Definition: eval.c:55

Definition at line 367 of file vf_boxblur.c.

const AVOption boxblur_options[]
static
Initial value:
= {
{ "luma_radius", "Radius of the luma blurring box", OFFSET(luma_param.radius_expr), AV_OPT_TYPE_STRING, {.str="2"}, .flags = FLAGS },
{ "lr", "Radius of the luma blurring box", OFFSET(luma_param.radius_expr), AV_OPT_TYPE_STRING, {.str="2"}, .flags = FLAGS },
{ "luma_power", "How many times should the boxblur be applied to luma", OFFSET(luma_param.power), AV_OPT_TYPE_INT, {.i64=2}, 0, INT_MAX, .flags = FLAGS },
{ "lp", "How many times should the boxblur be applied to luma", OFFSET(luma_param.power), AV_OPT_TYPE_INT, {.i64=2}, 0, INT_MAX, .flags = FLAGS },
{ "chroma_radius", "Radius of the chroma blurring box", OFFSET(chroma_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
{ "cr", "Radius of the chroma blurring box", OFFSET(chroma_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
{ "chroma_power", "How many times should the boxblur be applied to chroma", OFFSET(chroma_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
{ "cp", "How many times should the boxblur be applied to chroma", OFFSET(chroma_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
{ "alpha_radius", "Radius of the alpha blurring box", OFFSET(alpha_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
{ "ar", "Radius of the alpha blurring box", OFFSET(alpha_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
{ "alpha_power", "How many times should the boxblur be applied to alpha", OFFSET(alpha_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
{ "ap", "How many times should the boxblur be applied to alpha", OFFSET(alpha_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
{ NULL }
}
#define OFFSET(x)
Definition: vf_boxblur.c:333
#define FLAGS
Definition: vf_boxblur.c:334
NULL
Definition: eval.c:55

Definition at line 336 of file vf_boxblur.c.

const char* const var_names[]
static
Initial value:
= {
"w",
"h",
"cw",
"ch",
"hsub",
"vsub",
}
NULL
Definition: eval.c:55

Definition at line 38 of file vf_boxblur.c.