[FFmpeg-devel] [PATCH] libavfilter: created a new filter that obtains the average peak signal-to-noise ratio (PSNR) of two input video files in YUV format.

Mark Himsley mark at mdsh.com
Tue Jun 7 18:16:42 CEST 2011


On 07/06/11 13:03, Roger Pau Monné wrote:
[...]
> +static void end_frame(AVFilterLink *inlink)
> +{
> +    AVFilterContext *ctx = inlink->dst;
> +    PSNRContext *psnr = ctx->priv;
> +    AVFilterLink *outlink = ctx->outputs[0];
> +    AVFilterBufferRef *outpic = outlink->out_buf;
> +    AVFilterBufferRef *ref = psnr->picref;
> +    double mse[4];
> +    double mse_t = 0;
> +    int j;
> +
> +    if (psnr->picref) {
> +        compute_images_mse((const uint8_t **)outpic->data, (const uint8_t **)ref->data,
> +                           outpic->linesize, outpic->video->w, outpic->video->h,
> +&av_pix_fmt_descriptors[inlink->format], mse,
> +                           psnr->line1, psnr->line2);
> +
> +        for (j = 0; j<  av_pix_fmt_descriptors[inlink->format].nb_components; j++)
> +            mse_t += mse[j];
> +        mse_t /= av_pix_fmt_descriptors[inlink->format].nb_components;
> +
> +        if (psnr->min_mse == -1) {
> +            psnr->min_mse = mse_t;
> +            psnr->max_mse = mse_t;
> +        }
> +        if (psnr->min_mse>  mse_t)
> +            psnr->min_mse = mse_t;
> +        if (psnr->max_mse<  mse_t)
> +            psnr->max_mse = mse_t;
> +
> +        psnr->mse += mse_t;
> +        psnr->nb_frames++;
> +
> +        if (psnr->vstats_file) {
> +            if(psnr->is_yuv)
> +                fprintf(psnr->vstats_file,
> +                        "Frame:%d Y:%0.2fdB Cb:%0.2fdB Cr:%0.2fdB PSNR:%0.2fdB\n",
> +                        psnr->nb_frames,
> +                        get_psnr(mse[0], 1, psnr->max[0]),
> +                        get_psnr(mse[1], 1, psnr->max[1]),
> +                        get_psnr(mse[2], 1, psnr->max[2]),
> +                        get_psnr(mse_t, 1, psnr->average_max));
> +            if(psnr->is_rgb) {
> +                fprintf(psnr->vstats_file,
> +                        "Frame:%d R:%0.2fdB G:%0.2fdB B:%0.2fdB ",
> +                        psnr->nb_frames,
> +                        get_psnr(mse[0], 1, psnr->max[0]),
> +                        get_psnr(mse[1], 1, psnr->max[1]),
> +                        get_psnr(mse[2], 1, psnr->max[2]));
> +                if(av_pix_fmt_descriptors[inlink->format].nb_components>  3)
> +                    fprintf(psnr->vstats_file,
> +                            "A:%0.2fdB ",
> +                            get_psnr(mse[3], 1, psnr->max[3]));
> +                fprintf(psnr->vstats_file,
> +                        "PSNR:%0.2fdB\n",
> +                        get_psnr(mse_t, 1, psnr->average_max));
> +            }
> +        }
> +    }

Would it be possible to output as a csv, similar to qpsnr, so it could 
be quickly imported into a spreadsheet and a graph drawn without the 
need to pre-process your output file ?

[...]

-- 
Mark


More information about the ffmpeg-devel mailing list