Go to the documentation of this file.
   60 #define OFFSET(x) offsetof(PSNRContext, x) 
   61 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM 
   66     {
"stats_version", 
"Set the format version for the stats file.",               
OFFSET(stats_version),  
AV_OPT_TYPE_INT,    {.i64=1},    1, 2, 
FLAGS },
 
   78 static inline double get_psnr(
double mse, uint64_t nb_frames, 
int max)
 
   80     return 10.0 * log10(
pow_2(
max) / (mse / nb_frames));
 
   88     for (j = 0; j < outw; j++)
 
   89         m2 += 
pow_2(main_line[j] - ref_line[j]);
 
   98     const uint16_t *main_line = (
const uint16_t *) _main_line;
 
   99     const uint16_t *ref_line = (
const uint16_t *) _ref_line;
 
  101     for (j = 0; j < outw; j++)
 
  102         m2 += 
pow_2(main_line[j] - ref_line[j]);
 
  109                         const uint8_t *main_data[4], 
const int main_linesizes[4],
 
  110                         const uint8_t *ref_data[4], 
const int ref_linesizes[4],
 
  111                         int w, 
int h, 
double mse[4])
 
  115     for (
c = 0; 
c < 
s->nb_components; 
c++) {
 
  116         const int outw = 
s->planewidth[
c];
 
  117         const int outh = 
s->planeheight[
c];
 
  118         const uint8_t *main_line = main_data[
c];
 
  119         const uint8_t *ref_line = ref_data[
c];
 
  120         const int ref_linesize = ref_linesizes[
c];
 
  121         const int main_linesize = main_linesizes[
c];
 
  123         for (
i = 0; 
i < outh; 
i++) {
 
  124             m += 
s->dsp.sse_line(main_line, ref_line, outw);
 
  125             ref_line += ref_linesize;
 
  126             main_line += main_linesize;
 
  128         mse[
c] = m / (double)(outw * outh);
 
  150     double comp_mse[4], mse = 0;
 
  159     metadata = &
master->metadata;
 
  165     for (j = 0; j < 
s->nb_components; j++)
 
  166         mse += comp_mse[j] * 
s->planeweight[j];
 
  168     s->min_mse = 
FFMIN(
s->min_mse, mse);
 
  169     s->max_mse = 
FFMAX(
s->max_mse, mse);
 
  172     for (j = 0; j < 
s->nb_components; j++)
 
  173         s->mse_comp[j] += comp_mse[j];
 
  176     for (j = 0; j < 
s->nb_components; j++) {
 
  177         c = 
s->is_rgb ? 
s->rgba_map[j] : j;
 
  178         set_meta(metadata, 
"lavfi.psnr.mse.", 
s->comps[j], comp_mse[
c]);
 
  181     set_meta(metadata, 
"lavfi.psnr.mse_avg", 0, mse);
 
  185         if (
s->stats_version == 2 && !
s->stats_header_written) {
 
  186             fprintf(
s->stats_file, 
"psnr_log_version:2 fields:n");
 
  187             fprintf(
s->stats_file, 
",mse_avg");
 
  188             for (j = 0; j < 
s->nb_components; j++) {
 
  189                 fprintf(
s->stats_file, 
",mse_%c", 
s->comps[j]);
 
  191             fprintf(
s->stats_file, 
",psnr_avg");
 
  192             for (j = 0; j < 
s->nb_components; j++) {
 
  193                 fprintf(
s->stats_file, 
",psnr_%c", 
s->comps[j]);
 
  195             if (
s->stats_add_max) {
 
  196                 fprintf(
s->stats_file, 
",max_avg");
 
  197                 for (j = 0; j < 
s->nb_components; j++) {
 
  198                     fprintf(
s->stats_file, 
",max_%c", 
s->comps[j]);
 
  201             fprintf(
s->stats_file, 
"\n");
 
  202             s->stats_header_written = 1;
 
  204         fprintf(
s->stats_file, 
"n:%"PRId64
" mse_avg:%0.2f ", 
s->nb_frames, mse);
 
  205         for (j = 0; j < 
s->nb_components; j++) {
 
  206             c = 
s->is_rgb ? 
s->rgba_map[j] : j;
 
  207             fprintf(
s->stats_file, 
"mse_%c:%0.2f ", 
s->comps[j], comp_mse[
c]);
 
  209         fprintf(
s->stats_file, 
"psnr_avg:%0.2f ", 
get_psnr(mse, 1, 
s->average_max));
 
  210         for (j = 0; j < 
s->nb_components; j++) {
 
  211             c = 
s->is_rgb ? 
s->rgba_map[j] : j;
 
  212             fprintf(
s->stats_file, 
"psnr_%c:%0.2f ", 
s->comps[j],
 
  215         if (
s->stats_version == 2 && 
s->stats_add_max) {
 
  216             fprintf(
s->stats_file, 
"max_avg:%d ", 
s->average_max);
 
  217             for (j = 0; j < 
s->nb_components; j++) {
 
  218                 c = 
s->is_rgb ? 
s->rgba_map[j] : j;
 
  219                 fprintf(
s->stats_file, 
"max_%c:%d ", 
s->comps[j], 
s->max[
c]);
 
  222         fprintf(
s->stats_file, 
"\n");
 
  235     if (
s->stats_file_str) {
 
  236         if (
s->stats_version < 2 && 
s->stats_add_max) {
 
  238                 "stats_add_max was specified but stats_version < 2.\n" );
 
  241         if (!strcmp(
s->stats_file_str, 
"-")) {
 
  242             s->stats_file = stdout;
 
  244             s->stats_file = fopen(
s->stats_file_str, 
"w");
 
  245             if (!
s->stats_file) {
 
  250                        s->stats_file_str, buf);
 
  264 #define PF_NOALPHA(suf) AV_PIX_FMT_YUV420##suf,  AV_PIX_FMT_YUV422##suf,  AV_PIX_FMT_YUV444##suf 
  265 #define PF_ALPHA(suf)   AV_PIX_FMT_YUVA420##suf, AV_PIX_FMT_YUVA422##suf, AV_PIX_FMT_YUVA444##suf 
  266 #define PF(suf)         PF_NOALPHA(suf), PF_ALPHA(suf) 
  292     s->nb_components = 
desc->nb_components;
 
  293     if (
ctx->inputs[0]->w != 
ctx->inputs[1]->w ||
 
  294         ctx->inputs[0]->h != 
ctx->inputs[1]->h) {
 
  298     if (
ctx->inputs[0]->format != 
ctx->inputs[1]->format) {
 
  303     s->max[0] = (1 << 
desc->comp[0].depth) - 1;
 
  304     s->max[1] = (1 << 
desc->comp[1].depth) - 1;
 
  305     s->max[2] = (1 << 
desc->comp[2].depth) - 1;
 
  306     s->max[3] = (1 << 
desc->comp[3].depth) - 1;
 
  309     s->comps[0] = 
s->is_rgb ? 
'r' : 
'y' ;
 
  310     s->comps[1] = 
s->is_rgb ? 
'g' : 
'u' ;
 
  311     s->comps[2] = 
s->is_rgb ? 
'b' : 
'v' ;
 
  315     s->planeheight[0] = 
s->planeheight[3] = 
inlink->h;
 
  317     s->planewidth[0]  = 
s->planewidth[3]  = 
inlink->w;
 
  319     for (j = 0; j < 
s->nb_components; j++)
 
  320         sum += 
s->planeheight[j] * 
s->planewidth[j];
 
  322     for (j = 0; j < 
s->nb_components; j++) {
 
  323         s->planeweight[j] = (double) 
s->planeheight[j] * 
s->planewidth[j] / sum;
 
  324         average_max += 
s->max[j] * 
s->planeweight[j];
 
  326     s->average_max = 
lrint(average_max);
 
  345     outlink->
w = mainlink->
w;
 
  346     outlink->
h = mainlink->
h;
 
  357         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",
 
  359                ctx->inputs[1]->time_base.num, 
ctx->inputs[1]->time_base.den);
 
  374     if (
s->nb_frames > 0) {
 
  379         for (j = 0; j < 
s->nb_components; j++) {
 
  380             int c = 
s->is_rgb ? 
s->rgba_map[j] : j;
 
  393     if (
s->stats_file && 
s->stats_file != stdout)
 
  394         fclose(
s->stats_file);
 
  421     .preinit       = psnr_framesync_preinit,
 
  427     .priv_class    = &psnr_class,
 
  
#define AV_PIX_FMT_GBRAP16
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
#define AV_LOG_WARNING
Something somehow does not look correct.
static int config_input_ref(AVFilterLink *inlink)
AVPixelFormat
Pixel format.
static double psnr(double d)
static int do_psnr(FFFrameSync *fs)
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
static void set_meta(AVDictionary **metadata, const char *key, char comp, float d)
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
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)
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
This structure describes decoded (raw) audio or video data.
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
static av_cold int init(AVFilterContext *ctx)
A link between two filters.
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
void ff_psnr_init_x86(PSNRDSPContext *dsp, int bpp)
static const AVFilterPad psnr_inputs[]
static void compute_images_mse(PSNRContext *s, const uint8_t *main_data[4], const int main_linesizes[4], const uint8_t *ref_data[4], const int ref_linesizes[4], int w, int h, double mse[4])
#define AV_PIX_FMT_GBRP14
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GRAY16
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...
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP12
#define AV_CEIL_RSHIFT(a, b)
FRAMESYNC_DEFINE_CLASS(psnr, PSNRContext, fs)
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_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GBRP16
static int query_formats(AVFilterContext *ctx)
Describe the class of an AVClass context structure.
#define fs(width, name, subs,...)
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static const AVOption psnr_options[]
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 uint64_t sse_line_8bit(const uint8_t *main_line, const uint8_t *ref_line, int outw)
static uint64_t sse_line_16bit(const uint8_t *_main_line, const uint8_t *_ref_line, int outw)
static const AVFilterPad psnr_outputs[]
#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 unsigned pow_2(unsigned base)
static av_cold void uninit(AVFilterContext *ctx)
AVFilterContext * src
source filter
#define AV_LOG_INFO
Standard information.
#define i(width, name, range_min, range_max)
int w
agreed upon image width
#define AV_PIX_FMT_GBRP12
static int config_output(AVFilterLink *outlink)
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 double get_psnr(double mse, uint64_t nb_frames, int max)
int h
agreed upon image height
static int ref[MAX_W *MAX_W]
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
static int activate(AVFilterContext *ctx)
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
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)
@ 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