FFmpeg
Data Structures | Macros | Functions | Variables
vf_vif.c File Reference
#include <float.h>
#include "libavutil/avstring.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "framesync.h"
#include "drawutils.h"
#include "formats.h"
#include "internal.h"
#include "video.h"

Go to the source code of this file.

Data Structures

struct  VIFContext
 
struct  ThreadData
 Used for passing data between threads. More...
 

Macros

#define NUM_DATA_BUFS   13
 
#define OFFSET(x)   offsetof(VIFContext, x)
 
#define offset_fn(type, bits)
 
#define PF(suf)   AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf
 

Functions

 AVFILTER_DEFINE_CLASS (vif)
 
static void vif_dec2 (const float *src, float *dst, int w, int h, int src_stride, int dst_stride)
 
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 void vif_xx_yy_xy (const float *x, const float *y, float *xx, float *yy, float *xy, int w, int h)
 
static int vif_filter1d (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
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)
 
 offset_fn (uint8_t, 8)
 
static AVFramedo_vif (AVFilterContext *ctx, AVFrame *main, const AVFrame *ref)
 
static int config_input_ref (AVFilterLink *inlink)
 
static int process_frame (FFFrameSync *fs)
 
static int config_output (AVFilterLink *outlink)
 
static int activate (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 

Variables

static const AVOption vif_options []
 
static const uint8_t vif_filter1d_width1 [4] = { 17, 9, 5, 3 }
 
static const float vif_filter1d_table [4][17]
 
static enum AVPixelFormat pix_fmts []
 
static const AVFilterPad vif_inputs []
 
static const AVFilterPad vif_outputs []
 
const AVFilter ff_vf_vif
 

Detailed Description

Calculate VIF between two input videos.

Definition in file vf_vif.c.

Macro Definition Documentation

◆ NUM_DATA_BUFS

#define NUM_DATA_BUFS   13

Definition at line 40 of file vf_vif.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(VIFContext, x)

Definition at line 60 of file vf_vif.c.

◆ offset_fn

#define offset_fn (   type,
  bits 
)
Value:
static void offset_##bits##bit(VIFContext *s, \
const AVFrame *ref, \
{ \
int w = s->width; \
int h = s->height; \
\
int ref_stride = ref->linesize[0]; \
int main_stride = main->linesize[0]; \
\
const type *ref_ptr = (const type *) ref->data[0]; \
const type *main_ptr = (const type *) main->data[0]; \
\
const float factor = s->factor; \
\
float *ref_ptr_data = s->ref_data; \
float *main_ptr_data = s->main_data; \
for (int i = 0; i < h; i++) { \
for (int j = 0; j < w; j++) { \
ref_ptr_data[j] = ref_ptr[j] * factor - 128.f; \
main_ptr_data[j] = main_ptr[j] * factor - 128.f; \
} \
ref_ptr += ref_stride / sizeof(type); \
ref_ptr_data += w; \
main_ptr += main_stride / sizeof(type); \
main_ptr_data += w; \
} \
}

Definition at line 398 of file vf_vif.c.

◆ PF

#define PF (   suf)    AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf

Function Documentation

◆ AVFILTER_DEFINE_CLASS()

AVFILTER_DEFINE_CLASS ( vif  )

◆ vif_dec2()

static void vif_dec2 ( const float *  src,
float *  dst,
int  w,
int  h,
int  src_stride,
int  dst_stride 
)
static

Definition at line 101 of file vf_vif.c.

Referenced by compute_vif2().

◆ vif_statistic()

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

Definition at line 112 of file vf_vif.c.

Referenced by compute_vif2().

◆ vif_xx_yy_xy()

static void vif_xx_yy_xy ( const float *  x,
const float *  y,
float *  xx,
float *  yy,
float *  xy,
int  w,
int  h 
)
static

Definition at line 185 of file vf_vif.c.

Referenced by compute_vif2().

◆ vif_filter1d()

static int vif_filter1d ( AVFilterContext ctx,
void *  arg,
int  jobnr,
int  nb_jobs 
)
static

Vertical pass.

Horizontal pass.

Definition at line 209 of file vf_vif.c.

Referenced by compute_vif2().

◆ compute_vif2()

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 
)
static

Definition at line 287 of file vf_vif.c.

Referenced by do_vif().

◆ offset_fn()

offset_fn ( uint8_t  ,
 
)

