Go to the documentation of this file.
62 #define OFFSET(x) offsetof(VarBlurContext, x)
63 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
96 #define COMPUTE_SAT(type, stype, depth) \
97 static void compute_sat##depth(const uint8_t *ssrc, \
100 const uint8_t *dstp, \
103 const type *src = (const type *)ssrc; \
104 stype *dst = (stype *)dstp; \
106 linesize /= (depth / 8); \
107 dst_linesize /= (depth / 2); \
108 dst += dst_linesize; \
110 for (int y = 0; y < h; y++) { \
113 for (int x = 1; x < w; x++) { \
115 dst[x] = sum + dst[x - dst_linesize]; \
119 dst += dst_linesize; \
132 return v0 + (v1 -
v0) *
f;
135 #define BLUR_PLANE(type, stype, bits) \
136 static int blur_plane##bits(AVFilterContext *ctx, \
139 const uint8_t *rrptr, \
140 int rrptr_linesize, \
142 const uint8_t *pptr, \
144 int slice_start, int slice_end) \
146 VarBlurContext *s = ctx->priv; \
147 const int ddepth = s->depth; \
148 const int dst_linesize = ddst_linesize / (bits / 8); \
149 const int ptr_linesize = pptr_linesize / (bits / 2); \
150 const int rptr_linesize = rrptr_linesize / (bits / 8); \
151 const type *rptr = (const type *)rrptr + slice_start * rptr_linesize; \
152 type *dst = (type *)ddst + slice_start * dst_linesize; \
153 const stype *ptr = (stype *)pptr; \
154 const float minr = 2.f * s->min_radius + 1.f; \
155 const float maxr = 2.f * s->max_radius + 1.f; \
156 const float scaler = (maxr - minr) / ((1 << ddepth) - 1); \
158 for (int y = slice_start; y < slice_end; y++) { \
159 for (int x = 0; x < w; x++) { \
160 const float radiusf = minr + (FFMAX(0.f, 2 * rptr[x] + 1 - minr)) * scaler; \
161 const int radius = floorf(radiusf); \
162 const float factor = radiusf - radius; \
163 const int nradius = radius + 1; \
164 const int l = FFMIN(radius, x); \
165 const int r = FFMIN(radius, w - x - 1); \
166 const int t = FFMIN(radius, y); \
167 const int b = FFMIN(radius, h - y - 1); \
168 const int nl = FFMIN(nradius, x); \
169 const int nr = FFMIN(nradius, w - x - 1); \
170 const int nt = FFMIN(nradius, y); \
171 const int nb = FFMIN(nradius, h - y - 1); \
172 stype tl = ptr[(y - t) * ptr_linesize + x - l]; \
173 stype tr = ptr[(y - t) * ptr_linesize + x + r]; \
174 stype bl = ptr[(y + b) * ptr_linesize + x - l]; \
175 stype br = ptr[(y + b) * ptr_linesize + x + r]; \
176 stype ntl = ptr[(y - nt) * ptr_linesize + x - nl]; \
177 stype ntr = ptr[(y - nt) * ptr_linesize + x + nr]; \
178 stype nbl = ptr[(y + nb) * ptr_linesize + x - nl]; \
179 stype nbr = ptr[(y + nb) * ptr_linesize + x + nr]; \
180 stype div = (l + r) * (t + b); \
181 stype ndiv = (nl + nr) * (nt + nb); \
182 stype p0 = (br + tl - bl - tr) / div; \
183 stype n0 = (nbr + ntl - nbl - ntr) / ndiv; \
185 dst[x] = av_clip_uintp2_c(lrintf( \
186 lerpf(p0, n0, factor)), \
190 rptr += rptr_linesize; \
191 dst += dst_linesize; \
201 int jobnr,
int nb_jobs)
209 for (
int plane = 0; plane <
s->nb_planes; plane++) {
210 const int height =
s->planeheight[plane];
211 const int slice_start = (
height * jobnr) / nb_jobs;
213 const int width =
s->planewidth[plane];
214 const int linesize = in->
linesize[plane];
215 const int dst_linesize =
out->linesize[plane];
216 const uint8_t *rptr = radius->
data[plane];
217 const int rptr_linesize = radius->
linesize[plane];
218 uint8_t *ptr =
s->sat->data[plane];
219 const int ptr_linesize =
s->sat->linesize[plane];
220 const uint8_t *
src = in->
data[plane];
221 uint8_t *dst =
out->data[plane];
223 if (!(
s->planes & (1 << plane))) {
227 src + slice_start * linesize,
229 width * ((
s->depth + 7) / 8),
234 s->blur_plane(
ctx, dst, dst_linesize,
262 for (
int plane = 0; plane <
s->nb_planes; plane++) {
263 const int height =
s->planeheight[plane];
264 const int width =
s->planewidth[plane];
265 const int linesize = in->
linesize[plane];
266 uint8_t *ptr =
s->sat->data[plane];
267 const int ptr_linesize =
s->sat->linesize[plane];
268 const uint8_t *
src = in->
data[plane];
270 if (!(
s->planes & (1 << plane)))
300 if (
s->max_radius <=
s->min_radius)
301 s->max_radius =
s->min_radius + 1;
322 "(size %dx%d) do not match the corresponding "
323 "second input link %s parameters (size %dx%d)\n",
325 ctx->input_pads[1].name, radiuslink->
w, radiuslink->
h);
335 s->depth =
desc->comp[0].depth;
336 s->blur_plane =
s->depth <= 8 ? blur_plane8 : blur_plane16;
337 s->compute_sat =
s->depth <= 8 ? compute_sat8 : compute_sat16;
340 s->planewidth[0] =
s->planewidth[3] = outlink->
w;
342 s->planeheight[0] =
s->planeheight[3] = outlink->
h;
391 .priv_class = &varblur_class,
393 .
preinit = varblur_framesync_preinit,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_GBRAP16
static int blur_planes(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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. Frame references ownership and permissions
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
void(* compute_sat)(const uint8_t *ssrc, int linesize, int w, int h, const uint8_t *dstp, int dst_linesize)
#define FILTER_PIXFMTS_ARRAY(array)
static int config_output(AVFilterLink *outlink)
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_PIX_FMT_YUVA422P9
This structure describes decoded (raw) audio or video data.
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUV420P10
static av_cold int preinit(AVFilterContext *ctx)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
A link between two filters.
#define AV_PIX_FMT_YUVA422P10
#define BLUR_PLANE(type, stype, bits)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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.
static const AVFilterPad varblur_inputs[]
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_GBRP14
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUV422P9
static float lerpf(float v0, float v1, float f)
#define AV_PIX_FMT_GRAY16
A filter pad used for either input or output.
static int varblur_frame(FFFrameSync *fs)
#define AV_PIX_FMT_YUV444P10
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_PIX_FMT_YUV422P16
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP12
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_PIX_FMT_YUV444P16
#define AV_CEIL_RSHIFT(a, b)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV420P9
const AVFilter ff_vf_varblur
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_GRAY14
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_INPUTS(array)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
static const struct @321 planes[]
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GBRP16
Describe the class of an AVClass context structure.
#define COMPUTE_SAT(type, stype, depth)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define fs(width, name, subs,...)
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static av_cold void uninit(AVFilterContext *ctx)
static const AVOption varblur_options[]
#define AV_PIX_FMT_YUV422P10
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
int format
agreed upon media format
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV444P12
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
AVFilterContext * src
source filter
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AV_PIX_FMT_YUVA444P10
static int blur_frame(AVFilterContext *ctx, AVFrame *in, AVFrame *radius)
FRAMESYNC_DEFINE_CLASS(varblur, VarBlurContext, fs)
int w
agreed upon image width
#define AV_PIX_FMT_GBRP12
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Used for passing data between threads.
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
const char * name
Pad name.
static int activate(AVFilterContext *ctx)
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUVA444P9
int(* blur_plane)(AVFilterContext *ctx, uint8_t *ddst, int ddst_linesize, const uint8_t *rrptr, int rrptr_linesize, int w, int h, const uint8_t *pptr, int pptr_linesize, int slice_start, int slice_end)
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P14
int h
agreed upon image height
#define AV_PIX_FMT_YUVA422P12
static const AVFilterPad varblur_outputs[]
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define FILTER_OUTPUTS(array)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
#define AV_PIX_FMT_YUV440P12
static enum AVPixelFormat pix_fmts[]
#define AV_PIX_FMT_YUV444P14
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
#define AV_PIX_FMT_GRAY12
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
#define AV_PIX_FMT_YUV420P14