FFmpeg
Data Structures | Macros | Functions | Variables
vf_xpsnr.c File Reference
#include "libavutil/avstring.h"
#include "libavutil/file_open.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "drawutils.h"
#include "filters.h"
#include "framesync.h"
#include "xpsnr.h"

Go to the source code of this file.

Data Structures

struct  XPSNRContext
 

Macros

#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM
 
#define OFFSET(x)   offsetof(XPSNRContext, x)
 
#define XPSNR_GAMMA   2
 
#define PF_NOALPHA(suf)   AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf
 
#define PF_ALPHA(suf)   AV_PIX_FMT_YUVA420##suf, AV_PIX_FMT_YUVA422##suf, AV_PIX_FMT_YUVA444##suf
 
#define PF(suf)   PF_NOALPHA(suf), PF_ALPHA(suf)
 

Functions

 FRAMESYNC_DEFINE_CLASS (xpsnr, XPSNRContext, fs)
 
static uint64_t highds (const int x_act, const int y_act, const int w_act, const int h_act, const int16_t *o_m0, const int o)
 
static uint64_t diff1st (const uint32_t w_act, const uint32_t h_act, const int16_t *o_m0, int16_t *o_m1, const int o)
 
static uint64_t diff2nd (const uint32_t w_act, const uint32_t h_act, const int16_t *o_m0, int16_t *o_m1, int16_t *o_m2, const int o)
 
static uint64_t sse_line_16bit (const uint8_t *blk_org8, const uint8_t *blk_rec8, int block_width)
 
static uint64_t calc_squared_error (XPSNRContext const *s, const int16_t *blk_org, const uint32_t stride_org, const int16_t *blk_rec, const uint32_t stride_rec, const uint32_t block_width, const uint32_t block_height)
 
static double calc_squared_error_and_weight (XPSNRContext const *s, const int16_t *pic_org, const uint32_t stride_org, int16_t *pic_org_m1, int16_t *pic_org_m2, const int16_t *pic_rec, const uint32_t stride_rec, const uint32_t offset_x, const uint32_t offset_y, const uint32_t block_width, const uint32_t block_height, const uint32_t bit_depth, const uint32_t int_frame_rate, double *ms_act)
 
static double get_avg_xpsnr (const double sqrt_wsse_val, const double sum_xpsnr_val, const uint32_t image_width, const uint32_t image_height, const uint64_t max_error_64, const uint64_t num_frames_64)
 
static int get_wsse (AVFilterContext *ctx, int16_t **org, int16_t **org_m1, int16_t **org_m2, int16_t **rec, uint64_t *const wsse64)
 
static void set_meta (AVDictionary **metadata, const char *key, char comp, float d)
 
static int do_xpsnr (FFFrameSync *fs)
 
static av_cold int init (AVFilterContext *ctx)
 
static int config_input_ref (AVFilterLink *inlink)
 
static int config_output (AVFilterLink *outlink)
 
