55#define OFFSET(x) offsetof(BLKContext, x)
56#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
70 const int bufsize = inlink->
w * inlink->
h;
78 s->gradients =
av_calloc(bufsize,
sizeof(*
s->gradients));
87 float *
grad,
int grad_linesize,
88 uint8_t*
src,
int src_linesize)
91 float nonblock = 0.0f;
93 int nonblock_count = 0;
103 for (
int j = 1; j <
h; j++) {
104 for (
int i = 3;
i <
w - 4;
i++) {
106 grad[j * grad_linesize +
i] =
107 abs(
src[j * src_linesize +
i + 0] -
src[j * src_linesize +
i + 1]);
108 temp +=
abs(
src[j * src_linesize +
i + 1] -
src[j * src_linesize +
i + 2]);
109 temp +=
abs(
src[j * src_linesize +
i + 2] -
src[j * src_linesize +
i + 3]);
110 temp +=
abs(
src[j * src_linesize +
i + 3] -
src[j * src_linesize +
i + 4]);
111 temp +=
abs(
src[j * src_linesize +
i - 0] -
src[j * src_linesize +
i - 1]);
112 temp +=
abs(
src[j * src_linesize +
i - 1] -
src[j * src_linesize +
i - 2]);
113 temp +=
abs(
src[j * src_linesize +
i - 2] -
src[j * src_linesize +
i - 3]);
123 for (
int period =
s->period_min; period < s->period_max + 1; period++) {
129 for (
int i = 3;
i <
w - 4;
i++) {
130 if ((
i % period) == (period - 1)) {
138 if (block_count && nonblock_count) {
139 temp = (
block / block_count) / (nonblock / nonblock_count);
146 for (
int j = 3; j <
h - 4; j++) {
147 for (
int i = 1;
i <
w;
i++) {
149 grad[j * grad_linesize +
i] =
150 abs(
src[(j + 0) * src_linesize +
i] -
src[(j + 1) * src_linesize +
i]);
151 temp +=
abs(
src[(j + 1) * src_linesize +
i] -
src[(j + 2) * src_linesize +
i]);
152 temp +=
abs(
src[(j + 2) * src_linesize +
i] -
src[(j + 3) * src_linesize +
i]);
153 temp +=
abs(
src[(j + 3) * src_linesize +
i] -
src[(j + 4) * src_linesize +
i]);
154 temp +=
abs(
src[(j - 0) * src_linesize +
i] -
src[(j - 1) * src_linesize +
i]);
155 temp +=
abs(
src[(j - 1) * src_linesize +
i] -
src[(j - 2) * src_linesize +
i]);
156 temp +=
abs(
src[(j - 2) * src_linesize +
i] -
src[(j - 3) * src_linesize +
i]);
161 grad[j * grad_linesize] +=
grad[j * grad_linesize +
i];
166 for (
int period =
s->period_min; period < s->period_max + 1; period++) {
172 for (
int j = 3; j <
h - 4; j++) {
173 if ((j % period) == (period - 1)) {
175 grad[(j + 1) * grad_linesize]),
176 grad[(j - 1) * grad_linesize]);
179 nonblock +=
grad[j * grad_linesize];
183 if (block_count && nonblock_count) {
184 temp = (
block / block_count) / (nonblock / nonblock_count);
207 const int inw = inlink->
w;
208 const int inh = inlink->
h;
210 float *gradients =
s->gradients;
217 for (
int plane = 0; plane <
s->nb_planes; plane++) {
218 int hsub = plane == 1 || plane == 2 ?
s->hsub : 0;
219 int vsub = plane == 1 || plane == 2 ?
s->vsub : 0;
223 if (!((1 << plane) &
s->planes))
250 if (
s->nb_frames > 0) {
252 s->block_total /
s->nb_frames);
280 .p.name =
"blockdetect",
282 .p.priv_class = &blockdetect_class,
const FFFilter ff_vf_blockdetect
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define i(width, name, range_min, range_max)
#define AV_CEIL_RSHIFT(a, b)
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FILTER_PIXFMTS_ARRAY(array)
static FilterLink * ff_filter_link(AVFilterLink *link)
#define AVFILTER_DEFINE_CLASS(fname)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
static const struct @257111027162314367033347246032313251342043035002 planes[]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
static double grad(int hash, double x, double y, double z)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ 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_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Describe the class of an AVClass context structure.
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * dst
dest filter
int format
agreed upon media format
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVDictionary * metadata
metadata.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Link properties exposed to filter code, but not external callers.
int64_t frame_count_in
Number of past frames sent through the link.
static AVFormatContext * ctx
static float calculate_blockiness(BLKContext *s, int w, int h, float *grad, int grad_linesize, uint8_t *src, int src_linesize)
static av_cold void blockdetect_uninit(AVFilterContext *ctx)
static int blockdetect_config_input(AVFilterLink *inlink)
static void set_meta(AVDictionary **metadata, const char *key, float d)
static const AVFilterPad blockdetect_inputs[]
static int blockdetect_filter_frame(AVFilterLink *inlink, AVFrame *in)
static const AVOption blockdetect_options[]
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.