Go to the documentation of this file.
53 #define OFFSET(x) offsetof(BLKContext, x)
54 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
76 s->gradients =
av_calloc(bufsize,
sizeof(*
s->gradients));
85 float *grad,
int grad_linesize,
86 uint8_t*
src,
int src_linesize)
89 float nonblock = 0.0f;
91 int nonblock_count = 0;
101 for (
int j = 1; j <
h; j++) {
102 for (
int i = 3;
i <
w - 4;
i++) {
104 grad[j * grad_linesize +
i] =
105 abs(
src[j * src_linesize +
i + 0] -
src[j * src_linesize +
i + 1]);
106 temp +=
abs(
src[j * src_linesize +
i + 1] -
src[j * src_linesize +
i + 2]);
107 temp +=
abs(
src[j * src_linesize +
i + 2] -
src[j * src_linesize +
i + 3]);
108 temp +=
abs(
src[j * src_linesize +
i + 3] -
src[j * src_linesize +
i + 4]);
109 temp +=
abs(
src[j * src_linesize +
i - 0] -
src[j * src_linesize +
i - 1]);
110 temp +=
abs(
src[j * src_linesize +
i - 1] -
src[j * src_linesize +
i - 2]);
111 temp +=
abs(
src[j * src_linesize +
i - 2] -
src[j * src_linesize +
i - 3]);
113 grad[j * grad_linesize +
i] /=
temp;
116 grad[
i] += grad[j * grad_linesize +
i];
121 for (
int period =
s->period_min; period < s->period_max + 1;
period++) {
127 for (
int i = 3;
i <
w - 4;
i++) {
136 if (block_count && nonblock_count) {
137 temp = (
block / block_count) / (nonblock / nonblock_count);
144 for (
int j = 3; j <
h - 4; j++) {
145 for (
int i = 1;
i <
w;
i++) {
147 grad[j * grad_linesize +
i] =
148 abs(
src[(j + 0) * src_linesize +
i] -
src[(j + 1) * src_linesize +
i]);
149 temp +=
abs(
src[(j + 1) * src_linesize +
i] -
src[(j + 2) * src_linesize +
i]);
150 temp +=
abs(
src[(j + 2) * src_linesize +
i] -
src[(j + 3) * src_linesize +
i]);
151 temp +=
abs(
src[(j + 3) * src_linesize +
i] -
src[(j + 4) * src_linesize +
i]);
152 temp +=
abs(
src[(j - 0) * src_linesize +
i] -
src[(j - 1) * src_linesize +
i]);
153 temp +=
abs(
src[(j - 1) * src_linesize +
i] -
src[(j - 2) * src_linesize +
i]);
154 temp +=
abs(
src[(j - 2) * src_linesize +
i] -
src[(j - 3) * src_linesize +
i]);
156 grad[j * grad_linesize +
i] /=
temp;
159 grad[j * grad_linesize] += grad[j * grad_linesize +
i];
164 for (
int period =
s->period_min; period < s->period_max + 1;
period++) {
170 for (
int j = 3; j <
h - 4; j++) {
173 grad[(j + 1) * grad_linesize]),
174 grad[(j - 1) * grad_linesize]);
177 nonblock += grad[j * grad_linesize];
181 if (block_count && nonblock_count) {
182 temp = (
block / block_count) / (nonblock / nonblock_count);
204 const int inw =
inlink->w;
205 const int inh =
inlink->h;
207 float *gradients =
s->gradients;
214 for (
int plane = 0; plane <
s->nb_planes; plane++) {
215 int hsub = plane == 1 || plane == 2 ?
s->hsub : 0;
216 int vsub = plane == 1 || plane == 2 ?
s->vsub : 0;
220 if (!((1 << plane) &
s->planes))
238 s->nb_frames =
inlink->frame_count_in;
247 if (
s->nb_frames > 0) {
249 s->block_total /
s->nb_frames);
277 .
name =
"blockdetect",
284 .priv_class = &blockdetect_class,
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
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 enum AVPixelFormat pix_fmts[]
#define AV_LOG_VERBOSE
Detailed information.
static const AVFilterPad blockdetect_inputs[]
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
static av_cold void blockdetect_uninit(AVFilterContext *ctx)
A link between two filters.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const AVFilter ff_vf_blockdetect
@ 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.
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
@ 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)
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)
@ 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.
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 minimum maximum flags name is the option keep it simple and lowercase description are in without period
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
static float calculate_blockiness(BLKContext *s, int w, int h, float *grad, int grad_linesize, uint8_t *src, int src_linesize)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
@ 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)
static const struct @363 planes[]
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
static int blockdetect_filter_frame(AVFilterLink *inlink, AVFrame *in)
const char * name
Pad name.
void * av_calloc(size_t nmemb, size_t size)
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
static const AVOption blockdetect_options[]
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
AVFILTER_DEFINE_CLASS(blockdetect)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#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)
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)
The exact code depends on how similar the blocks are and how related they are to the block
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)
static int blockdetect_config_input(AVFilterLink *inlink)