FFmpeg
Data Structures | Macros | Functions | Variables
vf_vif.c File Reference
#include <float.h>
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "filters.h"
#include "framesync.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

 FRAMESYNC_DEFINE_CLASS (vif, VIFContext, fs)
 
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 37 of file vf_vif.c.

◆ OFFSET

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

Definition at line 57 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 395 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

◆ FRAMESYNC_DEFINE_CLASS()

FRAMESYNC_DEFINE_CLASS ( vif  ,
VIFContext  ,
fs   
)

◆ 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 98 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 109 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 182 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 206 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 284 of file vf_vif.c.

Referenced by do_vif().

◆ offset_fn()

offset_fn ( uint8_t  ,
 
)

Definition at line 426 of file vf_vif.c.

◆ do_vif()

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

Definition at line 436 of file vf_vif.c.

Referenced by process_frame().

◆ config_input_ref()

static int config_input_ref ( AVFilterLink inlink)
static

Definition at line 481 of file vf_vif.c.

◆ process_frame()

static int process_frame ( FFFrameSync fs)
static

Definition at line 524 of file vf_vif.c.

Referenced by config_output().

◆ config_output()

static int config_output ( AVFilterLink outlink)
static

Definition at line 548 of file vf_vif.c.

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 581 of file vf_vif.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 587 of file vf_vif.c.

Variable Documentation

◆ vif_options

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

Definition at line 59 of file vf_vif.c.

◆ vif_filter1d_width1

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

Definition at line 65 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 67 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 611 of file vf_vif.c.

◆ vif_outputs

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

Definition at line 622 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."),
.preinit = vif_framesync_preinit,
.uninit = uninit,
.priv_size = sizeof(VIFContext),
.priv_class = &vif_class,
}

Definition at line 630 of file vf_vif.c.

vif_outputs
static const AVFilterPad vif_outputs[]
Definition: vf_vif.c:622
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: filters.h:242
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_vif.c:587
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:106
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_vif.c:469
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:482
bit
#define bit(string, value)
Definition: cbs_mpeg2.c:56
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:486
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:283
main
int main
Definition: dovi_rpuenc.c:37
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:86
s
#define s(width, name)
Definition: cbs_vp9.c:198
bits
uint8_t bits
Definition: vp3data.h:128
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:485
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:73
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
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:87
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:483
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:85
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
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:94
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
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:107
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_vif.c:548
stride
#define stride
Definition: h264pred_template.c:537
PF
#define PF(suf)
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
vif_inputs
static const AVFilterPad vif_inputs[]
Definition: vf_vif.c:611
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:168
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
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:78
factor
static const int factor[16]
Definition: vf_pp7.c:80
activate
static int activate(AVFilterContext *ctx)
Definition: vf_vif.c:581
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:152
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:77
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:80
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:190
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:79
h
h
Definition: vp9dsp_template.c:2070
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:484
VIFContext
Definition: vf_vif.c:39
config_input_ref
static int config_input_ref(AVFilterLink *inlink)
Definition: vf_vif.c:481