FFmpeg
Data Structures | Macros | Functions | Variables
vf_ssim.c File Reference
#include "libavutil/avstring.h"
#include "libavutil/file_open.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avfilter.h"
#include "drawutils.h"
#include "framesync.h"
#include "internal.h"
#include "ssim.h"

Go to the source code of this file.

Data Structures

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

Macros

#define OFFSET(x)   offsetof(SSIMContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
#define SUM_LEN(w)   (((w) >> 2) + 3)
 
#define PF(suf)   AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf, AV_PIX_FMT_GBR##suf
 

Functions

 FRAMESYNC_DEFINE_CLASS (ssim, SSIMContext, fs)
 
static void set_meta (AVDictionary **metadata, const char *key, char comp, float d)
 
static void ssim_4x4xn_16bit (const uint8_t *main8, ptrdiff_t main_stride, const uint8_t *ref8, ptrdiff_t ref_stride, int64_t(*sums)[4], int width)
 
static void ssim_4x4xn_8bit (const uint8_t *main, ptrdiff_t main_stride, const uint8_t *ref, ptrdiff_t ref_stride, int(*sums)[4], int width)
 
static float ssim_end1x (int64_t s1, int64_t s2, int64_t ss, int64_t s12, int max)
 
static float ssim_end1 (int s1, int s2, int ss, int s12)
 
static float ssim_endn_16bit (const int64_t(*sum0)[4], const int64_t(*sum1)[4], int width, int max)
 
static double ssim_endn_8bit (const int(*sum0)[4], const int(*sum1)[4], int width)
 
static int ssim_plane_16bit (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static int ssim_plane (AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 
static double ssim_db (double ssim, double weight)
 
static int do_ssim (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 ssim_options []
 
static enum AVPixelFormat pix_fmts []
 
static const AVFilterPad ssim_inputs []
 
static const AVFilterPad ssim_outputs []
 
const AVFilter ff_vf_ssim
 

Macro Definition Documentation

◆ OFFSET

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

Definition at line 70 of file vf_ssim.c.

◆ FLAGS

Definition at line 71 of file vf_ssim.c.

◆ SUM_LEN

#define SUM_LEN (   w)    (((w) >> 2) + 3)

Definition at line 220 of file vf_ssim.c.

◆ PF

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

Function Documentation

◆ FRAMESYNC_DEFINE_CLASS()

FRAMESYNC_DEFINE_CLASS ( ssim  ,
SSIMContext  ,
fs   
)

◆ set_meta()

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

Definition at line 81 of file vf_ssim.c.

Referenced by do_ssim().

◆ ssim_4x4xn_16bit()

static void ssim_4x4xn_16bit ( const uint8_t *  main8,
ptrdiff_t  main_stride,
const uint8_t *  ref8,
ptrdiff_t  ref_stride,
int64_t(*)  sums[4],
int  width 
)
static

Definition at line 94 of file vf_ssim.c.

Referenced by ssim_plane_16bit().

◆ ssim_4x4xn_8bit()

static void ssim_4x4xn_8bit ( const uint8_t *  main,
ptrdiff_t  main_stride,
const uint8_t *  ref,
ptrdiff_t  ref_stride,
int(*)  sums[4],
int  width 
)
static

Definition at line 130 of file vf_ssim.c.

Referenced by config_input_ref().

◆ ssim_end1x()

static float ssim_end1x ( int64_t  s1,
int64_t  s2,
int64_t  ss,
int64_t  s12,
int  max 
)
static

Definition at line 161 of file vf_ssim.c.

Referenced by ssim_endn_16bit().

◆ ssim_end1()

static float ssim_end1 ( int  s1,
int  s2,
int  ss,
int  s12 
)
static

Definition at line 177 of file vf_ssim.c.

Referenced by ssim_endn_8bit().

◆ ssim_endn_16bit()

static float ssim_endn_16bit ( const int64_t(*)  sum0[4],
const int64_t(*)  sum1[4],
int  width,
int  max 
)
static

Definition at line 193 of file vf_ssim.c.

Referenced by ssim_plane_16bit().

◆ ssim_endn_8bit()

static double ssim_endn_8bit ( const int(*)  sum0[4],
const int(*)  sum1[4],
int  width 
)
static

Definition at line 207 of file vf_ssim.c.

Referenced by config_input_ref().

◆ ssim_plane_16bit()

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

Definition at line 236 of file vf_ssim.c.

Referenced by config_input_ref().

◆ ssim_plane()

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

Definition at line 279 of file vf_ssim.c.

Referenced by config_input_ref().

◆ ssim_db()

static double ssim_db ( double  ssim,
double  weight 
)
static

Definition at line 322 of file vf_ssim.c.

Referenced by do_ssim(), and uninit().

◆ do_ssim()

static int do_ssim ( FFFrameSync fs)
static

Definition at line 327 of file vf_ssim.c.

Referenced by init().

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 398 of file vf_ssim.c.

◆ config_input_ref()

static int config_input_ref ( AVFilterLink inlink)
static

Definition at line 435 of file vf_ssim.c.

◆ config_output()

static int config_output ( AVFilterLink outlink)
static

Definition at line 497 of file vf_ssim.c.

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 527 of file vf_ssim.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 533 of file vf_ssim.c.

Variable Documentation

◆ ssim_options

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

Definition at line 73 of file vf_ssim.c.

◆ pix_fmts

enum AVPixelFormat pix_fmts[]
static

◆ ssim_inputs

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

Definition at line 564 of file vf_ssim.c.

◆ ssim_outputs

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

Definition at line 575 of file vf_ssim.c.

◆ ff_vf_ssim

const AVFilter ff_vf_ssim
Initial value:
= {
.name = "ssim",
.description = NULL_IF_CONFIG_SMALL("Calculate the SSIM between two video streams."),
.preinit = ssim_framesync_preinit,
.init = init,
.uninit = uninit,
.activate = activate,
.priv_size = sizeof(SSIMContext),
.priv_class = &ssim_class,
}

Definition at line 583 of file vf_ssim.c.

FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:174
activate
static int activate(AVFilterContext *ctx)
Definition: vf_ssim.c:527
config_input_ref
static int config_input_ref(AVFilterLink *inlink)
Definition: vf_ssim.c:435
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
FLAGS
#define FLAGS
Definition: vf_ssim.c:71
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:439
PF
#define PF(suf)
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:443
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:276
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
ssim_inputs
static const AVFilterPad ssim_inputs[]
Definition: vf_ssim.c:564
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:442
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:194
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:440
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
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:115
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_ssim.c:398
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_ssim.c:533
ssim_outputs
static const AVFilterPad ssim_outputs[]
Definition: vf_ssim.c:575
OFFSET
#define OFFSET(x)
Definition: vf_ssim.c:70
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_ssim.c:497
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_ssim.c:422
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
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:133
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
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:158
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:117
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:195
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
SSIMContext
Definition: vf_ssim.c:47
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:150
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
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:441