FFmpeg
Data Structures | Macros | Functions | Variables
vf_ssim.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 "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 71 of file vf_ssim.c.

◆ FLAGS

Definition at line 72 of file vf_ssim.c.

◆ SUM_LEN

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

Definition at line 219 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 82 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 95 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 131 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 162 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 178 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 194 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 235 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 278 of file vf_ssim.c.

Referenced by config_input_ref().

◆ ssim_db()

static double ssim_db ( double  ssim,
double  weight 
)
static

Definition at line 321 of file vf_ssim.c.

Referenced by do_ssim(), and uninit().

◆ do_ssim()

static int do_ssim ( FFFrameSync fs)
static

Definition at line 326 of file vf_ssim.c.

Referenced by init().

◆ init()

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 404 of file vf_ssim.c.

◆ config_input_ref()

static int config_input_ref ( AVFilterLink inlink)
static

Definition at line 439 of file vf_ssim.c.

◆ config_output()

static int config_output ( AVFilterLink outlink)
static

Definition at line 501 of file vf_ssim.c.

◆ activate()

static int activate ( AVFilterContext ctx)
static

Definition at line 533 of file vf_ssim.c.

◆ uninit()

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 539 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 74 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 569 of file vf_ssim.c.

◆ ssim_outputs

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

Definition at line 580 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 588 of file vf_ssim.c.

FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: filters.h:242
activate
static int activate(AVFilterContext *ctx)
Definition: vf_ssim.c:533
config_input_ref
static int config_input_ref(AVFilterLink *inlink)
Definition: vf_ssim.c:439
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
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
FLAGS
#define FLAGS
Definition: vf_ssim.c:72
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:482
PF
#define PF(suf)
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
ssim_inputs
static const AVFilterPad ssim_inputs[]
Definition: vf_ssim.c:569
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
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_ssim.c:404
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_ssim.c:539
ssim_outputs
static const AVFilterPad ssim_outputs[]
Definition: vf_ssim.c:580
OFFSET
#define OFFSET(x)
Definition: vf_ssim.c:71
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_ssim.c:501
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_ssim.c:426
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
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
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:165
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
SSIMContext
Definition: vf_ssim.c:48
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