Go to the documentation of this file.
36 #define RADIUS_MIN 0.1
37 #define RADIUS_MAX 5.0
39 #define STRENGTH_MIN -1.0
40 #define STRENGTH_MAX 1.0
42 #define THRESHOLD_MIN -30
43 #define THRESHOLD_MAX 30
62 #define OFFSET(x) offsetof(SmartblurContext, x)
63 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
91 s->chroma.radius =
s->luma.radius;
93 s->chroma.strength =
s->luma.strength;
95 s->chroma.threshold =
s->luma.threshold;
97 s->luma.quality =
s->chroma.quality = 3.0;
101 "luma_radius:%f luma_strength:%f luma_threshold:%d "
102 "chroma_radius:%f chroma_strength:%f chroma_threshold:%d\n",
103 s->luma.radius,
s->luma.strength,
s->luma.threshold,
104 s->chroma.radius,
s->chroma.strength,
s->chroma.threshold);
137 sws_filter.
lumH = sws_filter.
lumV = vec;
146 if (!
f->filter_context)
157 s->hsub =
desc->log2_chroma_w;
158 s->vsub =
desc->log2_chroma_h;
169 static void blur(uint8_t *dst,
const int dst_linesize,
170 const uint8_t *
src,
const int src_linesize,
171 const int w,
const int h,
const int threshold,
178 const uint8_t*
const src_array[4] = {
src};
179 uint8_t *dst_array[4] = {dst};
180 int src_linesize_array[4] = {src_linesize};
181 int dst_linesize_array[4] = {dst_linesize};
183 sws_scale(filter_context, src_array, src_linesize_array,
184 0,
h, dst_array, dst_linesize_array);
187 for (y = 0; y <
h; ++y) {
188 for (x = 0; x <
w; ++x) {
189 orig =
src[x + y * src_linesize];
190 filtered = dst[x + y * dst_linesize];
191 diff = orig - filtered;
194 if (
diff > 2 * threshold)
195 dst[x + y * dst_linesize] = orig;
196 else if (
diff > threshold)
198 dst[x + y * dst_linesize] = orig - threshold;
200 if (-
diff > 2 * threshold)
201 dst[x + y * dst_linesize] = orig;
202 else if (-
diff > threshold)
204 dst[x + y * dst_linesize] = orig + threshold;
208 }
else if (threshold < 0) {
209 for (y = 0; y <
h; ++y) {
210 for (x = 0; x <
w; ++x) {
211 orig =
src[x + y * src_linesize];
212 filtered = dst[x + y * dst_linesize];
213 diff = orig - filtered;
216 if (
diff <= -threshold)
217 dst[x + y * dst_linesize] = orig;
218 else if (
diff <= -2 * threshold)
220 dst[x + y * dst_linesize] = filtered - threshold;
222 if (
diff >= threshold)
223 dst[x + y * dst_linesize] = orig;
224 else if (
diff >= 2 * threshold)
226 dst[x + y * dst_linesize] = filtered + threshold;
251 s->luma.filter_context);
253 if (
inpic->data[2]) {
256 cw, ch,
s->chroma.threshold,
257 s->chroma.filter_context);
260 cw, ch,
s->chroma.threshold,
261 s->chroma.filter_context);
293 .priv_class = &smartblur_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
struct SwsContext * sws_getCachedContext(struct SwsContext *context, int srcW, int srcH, enum AVPixelFormat srcFormat, int dstW, int dstH, enum AVPixelFormat dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, const double *param)
Check if context can be reused, otherwise reallocate a new one.
const AVFilter ff_vf_smartblur
AVPixelFormat
Pixel format.
static int config_props(AVFilterLink *inlink)
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
AVFILTER_DEFINE_CLASS(smartblur)
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)
#define FILTER_PIXFMTS_ARRAY(array)
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
static int alloc_sws_context(FilterParam *f, int width, int height, unsigned int flags)
static const AVOption smartblur_options[]
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
static enum AVPixelFormat pix_fmts[]
#define AV_LOG_VERBOSE
Detailed information.
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
int attribute_align_arg sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], const int srcStride[], int srcSliceY, int srcSliceH, uint8_t *const dst[], const int dstStride[])
swscale wrapper, so we don't need to export the SwsContext.
const char * name
Filter name.
A link between two filters.
void sws_freeVec(SwsVector *a)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static void blur(uint8_t *dst, const int dst_linesize, const uint8_t *src, const int src_linesize, const int w, const int h, const int threshold, struct SwsContext *filter_context)
static av_cold int init(AVFilterContext *ctx)
A filter pad used for either input or output.
#define AV_CEIL_RSHIFT(a, b)
int length
number of coefficients in the vector
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
SwsVector * sws_getGaussianVec(double variance, double quality)
Return a normalized Gaussian curve used to filter stuff quality = 3 is high quality,...
#define FILTER_INPUTS(array)
Describe the class of an AVClass context structure.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static int filter_frame(AVFilterLink *inlink, AVFrame *inpic)
double * coeff
pointer to the list of coefficients
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
void sws_scaleVec(SwsVector *a, double scalar)
Scale all the coefficients of a by the scalar value.
static const AVFilterPad smartblur_inputs[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold void uninit(AVFilterContext *ctx)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
int w
agreed upon image width
const char * name
Pad name.
static const AVFilterPad smartblur_outputs[]
void sws_freeContext(struct SwsContext *swsContext)
Free the swscaler context swsContext.
int h
agreed upon image height
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
struct SwsContext * filter_context
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static av_always_inline int diff(const uint32_t a, const uint32_t b)
#define FILTER_OUTPUTS(array)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#define flags(name, subs,...)
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)