Commit aabe12eb authored by Lucas Cooper's avatar Lucas Cooper Committed by Michael Niedermayer

avfilter/vf_psnr: Add max value output option to psnr stats log.

This allows retroactive calculation/aggregation of PSNR from the stats
log.
Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent 2b1d316f
...@@ -10832,6 +10832,12 @@ standard output. ...@@ -10832,6 +10832,12 @@ standard output.
Specifies which version of the stats file format to use. Details of Specifies which version of the stats file format to use. Details of
each format are written below. each format are written below.
Default value is 1. Default value is 1.
@item stats_add_max
Determines whether the max value is output to the stats log.
Default value is 0.
Requires stats_version >= 2. If this is set and stats_version < 2,
the filter will return an error.
@end table @end table
The file printed if @var{stats_file} is selected, contains a sequence of The file printed if @var{stats_file} is selected, contains a sequence of
...@@ -10868,6 +10874,10 @@ frames for the component specified by the suffix. ...@@ -10868,6 +10874,10 @@ frames for the component specified by the suffix.
@item psnr_y, psnr_u, psnr_v, psnr_r, psnr_g, psnr_b, psnr_a @item psnr_y, psnr_u, psnr_v, psnr_r, psnr_g, psnr_b, psnr_a
Peak Signal to Noise ratio of the compared frames for the component Peak Signal to Noise ratio of the compared frames for the component
specified by the suffix. specified by the suffix.
@item max_avg, max_y, max_u, max_v
Maximum allowed value for each channel, and average over all
channels.
@end table @end table
For example: For example:
......
...@@ -45,6 +45,7 @@ typedef struct PSNRContext { ...@@ -45,6 +45,7 @@ typedef struct PSNRContext {
char *stats_file_str; char *stats_file_str;
int stats_version; int stats_version;
int stats_header_written; int stats_header_written;
int stats_add_max;
int max[4], average_max; int max[4], average_max;
int is_rgb; int is_rgb;
uint8_t rgba_map[4]; uint8_t rgba_map[4];
...@@ -63,6 +64,7 @@ static const AVOption psnr_options[] = { ...@@ -63,6 +64,7 @@ static const AVOption psnr_options[] = {
{"stats_file", "Set file where to store per-frame difference information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS }, {"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 }, {"f", "Set file where to store per-frame difference information", OFFSET(stats_file_str), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, FLAGS },
{"stats_version", "Set the format version for the stats file.", OFFSET(stats_version), AV_OPT_TYPE_INT, {.i64=1}, 1, 2, FLAGS }, {"stats_version", "Set the format version for the stats file.", OFFSET(stats_version), AV_OPT_TYPE_INT, {.i64=1}, 1, 2, FLAGS },
{"output_max", "Add raw stats (max values) to the output log.", OFFSET(stats_add_max), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS},
{ NULL } { NULL }
}; };
...@@ -182,6 +184,12 @@ static AVFrame *do_psnr(AVFilterContext *ctx, AVFrame *main, ...@@ -182,6 +184,12 @@ static AVFrame *do_psnr(AVFilterContext *ctx, AVFrame *main,
for (j = 0; j < s->nb_components; j++) { for (j = 0; j < s->nb_components; j++) {
fprintf(s->stats_file, ",psnr_%c", s->comps[j]); fprintf(s->stats_file, ",psnr_%c", s->comps[j]);
} }
if (s->stats_add_max) {
fprintf(s->stats_file, ",max_avg");
for (j = 0; j < s->nb_components; j++) {
fprintf(s->stats_file, ",max_%c", s->comps[j]);
}
}
fprintf(s->stats_file, "\n"); fprintf(s->stats_file, "\n");
s->stats_header_written = 1; s->stats_header_written = 1;
} }
...@@ -196,6 +204,13 @@ static AVFrame *do_psnr(AVFilterContext *ctx, AVFrame *main, ...@@ -196,6 +204,13 @@ static AVFrame *do_psnr(AVFilterContext *ctx, AVFrame *main,
fprintf(s->stats_file, "psnr_%c:%0.2f ", s->comps[j], fprintf(s->stats_file, "psnr_%c:%0.2f ", s->comps[j],
get_psnr(comp_mse[c], 1, s->max[c])); get_psnr(comp_mse[c], 1, s->max[c]));
} }
if (s->stats_version == 2 && s->stats_add_max) {
fprintf(s->stats_file, "max_avg:%d ", s->average_max);
for (j = 0; j < s->nb_components; j++) {
c = s->is_rgb ? s->rgba_map[j] : j;
fprintf(s->stats_file, "max_%c:%d ", s->comps[j], s->max[c]);
}
}
fprintf(s->stats_file, "\n"); fprintf(s->stats_file, "\n");
} }
...@@ -210,6 +225,11 @@ static av_cold int init(AVFilterContext *ctx) ...@@ -210,6 +225,11 @@ static av_cold int init(AVFilterContext *ctx)
s->max_mse = -INFINITY; s->max_mse = -INFINITY;
if (s->stats_file_str) { if (s->stats_file_str) {
if (s->stats_version < 2 && s->stats_add_max) {
av_log(ctx, AV_LOG_ERROR,
"stats_add_max was specified but stats_version < 2.\n" );
return AVERROR(EINVAL);
}
if (!strcmp(s->stats_file_str, "-")) { if (!strcmp(s->stats_file_str, "-")) {
s->stats_file = stdout; s->stats_file = stdout;
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment