88 if (
s->print_summary) {
89 float avg_si =
s->sum_si /
s->nb_frames;
90 float avg_ti =
s->sum_ti /
s->nb_frames;
92 "SITI Summary:\nTotal frames: %"PRId64
"\n\n"
93 "Spatial Information:\nAverage: %f\nMax: %f\nMin: %f\n\n"
94 "Temporal Information:\nAverage: %f\nMax: %f\nMin: %f\n",
95 s->nb_frames, avg_si,
s->max_si,
s->min_si, avg_ti,
s->max_ti,
s->min_ti
123 s->pixel_depth = max_pixsteps[0];
124 s->width = inlink->
w;
125 s->height = inlink->
h;
126 pixel_sz =
s->pixel_depth == 1 ?
sizeof(uint8_t) :
sizeof(uint16_t);
127 data_sz =
s->width * pixel_sz *
s->height;
131 gradient_sz = (
s->width - 2) *
sizeof(
float) * (
s->height - 2);
134 motion_sz =
s->width *
sizeof(
float) *
s->height;
137 if (!
s->prev_frame || !
s->gradient_matrix || !
s->motion_matrix) {
164 full_upper = 256 *
factor - 1;
166 return (full_upper * limit_y / limit_upper);
179 int filter_width = 3;
180 int filter_size = filter_width * filter_width;
181 int stride = linesize /
s->pixel_depth;
183 int factor =
s->pixel_depth == 1 ? 1 : 4;
186 #define CONVOLVE(bps) \
188 uint##bps##_t *vsrc = (uint##bps##_t*)src; \
189 for (int j = 1; j < s->height - 1; j++) { \
190 for (int i = 1; i < s->width - 1; i++) { \
193 for (int k = 0; k < filter_size; k++) { \
194 ki = k % filter_width - 1; \
195 kj = floor(k / filter_width) - 1; \
196 index = (j + kj) * stride + (i + ki); \
197 data = s->full_range ? vsrc[index] : convert_full_range(factor, vsrc[index]); \
198 x_conv_sum += data * X_FILTER[k]; \
199 y_conv_sum += data * Y_FILTER[k]; \
201 gradient = sqrt(x_conv_sum * x_conv_sum + y_conv_sum * y_conv_sum); \
202 dst[(j - 1) * (s->width - 2) + (i - 1)] = gradient; \
207 if (
s->pixel_depth == 2) {
216 float *motion_matrix,
int linesize)
218 int stride = linesize /
s->pixel_depth;
224 int factor =
s->pixel_depth == 1 ? 1 : 4;
227 #define CALCULATE(bps) \
229 uint##bps##_t *vsrc = (uint##bps##_t*)curr; \
230 uint##bps##_t *vdst = (uint##bps##_t*)s->prev_frame; \
231 for (int j = 0; j < s->height; j++) { \
232 for (int i = 0; i < s->width; i++) { \
234 curr_index = j * stride + i; \
235 prev_index = j * s->width + i; \
236 curr_data = s->full_range ? vsrc[curr_index] : convert_full_range(factor, vsrc[curr_index]); \
237 if (s->nb_frames > 1) \
238 motion = curr_data - vdst[prev_index]; \
239 vdst[prev_index] = curr_data; \
240 motion_matrix[j * s->width + i] = motion; \
245 if (
s->pixel_depth == 2) {
258 for (
int j = 0; j <
height; j++)
264 for (
int j = 0; j <
height; j++) {
266 float mean_diff = img_metrics[j *
width +
i] -
mean;
267 sqr_diff += (mean_diff * mean_diff);
270 sqr_diff = sqr_diff /
size;
271 return sqrt(sqr_diff);
298 s->max_si =
fmaxf(si,
s->max_si);
299 s->max_ti =
fmaxf(ti,
s->max_ti);
302 s->min_si =
s->nb_frames == 1 ? si :
fminf(si,
s->min_si);
303 s->min_ti =
s->nb_frames == 1 ? ti :
fminf(ti,
s->min_ti);
312#define OFFSET(x) offsetof(SiTiContext, x)
313#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
333 .p.description =
NULL_IF_CONFIG_SMALL(
"Calculate spatial information (SI) and temporal information (TI)."),
334 .p.priv_class = &siti_class,
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static int config_input(AVFilterLink *inlink)
const FFFilter ff_vf_siti
static AVFormatContext * ctx
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define i(width, name, range_min, range_max)
float fminf(float, float)
float fmaxf(float, float)
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
int(* init)(AVBSFContext *ctx)
static int print_summary(int interrupted)
@ AV_OPT_TYPE_BOOL
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_INFO
Standard information.
void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], const AVPixFmtDescriptor *pixdesc)
Compute the max pixel step for each plane of an image with a format described by pixdesc.
static av_cold void uninit(AVBitStreamFilterContext *ctx)
static int shift(int a, int b)
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FILTER_PIXFMTS_ARRAY(array)
#define AVFILTER_DEFINE_CLASS(fname)
static const int factor[16]
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
Memory handling functions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_YUV420P10
@ AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_NB
Not part of ABI.
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_YUV422P10
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ 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_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.
AVFilterLink ** outputs
array of pointers to output links
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.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static float mean(const float *input, int size)
static const AVOption siti_options[]
static void calculate_motion(SiTiContext *s, const uint8_t *curr, float *motion_matrix, int linesize)
static const int Y_FILTER[9]
static const int X_FILTER[9]
static int is_full_range(AVFrame *frame)
static const AVFilterPad avfilter_vf_siti_inputs[]
static int config_input(AVFilterLink *inlink)
static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
static void convolve_sobel(SiTiContext *s, const uint8_t *src, float *dst, int linesize)
static void set_meta(AVDictionary **metadata, const char *key, float d)
static uint16_t convert_full_range(int factor, uint16_t y)
static av_cold void uninit(AVFilterContext *ctx)
static float std_deviation(float *img_metrics, int width, int height)
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.