Go to the documentation of this file.
38 #define NUM_DATA_BUFS 13
58 #define OFFSET(x) offsetof(VIFContext, x)
71 0.00745626912, 0.0142655009, 0.0250313189, 0.0402820669, 0.0594526194,
72 0.0804751068, 0.0999041125, 0.113746084, 0.118773937, 0.113746084,
73 0.0999041125, 0.0804751068, 0.0594526194, 0.0402820669, 0.0250313189,
74 0.0142655009, 0.00745626912
77 0.0189780835, 0.0558981746, 0.120920904, 0.192116052, 0.224173605,
78 0.192116052, 0.120920904, 0.0558981746, 0.0189780835
81 0.054488685, 0.244201347, 0.402619958, 0.244201347, 0.054488685
84 0.166378498, 0.667243004, 0.166378498
100 int src_stride,
int dst_stride)
102 const int dst_px_stride = dst_stride / 2;
104 for (
int i = 0;
i <
h / 2;
i++) {
105 for (
int j = 0; j <
w / 2; j++)
106 dst[
i * dst_px_stride + j] =
src[(
i * 2) * src_stride + (j * 2)];
111 const float *mu1_mu2,
const float *xx_filt,
112 const float *yy_filt,
const float *xy_filt,
113 float *num,
float *den,
int w,
int h)
115 static const float sigma_nsq = 2;
116 float mu1_sq_val, mu2_sq_val, mu1_mu2_val, xx_filt_val, yy_filt_val, xy_filt_val;
117 float sigma1_sq, sigma2_sq, sigma12,
g, sv_sq, eps = 1.0e-10
f;
118 float gain_limit = 100.f;
119 float num_val, den_val;
120 float accum_num = 0.0f;
121 float accum_den = 0.0f;
123 for (
int i = 0;
i <
h;
i++) {
124 float accum_inner_num = 0.f;
125 float accum_inner_den = 0.f;
127 for (
int j = 0; j <
w; j++) {
128 mu1_sq_val = mu1_sq[
i *
w + j];
129 mu2_sq_val = mu2_sq[
i *
w + j];
130 mu1_mu2_val = mu1_mu2[
i *
w + j];
131 xx_filt_val = xx_filt[
i *
w + j];
132 yy_filt_val = yy_filt[
i *
w + j];
133 xy_filt_val = xy_filt[
i *
w + j];
135 sigma1_sq = xx_filt_val - mu1_sq_val;
136 sigma2_sq = yy_filt_val - mu2_sq_val;
137 sigma12 = xy_filt_val - mu1_mu2_val;
139 sigma1_sq =
FFMAX(sigma1_sq, 0.0
f);
140 sigma2_sq =
FFMAX(sigma2_sq, 0.0
f);
141 sigma12 =
FFMAX(sigma12, 0.0
f);
143 g = sigma12 / (sigma1_sq + eps);
144 sv_sq = sigma2_sq -
g * sigma12;
146 if (sigma1_sq < eps) {
152 if (sigma2_sq < eps) {
161 sv_sq =
FFMAX(sv_sq, eps);
165 num_val =
log2f(1.0
f +
g *
g * sigma1_sq / (sv_sq + sigma_nsq));
166 den_val =
log2f(1.0
f + sigma1_sq / sigma_nsq);
169 num_val = den_val = 1.f;
171 accum_inner_num += num_val;
172 accum_inner_den += den_val;
175 accum_num += accum_inner_num;
176 accum_den += accum_inner_den;
183 static void vif_xx_yy_xy(
const float *x,
const float *y,
float *xx,
float *yy,
184 float *xy,
int w,
int h)
186 for (
int i = 0;
i <
h;
i++) {
187 for (
int j = 0; j <
w; j++) {
190 float xxval = xval * xval;
191 float yyval = yval * yval;
192 float xyval = xval * yval;
211 const float *
src = td->
src;
224 for (
int j = 0; j <
w; j++) {
227 if (
i >= filt_w / 2 &&
i <
h - filt_w / 2 - 1) {
228 for (
int filt_i = 0; filt_i < filt_w; filt_i++) {
229 const float filt_coeff =
filter[filt_i];
231 int ii =
i - filt_w / 2 + filt_i;
233 img_coeff =
src[ii * src_stride + j];
234 sum += filt_coeff * img_coeff;
237 for (
int filt_i = 0; filt_i < filt_w; filt_i++) {
238 const float filt_coeff =
filter[filt_i];
239 int ii =
i - filt_w / 2 + filt_i;
244 img_coeff =
src[ii * src_stride + j];
245 sum += filt_coeff * img_coeff;
253 for (
int j = 0; j <
w; j++) {
256 if (j >= filt_w / 2 && j <
w - filt_w / 2 - 1) {
257 for (
int filt_j = 0; filt_j < filt_w; filt_j++) {
258 const float filt_coeff =
filter[filt_j];
259 int jj = j - filt_w / 2 + filt_j;
262 img_coeff =
temp[jj];
263 sum += filt_coeff * img_coeff;
266 for (
int filt_j = 0; filt_j < filt_w; filt_j++) {
267 const float filt_coeff =
filter[filt_j];
268 int jj = j - filt_w / 2 + filt_j;
273 img_coeff =
temp[jj];
274 sum += filt_coeff * img_coeff;
278 dst[
i * dst_stride + j] = sum;
286 const float *
ref,
const float *
main,
int w,
int h,
287 int ref_stride,
int main_stride,
float *score,
292 float *ref_scale = data_buf[0];
293 float *main_scale = data_buf[1];
294 float *ref_sq = data_buf[2];
295 float *main_sq = data_buf[3];
296 float *ref_main = data_buf[4];
297 float *mu1 = data_buf[5];
298 float *mu2 = data_buf[6];
299 float *mu1_sq = data_buf[7];
300 float *mu2_sq = data_buf[8];
301 float *mu1_mu2 = data_buf[9];
302 float *ref_sq_filt = data_buf[10];
303 float *main_sq_filt = data_buf[11];
304 float *ref_main_filt = data_buf[12];
306 const float *curr_ref_scale =
ref;
307 const float *curr_main_scale =
main;
308 int curr_ref_stride = ref_stride;
309 int curr_main_stride = main_stride;
317 const int nb_threads =
FFMIN(
h, gnb_threads);
325 td.
src = curr_ref_scale;
334 td.
src = curr_main_scale;
339 vif_dec2(mu1, ref_scale, buf_valid_w, buf_valid_h,
w,
w);
340 vif_dec2(mu2, main_scale, buf_valid_w, buf_valid_h,
w,
w);
348 curr_ref_scale = ref_scale;
349 curr_main_scale = main_scale;
352 curr_main_stride =
w;
355 td.
src = curr_ref_scale;
364 td.
src = curr_main_scale;
371 vif_xx_yy_xy(curr_ref_scale, curr_main_scale, ref_sq, main_sq, ref_main,
w,
h);
374 td.
dst = ref_sq_filt;
379 td.
dst = main_sq_filt;
384 td.
dst = ref_main_filt;
387 vif_statistic(mu1_sq, mu2_sq, mu1_mu2, ref_sq_filt, main_sq_filt,
388 ref_main_filt, &num, &den,
w,
h);
390 score[
scale] = den <= FLT_EPSILON ? 1.f : num / den;
396 #define offset_fn(type, bits) \
397 static void offset_##bits##bit(VIFContext *s, \
398 const AVFrame *ref, \
399 AVFrame *main, int stride)\
404 int ref_stride = ref->linesize[0]; \
405 int main_stride = main->linesize[0]; \
407 const type *ref_ptr = (const type *) ref->data[0]; \
408 const type *main_ptr = (const type *) main->data[0]; \
410 const float factor = s->factor; \
412 float *ref_ptr_data = s->ref_data; \
413 float *main_ptr_data = s->main_data; \
415 for (int i = 0; i < h; i++) { \
416 for (int j = 0; j < w; j++) { \
417 ref_ptr_data[j] = ref_ptr[j] * factor - 128.f; \
418 main_ptr_data[j] = main_ptr[j] * factor - 128.f; \
420 ref_ptr += ref_stride / sizeof(type); \
422 main_ptr += main_stride / sizeof(type); \
423 main_ptr_data += w; \
443 s->factor = 1.f / (1 << (
s->desc->comp[0].depth - 8));
444 if (
s->desc->comp[0].depth <= 8) {
451 s->width,
s->height,
s->width,
s->width,
452 score,
s->data_buf,
s->temp,
s->nb_threads);
459 for (
int i = 0;
i < 4;
i++) {
460 s->vif_min[
i] =
FFMIN(
s->vif_min[
i], score[
i]);
461 s->vif_max[
i] =
FFMAX(
s->vif_max[
i], score[
i]);
462 s->vif_sum[
i] += score[
i];
477 #define PF(suf) AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf
487 if (
ctx->inputs[0]->w !=
ctx->inputs[1]->w ||
488 ctx->inputs[0]->h !=
ctx->inputs[1]->h) {
494 s->width =
ctx->inputs[0]->w;
495 s->height =
ctx->inputs[0]->h;
498 for (
int i = 0;
i < 4;
i++) {
499 s->vif_min[
i] = DBL_MAX;
500 s->vif_max[
i] = -DBL_MAX;
504 if (!(
s->data_buf[
i] =
av_calloc(
s->width,
s->height *
sizeof(
float))))
508 if (!(
s->ref_data =
av_calloc(
s->width,
s->height *
sizeof(
float))))
511 if (!(
s->main_data =
av_calloc(
s->width,
s->height *
sizeof(
float))))
514 if (!(
s->temp =
av_calloc(
s->nb_threads,
sizeof(
s->temp[0]))))
517 for (
int i = 0;
i <
s->nb_threads;
i++) {
538 out_frame = main_frame;
559 outlink->
w = mainlink->
w;
560 outlink->
h = mainlink->
h;
592 if (
s->nb_frames > 0) {
593 for (
int i = 0;
i < 4;
i++)
595 i,
s->vif_sum[
i] /
s->nb_frames,
s->vif_min[
i],
s->vif_max[
i]);
604 for (
int i = 0;
i <
s->nb_threads &&
s->temp;
i++)
634 .p.priv_class = &vif_class,
638 .preinit = vif_framesync_preinit,
static const AVFilterPad vif_outputs[]
AVRational time_base
Time base for the incoming frames.
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
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
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
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)
static int process_frame(FFFrameSync *fs)
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
#define offset_fn(type, bits)
static void vif_xx_yy_xy(const float *x, const float *y, float *xx, float *yy, float *xy, int w, int h)
This structure describes decoded (raw) audio or video data.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
static av_cold void uninit(AVFilterContext *ctx)
static const float vif_filter1d_table[4][17]
void(* filter)(uint8_t *src, int stride, int qscale)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
static int vif_filter1d(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static enum AVPixelFormat pix_fmts[]
static const uint8_t vif_filter1d_width1[4]
@ EXT_STOP
Completely stop all streams with this one.
A link between two filters.
Link properties exposed to filter code, but not external callers.
const AVPixFmtDescriptor * desc
static int slice_end(AVCodecContext *avctx, AVFrame *pict, int *got_output)
Handle slice ends.
#define FILTER_PIXFMTS_ARRAY(array)
static void vif_dec2(const float *src, float *dst, int w, int h, int src_stride, int dst_stride)
#define AV_PIX_FMT_GRAY16
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events.
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 ...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define FILTER_OUTPUTS(array)
static FilterLink * ff_filter_link(AVFilterLink *link)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
static AVFormatContext * ctx
#define AV_PIX_FMT_GRAY14
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
static AVFrame * do_vif(AVFilterContext *ctx, AVFrame *main, const AVFrame *ref)
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
#define AV_PIX_FMT_GRAY10
Describe the class of an AVClass context structure.
#define fs(width, name, subs,...)
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static av_always_inline av_const int avpriv_mirror(int x, int w)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
#define i(width, name, range_min, range_max)
static int ref_frame(VVCFrame *dst, const VVCFrame *src)
AVFilterContext * src
source filter
#define AV_LOG_INFO
Standard information.
static int compute_vif2(AVFilterContext *ctx, const float *ref, const float *main, int w, int h, int ref_stride, int main_stride, float *score, float *const data_buf[NUM_DATA_BUFS], float **temp, int gnb_threads)
int w
agreed upon image width
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Used for passing data between threads.
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 int config_output(AVFilterLink *outlink)
void * av_calloc(size_t nmemb, size_t size)
static void vif_statistic(const float *mu1_sq, const float *mu2_sq, const float *mu1_mu2, const float *xx_filt, const float *yy_filt, const float *xy_filt, float *num, float *den, int w, int h)
static int slice_start(SliceContext *sc, VVCContext *s, VVCFrameContext *fc, const CodedBitstreamUnit *unit, const int is_first_slice)
int ff_framesync_init(FFFrameSync *fs, AVFilterContext *parent, unsigned nb_in)
Initialize a frame sync structure.
#define FILTER_INPUTS(array)
static void set_meta(AVDictionary **metadata, int chan, const char *key, const char *fmt, float val)
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
int h
agreed upon image height
int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
static const AVFilterPad vif_inputs[]
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
static int ref[MAX_W *MAX_W]
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
float * data_buf[NUM_DATA_BUFS]
static int activate(AVFilterContext *ctx)
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
AVFilter p
The public AVFilter.
@ 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 void scale(int *out, const int *in, const int w, const int h, const int shift)
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)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
static int ff_slice_pos(int total, int jobnr, int nb_jobs)
Compute the boundary index for a slice when work of size total is split into nb_jobs slices.
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable.
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
static const AVOption vif_options[]
#define AV_PIX_FMT_GRAY12
FRAMESYNC_DEFINE_CLASS(vif, VIFContext, fs)
static int config_input_ref(AVFilterLink *inlink)