Go to the documentation of this file.
39 static int comp(
const float *
a,
const float *
b)
68 #define OFFSET(x) offsetof(BLRContext, x)
69 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
74 {
"block_pct",
"block pooling threshold when calculating blurriness",
OFFSET(block_pct),
AV_OPT_TYPE_INT, {.i64=80}, 1, 100,
FLAGS },
75 {
"block_width",
"block size for block-based abbreviation of blurriness",
OFFSET(block_width),
AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX,
FLAGS },
76 {
"block_height",
"block size for block-based abbreviation of blurriness",
OFFSET(block_height),
AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX,
FLAGS },
87 s->low_u8 =
s->low * 255. + .5;
88 s->high_u8 =
s->high * 255. + .5;
105 if (
s->block_width < 1 ||
s->block_height < 1) {
112 s->gradients =
av_calloc(bufsize,
sizeof(*
s->gradients));
117 if (!
s->tmpbuf || !
s->filterbuf || !
s->gradients || !
s->directions || !
s->blks)
125 int edge,
const uint8_t *
src,
int src_linesize)
141 default: dX = 1; dY = 1;
break;
145 sign =
src[j * src_linesize +
i] >
src[(j - dY) * src_linesize +
i - dX] ? 1 : -1;
148 for (k = 0; k < radius; k++) {
151 p1 = y * src_linesize + x;
154 p2 = y * src_linesize + x;
155 if (x < 0 || x >=
w || y < 0 || y >=
h)
166 for (k = 0; k < radius; k++) {
169 p1 = y * src_linesize + x;
172 p2 = y * src_linesize + x;
173 if (x < 0 || x >=
w || y < 0 || y >=
h)
191 int8_t* dir,
int dir_linesize,
192 uint8_t* dst,
int dst_linesize,
193 uint8_t*
src,
int src_linesize)
195 float total_width = 0.0;
197 double block_total_width;
202 float *blks =
s->blks;
203 float block_pool_threshold =
s->block_pct / 100.0;
207 int brows =
h / block_height;
208 int bcols =
w / block_width;
210 for (
int blkj = 0; blkj < brows; blkj++) {
211 for (
int blki = 0; blki < bcols; blki++) {
212 block_total_width = 0.0;
214 for (
int inj = 0; inj < block_height; inj++) {
215 for (
int ini = 0; ini < block_width; ini++) {
216 i = blki * block_width + ini;
217 j = blkj * block_height + inj;
219 if (dst[j * dst_linesize +
i] > 0) {
221 w,
h, dst[j*dst_linesize+
i],
225 block_total_width +=
width;
231 if (block_total_width >= 2 && block_count) {
232 blks[blkcnt] = block_total_width / block_count;
240 blkcnt =
ceil(blkcnt * block_pool_threshold);
241 for (
int i = 0;
i < blkcnt;
i++) {
242 total_width += blks[
i];
245 return total_width / blkcnt;
261 const int inw =
inlink->w;
262 const int inh =
inlink->h;
264 uint8_t *tmpbuf =
s->tmpbuf;
265 uint8_t *filterbuf =
s->filterbuf;
266 uint16_t *gradients =
s->gradients;
267 int8_t *directions =
s->directions;
274 for (
int plane = 0; plane <
s->nb_planes; plane++) {
275 int hsub = plane == 1 || plane == 2 ?
s->hsub : 0;
276 int vsub = plane == 1 || plane == 2 ?
s->vsub : 0;
280 if (!((1 << plane) &
s->planes))
286 ff_gaussian_blur_8(
w,
h,
291 ff_sobel_8(
w,
h, gradients,
w, directions,
w, filterbuf,
w, 1);
295 memset(tmpbuf, 0, inw * inh);
301 tmpbuf,
w, tmpbuf,
w);
304 tmpbuf,
w, filterbuf,
w);
310 s->blur_total +=
blur;
317 s->nb_frames =
inlink->frame_count_in;
326 if (
s->nb_frames > 0) {
328 s->blur_total /
s->nb_frames);
367 .
name =
"blurdetect",
375 .priv_class = &blurdetect_class,
AVPixelFormat
Pixel format.
static const struct @346 planes[]
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
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
This structure describes decoded (raw) audio or video data.
static float calculate_blur(BLRContext *s, int w, int h, int hsub, int vsub, int8_t *dir, int dir_linesize, uint8_t *dst, int dst_linesize, uint8_t *src, int src_linesize)
static av_cold int blurdetect_init(AVFilterContext *ctx)
#define AV_LOG_VERBOSE
Detailed information.
@ 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.
static enum AVPixelFormat pix_fmts[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
static void set_meta(AVDictionary **metadata, const char *key, float d)
A filter pad used for either input or output.
#define FFDIFFSIGN(x, y)
Comparator.
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
static __device__ float ceil(float a)
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_CEIL_RSHIFT(a, b)
int(* init)(AVBSFContext *ctx)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_INPUTS(array)
static int comp(const float *a, const float *b)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Describe the class of an AVClass context structure.
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
void ff_non_maximum_suppression(int w, int h, uint8_t *dst, int dst_linesize, const int8_t *dir, int dir_linesize, const uint16_t *src, int src_linesize)
Filters rounded gradients to drop all non-maxima pixels in the magnitude image Expects gradients gene...
static av_cold void blurdetect_uninit(AVFilterContext *ctx)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
static void blur(uint8_t *dst, int dst_step, const uint8_t *src, int src_step, int len, int radius, int pixsize)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void ff_double_threshold(int low, int high, int w, int h, uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize)
Filters all pixels in src to keep all pixels > high, and keep all pixels > low where all surrounding ...
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AV_LOG_INFO
Standard information.
#define i(width, name, range_min, range_max)
#define AV_QSORT(p, num, type, cmp)
Quicksort This sort is fast, and fully inplace but not stable and it is possible to construct input t...
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
@ 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 const AVOption blurdetect_options[]
void * av_calloc(size_t nmemb, size_t size)
static float edge_width(BLRContext *blr, int i, int j, int8_t dir, int w, int h, int edge, const uint8_t *src, int src_linesize)
static const AVFilterPad blurdetect_inputs[]
static int blurdetect_filter_frame(AVFilterLink *inlink, AVFrame *in)
AVFILTER_DEFINE_CLASS(blurdetect)
AVDictionary * metadata
metadata.
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
@ 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
@ 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...
static const AVFilterPad blurdetect_outputs[]
#define FILTER_OUTPUTS(array)
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
static int blurdetect_config_input(AVFilterLink *inlink)
const AVFilter ff_vf_blurdetect
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)
static av_cold int uninit(AVCodecContext *avctx)
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)