Go to the documentation of this file.
72 #define OFFSET(x) offsetof(SSIMContext, x)
73 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
97 const uint8_t *ref8, ptrdiff_t ref_stride,
98 int64_t (*sums)[4],
int width)
100 const uint16_t *main16 = (
const uint16_t *)main8;
101 const uint16_t *ref16 = (
const uint16_t *)ref8;
107 for (z = 0; z <
width; z++) {
108 uint64_t
s1 = 0,
s2 = 0,
ss = 0, s12 = 0;
110 for (y = 0; y < 4; y++) {
111 for (
x = 0;
x < 4;
x++) {
112 unsigned a = main16[
x + y * main_stride];
113 unsigned b = ref16[
x + y * ref_stride];
134 int (*sums)[4],
int width)
138 for (z = 0; z <
width; z++) {
139 uint32_t
s1 = 0,
s2 = 0,
ss = 0, s12 = 0;
141 for (y = 0; y < 4; y++) {
142 for (
x = 0;
x < 4;
x++) {
143 int a =
main[
x + y * main_stride];
144 int b =
ref[
x + y * ref_stride];
165 int64_t ssim_c1 = (int64_t)(.01*.01*
max*
max*64 + .5);
166 int64_t ssim_c2 = (int64_t)(.03*.03*
max*
max*64*63 + .5);
172 int64_t
vars = fss * 64 - fs1 * fs1 - fs2 * fs2;
173 int64_t covar = fs12 * 64 - fs1 * fs2;
175 return (
float)(2 * fs1 * fs2 + ssim_c1) * (
float)(2 * covar + ssim_c2)
176 / ((
float)(fs1 * fs1 + fs2 * fs2 + ssim_c1) * (
float)(
vars + ssim_c2));
181 static const int ssim_c1 = (
int)(.01*.01*255*255*64 + .5);
182 static const int ssim_c2 = (
int)(.03*.03*255*255*64*63 + .5);
188 int vars = fss * 64 - fs1 * fs1 - fs2 * fs2;
189 int covar = fs12 * 64 - fs1 * fs2;
191 return (
float)(2 * fs1 * fs2 + ssim_c1) * (
float)(2 * covar + ssim_c2)
192 / ((
float)(fs1 * fs1 + fs2 * fs2 + ssim_c1) * (
float)(
vars + ssim_c2));
201 ssim +=
ssim_end1x(sum0[
i][0] + sum0[
i + 1][0] + sum1[
i][0] + sum1[
i + 1][0],
202 sum0[
i][1] + sum0[
i + 1][1] + sum1[
i][1] + sum1[
i + 1][1],
203 sum0[
i][2] + sum0[
i + 1][2] + sum1[
i][2] + sum1[
i + 1][2],
204 sum0[
i][3] + sum0[
i + 1][3] + sum1[
i][3] + sum1[
i + 1][3],
215 ssim +=
ssim_end1(sum0[
i][0] + sum0[
i + 1][0] + sum1[
i][0] + sum1[
i + 1][0],
216 sum0[
i][1] + sum0[
i + 1][1] + sum1[
i][1] + sum1[
i + 1][1],
217 sum0[
i][2] + sum0[
i + 1][2] + sum1[
i][2] + sum1[
i + 1][2],
218 sum0[
i][3] + sum0[
i + 1][3] + sum1[
i][3] + sum1[
i + 1][3]);
222 #define SUM_LEN(w) (((w) >> 2) + 3)
232 int64_t (*sum0)[4] =
temp;
238 for (y = 1; y <
height; y++) {
239 for (; z <= y; z++) {
240 FFSWAP(
void*, sum0, sum1);
242 &
ref[4 * z * ref_stride], ref_stride,
266 for (y = 1; y <
height; y++) {
267 for (; z <= y; z++) {
268 FFSWAP(
void*, sum0, sum1);
270 &
ref[4 * z * ref_stride], ref_stride,
274 ssim += dsp->
ssim_end_line((
const int (*)[4])sum0, (
const int (*)[4])sum1,
width - 1);
291 double c[4] = { 0 }, ssimv = 0.0;
299 metadata = &
master->metadata;
303 for (
i = 0;
i <
s->nb_components;
i++) {
306 s->planewidth[
i],
s->planeheight[
i],
s->temp,
308 ssimv +=
s->coefs[
i] *
c[
i];
311 for (
i = 0;
i <
s->nb_components;
i++) {
312 int cidx =
s->is_rgb ?
s->rgba_map[
i] :
i;
313 set_meta(metadata,
"lavfi.ssim.",
s->comps[
i],
c[cidx]);
315 s->ssim_total += ssimv;
317 set_meta(metadata,
"lavfi.ssim.All", 0, ssimv);
321 fprintf(
s->stats_file,
"n:%"PRId64
" ",
s->nb_frames);
323 for (
i = 0;
i <
s->nb_components;
i++) {
324 int cidx =
s->is_rgb ?
s->rgba_map[
i] :
i;
325 fprintf(
s->stats_file,
"%c:%f ",
s->comps[
i],
c[cidx]);
328 fprintf(
s->stats_file,
"All:%f (%f)\n", ssimv,
ssim_db(ssimv, 1.0));
338 if (
s->stats_file_str) {
339 if (!strcmp(
s->stats_file_str,
"-")) {
340 s->stats_file = stdout;
342 s->stats_file = fopen(
s->stats_file_str,
"w");
343 if (!
s->stats_file) {
348 s->stats_file_str, buf);
368 #define PF(suf) AV_PIX_FMT_YUV420##suf, AV_PIX_FMT_YUV422##suf, AV_PIX_FMT_YUV444##suf, AV_PIX_FMT_GBR##suf
386 s->nb_components =
desc->nb_components;
388 if (
ctx->inputs[0]->w !=
ctx->inputs[1]->w ||
389 ctx->inputs[0]->h !=
ctx->inputs[1]->h) {
393 if (
ctx->inputs[0]->format !=
ctx->inputs[1]->format) {
399 s->comps[0] =
s->is_rgb ?
'R' :
'Y';
400 s->comps[1] =
s->is_rgb ?
'G' :
'U';
401 s->comps[2] =
s->is_rgb ?
'B' :
'V';
405 s->planeheight[0] =
s->planeheight[3] =
inlink->h;
407 s->planewidth[0] =
s->planewidth[3] =
inlink->w;
408 for (
i = 0;
i <
s->nb_components;
i++)
409 sum +=
s->planeheight[
i] *
s->planewidth[
i];
410 for (
i = 0;
i <
s->nb_components;
i++)
411 s->coefs[
i] = (
double)
s->planeheight[
i] *
s->planewidth[
i] / sum;
416 s->max = (1 <<
desc->comp[0].depth) - 1;
437 outlink->
w = mainlink->
w;
438 outlink->
h = mainlink->
h;
450 av_log(
ctx,
AV_LOG_WARNING,
"not matching timebases found between first input: %d/%d and second input %d/%d, results may be incorrect!\n",
452 ctx->inputs[1]->time_base.num,
ctx->inputs[1]->time_base.den);
467 if (
s->nb_frames > 0) {
471 for (
i = 0;
i <
s->nb_components;
i++) {
472 int c =
s->is_rgb ?
s->rgba_map[
i] :
i;
473 av_strlcatf(buf,
sizeof(buf),
" %c:%f (%f)",
s->comps[
i],
s->ssim[
c] /
s->nb_frames,
477 s->ssim_total /
s->nb_frames,
ssim_db(
s->ssim_total,
s->nb_frames));
482 if (
s->stats_file &&
s->stats_file != stdout)
483 fclose(
s->stats_file);
512 .preinit = ssim_framesync_preinit,
518 .priv_class = &ssim_class,
static double ssim_plane(SSIMDSPContext *dsp, uint8_t *main, int main_stride, uint8_t *ref, int ref_stride, int width, int height, void *temp, int max)
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
#define AV_LOG_WARNING
Something somehow does not look correct.
void ff_ssim_init_x86(SSIMDSPContext *dsp)
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
#define FFSWAP(type, a, b)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
static float ssim_end1x(int64_t s1, int64_t s2, int64_t ss, int64_t s12, int max)
static int activate(AVFilterContext *ctx)
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
static int config_input_ref(AVFilterLink *inlink)
This structure describes decoded (raw) audio or video data.
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
A link between two filters.
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
static int query_formats(AVFilterContext *ctx)
static const AVOption ssim_options[]
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass ‘ target exec’ to ‘configure’ or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script ‘tests fate sh’ from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at ‘doc fate_config sh template’ Create a configuration that suits your based on the configuration template The ‘slot’ configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern ‘ARCH OS COMPILER COMPILER VERSION’ The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the ‘fate_recv’ variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration it may help to try out the ‘ssh’ command with one or more ‘ v’ options You should get detailed output concerning your SSH configuration and the authentication process The only thing left is to automate the execution of the fate sh script and the synchronisation of the samples directory Uploading new samples to the fate suite *****************************************If you need a sample uploaded send a mail to samples request This is for developers who have an account on the fate suite server If you upload new please make sure they are as small as space on each network bandwidth and so on benefit from smaller test cases Also keep in mind older checkouts use existing sample that means in practice generally do not remove or overwrite files as it likely would break older checkouts or releases Also all needed samples for a commit should be ideally before the push If you need an account for frequently uploading samples or you wish to help others by doing that send a mail to ffmpeg devel rsync vauL Duo x
#define AV_PIX_FMT_GRAY16
#define ss(width, name, subs,...)
A filter pad used for either input or output.
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
static float ssim_endn_16bit(const int64_t(*sum0)[4], const int64_t(*sum1)[4], int width, int max)
void(* ssim_4x4_line)(const uint8_t *buf, ptrdiff_t buf_stride, const uint8_t *ref, ptrdiff_t ref_stride, int(*sums)[4], int w)
static double ssim_endn_8bit(const int(*sum0)[4], const int(*sum1)[4], int width)
#define AV_CEIL_RSHIFT(a, b)
static const AVFilterPad ssim_inputs[]
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
static const AVFilterPad outputs[]
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
static enum AVPixelFormat pix_fmts[]
#define AV_PIX_FMT_GRAY14
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
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)
#define AV_PIX_FMT_GRAY10
int main(int argc, char *argv[])
Describe the class of an AVClass context structure.
#define fs(width, name, subs,...)
static const uint8_t vars[2][12]
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
FRAMESYNC_DEFINE_CLASS(ssim, SSIMContext, fs)
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static int weight(int i, int blen, int offset)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
static double ssim_db(double ssim, double weight)
static av_cold int init(AVFilterContext *ctx)
static double ssim_plane_16bit(SSIMDSPContext *dsp, uint8_t *main, int main_stride, uint8_t *ref, int ref_stride, int width, int height, void *temp, int max)
AVFilterContext * src
source filter
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
#define AV_LOG_INFO
Standard information.
static av_cold void uninit(AVFilterContext *ctx)
static const AVFilterPad ssim_outputs[]
static int do_ssim(FFFrameSync *fs)
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 float ssim_end1(int s1, int s2, int ss, int s12)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
double(* ssim_end_line)(const int(*sum0)[4], const int(*sum1)[4], int w)
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 default value
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
const char * name
Pad name.
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
static int config_output(AVFilterLink *outlink)
int h
agreed upon image height
static int ref[MAX_W *MAX_W]
static void set_meta(AVDictionary **metadata, const char *key, char comp, float d)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
int ff_fill_rgba_map(uint8_t *rgba_map, enum AVPixelFormat pix_fmt)
double(* ssim_plane)(SSIMDSPContext *dsp, uint8_t *main, int main_stride, uint8_t *ref, int ref_stride, int width, int height, void *temp, int max)
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
int ff_framesync_dualinput_get(FFFrameSync *fs, AVFrame **f0, AVFrame **f1)
#define AV_PIX_FMT_GRAY12