static int activate (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 

Variables

static const AVOption xpsnr_options []
 
static enum AVPixelFormat xpsnr_formats []
 
static const AVFilterPad xpsnr_inputs []
 
static const AVFilterPad xpsnr_outputs []
 
const AVFilter ff_vf_xpsnr
 

Detailed Description

Calculate the extended perceptually weighted PSNR (XPSNR) between two input videos.

Authors: Christian Helmrich, Lehmann, and Stoffers, Fraunhofer HHI, Berlin, Germany

Definition in file vf_xpsnr.c.

Macro Definition Documentation

◆ FLAGS

Definition at line 76 of file vf_xpsnr.c.

◆ OFFSET

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

Definition at line 77 of file vf_xpsnr.c.

◆ XPSNR_GAMMA

#define XPSNR_GAMMA   2

Definition at line 78 of file vf_xpsnr.c.

◆ PF_NOALPHA

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

◆ PF_ALPHA

#define PF_ALPHA (   suf)    AV_PIX_FMT_YUVA420##suf, AV_PIX_FMT_YUVA422##suf, AV_PIX_FMT_YUVA444##suf

◆ PF

#define PF (   suf)    PF_NOALPHA(suf), PF_ALPHA(suf)

Function Documentation

◆ FRAMESYNC_DEFINE_CLASS()

FRAMESYNC_DEFINE_CLASS ( xpsnr  ,
XPSNRContext  ,
fs   
)

◆ highds()

static uint64_t highds ( const int  x_act,
const int  y_act,
const int  w_act,
const int  h_act,
const int16_t *  o_m0,
const int  o 
)
static

Definition at line 90 of file vf_xpsnr.c.

Referenced by calc_squared_error_and_weight(), and config_input_ref().

◆ diff1st()

static uint64_t diff1st ( const uint32_t  w_act,
const uint32_t  h_act,
const int16_t *  o_m0,
int16_t *  o_m1,
const int  o 
)
static

Definition at line 110 of file vf_xpsnr.c.

Referenced by config_input_ref().

◆ diff2nd()

static uint64_t diff2nd ( const uint32_t  w_act,
const uint32_t  h_act,
const int16_t *  o_m0,
int16_t *  o_m1,
int16_t *  o_m2,
const int  o 
)
static

Definition at line 126 of file vf_xpsnr.c.

Referenced by config_input_ref().

◆ sse_line_16bit()

static uint64_t sse_line_16bit ( const uint8_t *  blk_org8,
const uint8_t *  blk_rec8,
int  block_width 
)
static

Definition at line 145 of file vf_xpsnr.c.

Referenced by config_input_ref().

◆ calc_squared_error()

static uint64_t calc_squared_error ( XPSNRContext const *  s,
const int16_t *  blk_org,
const uint32_t  stride_org,
const int16_t *  blk_rec,
const uint32_t  stride_rec,
const uint32_t  block_width,
const uint32_t  block_height 
)
inlinestatic

Definition at line 161 of file vf_xpsnr.c.

Referenced by calc_squared_error_and_weight(), and get_wsse().

◆ calc_squared_error_and_weight()

static double calc_squared_error_and_weight ( XPSNRContext const *  s,
const int16_t *  pic_org,
const uint32_t  stride_org,
int16_t *  pic_org_m1,
int16_t *  pic_org_m2,
const int16_t *  pic_rec,
const uint32_t  stride_rec,
const uint32_t  offset_x,
const uint32_t  offset_y,
const uint32_t  block_width,
const uint32_t  block_height,
const uint32_t  bit_depth,
const uint32_t  int_frame_rate,
double ms_act 
)
inlinestatic

Definition at line 178 of file vf_xpsnr.c.

Referenced by get_wsse().

◆ get_avg_xpsnr()

static double get_avg_xpsnr ( const double  sqrt_wsse_val,
const double  sum_xpsnr_val,
const uint32_t  image_width,
const uint32_t  image_height,
const uint64_t  max_error_64,
const uint64_t  num_frames_64 
)
inlinestatic

Definition at line 266 of file vf_xpsnr.c.

Referenced by do_xpsnr(), and uninit().

◆ get_wsse()

static int get_wsse ( AVFilterContext ctx,
int16_t **  org,
int16_t **  org_m1,
int16_t **  org_m2,
int16_t **  rec,
uint64_t *const  wsse64 
)
static

Definition at line 283 of file vf_xpsnr.c.

Referenced by do_xpsnr().

◆ set_meta()

static void set_meta ( AVDictionary **  metadata,
const char *  key,
char  comp,
float  d 
)
static

Definition at line 398 of file vf_xpsnr.c.

Referenced by do_xpsnr().

◆ do_xpsnr()

static int do_xpsnr ( FFFrameSync fs)
static

Definition at line 411 of file vf_xpsnr.c.

Referenced by init().

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 520 of file vf_xpsnr.c.

◆ config_input_ref()

static int config_input_ref ( AVFilterLink inlink)
static

Definition at line 575 of file vf_xpsnr.c.

◆ config_output()

static int config_output ( AVFilterLink outlink)
static

Definition at line 623 of file vf_xpsnr.c.

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 655 of file vf_xpsnr.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 662 of file vf_xpsnr.c.

Variable Documentation

◆ xpsnr_options

const AVOption xpsnr_options[]
static
Initial value:
= {
{"stats_file", "Set file where to store per-frame XPSNR information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS},
{"f", "Set file where to store per-frame XPSNR information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, FLAGS},
{ NULL }
}

Definition at line 80 of file vf_xpsnr.c.

◆ xpsnr_formats

enum AVPixelFormat xpsnr_formats[]
static

◆ xpsnr_inputs

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

Definition at line 727 of file vf_xpsnr.c.

◆ xpsnr_outputs

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

Definition at line 738 of file vf_xpsnr.c.

◆ ff_vf_xpsnr

const AVFilter ff_vf_xpsnr
Initial value:
= {
.name = "xpsnr",
.description = NULL_IF_CONFIG_SMALL("Calculate the extended perceptually weighted peak signal-to-noise ratio (XPSNR) between two video streams."),
.preinit = xpsnr_framesync_preinit,
.init = init,
.uninit = uninit,
.activate = activate,
.priv_size = sizeof(XPSNRContext),
.priv_class = &xpsnr_class,
}

Definition at line 746 of file vf_xpsnr.c.

AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:501
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: filters.h:242
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_xpsnr.c:520
FLAGS
#define FLAGS
Definition: vf_xpsnr.c:76
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_xpsnr.c:662
OFFSET
#define OFFSET(x)
Definition: vf_xpsnr.c:77
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
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:458
activate
static int activate(AVFilterContext *ctx)
Definition: vf_xpsnr.c:655
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:496
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:212
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:494
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:462
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
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
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:498
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:499
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_xpsnr.c:623
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:461
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:459
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:497
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
PF
#define PF(suf)
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:493
xpsnr_formats
static enum AVPixelFormat xpsnr_formats[]
Definition: vf_xpsnr.c:560
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
P
#define P
PF_NOALPHA
#define PF_NOALPHA(suf)
xpsnr_outputs
static const AVFilterPad xpsnr_outputs[]
Definition: vf_xpsnr.c:738
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:495
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
xpsnr_inputs
static const AVFilterPad xpsnr_inputs[]
Definition: vf_xpsnr.c:727
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
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
config_input_ref
static int config_input_ref(AVFilterLink *inlink)
Definition: vf_xpsnr.c:575
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:165
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
XPSNRContext
Definition: vf_xpsnr.c:43
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
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:460