Definition at line 429 of file vf_vif.c.

◆ do_vif()

static AVFrame* do_vif ( AVFilterContext ctx,
AVFrame main,
const AVFrame ref 
)
static

Definition at line 439 of file vf_vif.c.

Referenced by process_frame().

◆ config_input_ref()

static int config_input_ref ( AVFilterLink inlink)
static

Definition at line 484 of file vf_vif.c.

◆ process_frame()

static int process_frame ( FFFrameSync fs)
static

Definition at line 527 of file vf_vif.c.

Referenced by config_output().

◆ config_output()

static int config_output ( AVFilterLink outlink)
static

Definition at line 551 of file vf_vif.c.

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 582 of file vf_vif.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 588 of file vf_vif.c.

Variable Documentation

◆ vif_options

const AVOption vif_options[]
static
Initial value:
= {
{ NULL }
}

Definition at line 62 of file vf_vif.c.

◆ vif_filter1d_width1

const uint8_t vif_filter1d_width1[4] = { 17, 9, 5, 3 }
static

Definition at line 68 of file vf_vif.c.

Referenced by compute_vif2().

◆ vif_filter1d_table

const float vif_filter1d_table[4][17]
static
Initial value:
=
{
{
0.00745626912, 0.0142655009, 0.0250313189, 0.0402820669, 0.0594526194,
0.0804751068, 0.0999041125, 0.113746084, 0.118773937, 0.113746084,
0.0999041125, 0.0804751068, 0.0594526194, 0.0402820669, 0.0250313189,
0.0142655009, 0.00745626912
},
{
0.0189780835, 0.0558981746, 0.120920904, 0.192116052, 0.224173605,
0.192116052, 0.120920904, 0.0558981746, 0.0189780835
},
{
0.054488685, 0.244201347, 0.402619958, 0.244201347, 0.054488685
},
{
0.166378498, 0.667243004, 0.166378498
}
}

Definition at line 70 of file vf_vif.c.

Referenced by compute_vif2().

◆ pix_fmts

enum AVPixelFormat pix_fmts[]
static

◆ vif_inputs

const AVFilterPad vif_inputs[]
static
Initial value:
= {
{
.name = "main",
},{
.name = "reference",
.config_props = config_input_ref,
},
}

Definition at line 612 of file vf_vif.c.

◆ vif_outputs

const AVFilterPad vif_outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_output,
},
}

Definition at line 623 of file vf_vif.c.

◆ ff_vf_vif

const AVFilter ff_vf_vif
Initial value:
= {
.name = "vif",
.description = NULL_IF_CONFIG_SMALL("Calculate the VIF between two video streams."),
.uninit = uninit,
.priv_size = sizeof(VIFContext),
.priv_class = &vif_class,
}

Definition at line 631 of file vf_vif.c.

vif_outputs
static const AVFilterPad vif_outputs[]
Definition: vf_vif.c:623
stride
int stride
Definition: mace.c:144
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:171
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:317
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_vif.c:588
w
uint8_t w
Definition: llviddspenc.c:38
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_vif.c:472
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:384
bit
#define bit(string, value)
Definition: cbs_mpeg2.c:58
type
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 type
Definition: writing_filters.txt:86
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:388
AV_PIX_FMT_YUVJ411P
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:248
AV_PIX_FMT_YUVJ422P
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
s
#define s(width, name)
Definition: cbs_vp9.c:257
bits
uint8_t bits
Definition: vp3data.h:141
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:387
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:191
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:385
main
int main(int argc, char *argv[])
Definition: avio_list_dir.c:112
NULL
#define NULL
Definition: coverity.c:32
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
AV_PIX_FMT_YUVJ440P
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:100
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_vif.c:551
PF
#define PF(suf)
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
vif_inputs
static const AVFilterPad vif_inputs[]
Definition: vf_vif.c:612
AVFILTER_FLAG_METADATA_ONLY
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
Definition: avfilter.h:137
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
factor
static const int factor[16]
Definition: vf_pp7.c:76
activate
static int activate(AVFilterContext *ctx)
Definition: vf_vif.c:582
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:121
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:192
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition: avfilter.h:154
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
h
h
Definition: vp9dsp_template.c:2038
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:386
VIFContext
Definition: vf_vif.c:42
config_input_ref
static int config_input_ref(AVFilterLink *inlink)
Definition: vf_vif.c:484