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 "psnr.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 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 78 of file vf_xpsnr.c.

◆ OFFSET

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

Definition at line 79 of file vf_xpsnr.c.

◆ XPSNR_GAMMA

#define XPSNR_GAMMA   2

Definition at line 80 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 92 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 112 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 128 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 147 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 164 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 252 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 269 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 384 of file vf_xpsnr.c.

Referenced by do_xpsnr().

◆ do_xpsnr()

static int do_xpsnr ( FFFrameSync fs)
static

Definition at line 397 of file vf_xpsnr.c.

Referenced by init().

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 506 of file vf_xpsnr.c.

◆ config_input_ref()

static int config_input_ref ( AVFilterLink inlink)
static

Definition at line 561 of file vf_xpsnr.c.

◆ config_output()

static int config_output ( AVFilterLink outlink)
static

Definition at line 607 of file vf_xpsnr.c.

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 639 of file vf_xpsnr.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 646 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 82 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 711 of file vf_xpsnr.c.

◆ xpsnr_outputs

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

Definition at line 722 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 730 of file vf_xpsnr.c.

AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:525
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: filters.h:242
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_xpsnr.c:506
FLAGS
#define FLAGS
Definition: vf_xpsnr.c:78
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_xpsnr.c:646
OFFSET
#define OFFSET(x)
Definition: vf_xpsnr.c:79
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:482
activate
static int activate(AVFilterContext *ctx)
Definition: vf_xpsnr.c:639
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:520
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:518
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
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:522
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:523
config_output
static int config_output(AVFilterLink *outlink)
Definition: vf_xpsnr.c:607
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:485
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
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:521
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:517
xpsnr_formats
static enum AVPixelFormat xpsnr_formats[]
Definition: vf_xpsnr.c:546
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:722
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:519
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:711
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:561
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:44
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:484