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

avfilter: Add new format for PSNR stats log

Add an AVOption stats_version with a new header for V2 stats, which
specifies the stats log version and lists the fields that will be
present in the log (to ease parsing).

The primary motivation is to facilitate the addition of optional fields
to the log without breaking backwards compatibility, while making the
logs easier to parse.
Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent 0219dc6c
...@@ -43,6 +43,8 @@ typedef struct PSNRContext { ...@@ -43,6 +43,8 @@ typedef struct PSNRContext {
uint64_t nb_frames; uint64_t nb_frames;
FILE *stats_file; FILE *stats_file;
char *stats_file_str; char *stats_file_str;
int stats_version;
int stats_header_written;
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];
...@@ -60,6 +62,7 @@ typedef struct PSNRContext { ...@@ -60,6 +62,7 @@ typedef struct PSNRContext {
static const AVOption psnr_options[] = { 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 },
{ NULL } { NULL }
}; };
...@@ -169,6 +172,19 @@ static AVFrame *do_psnr(AVFilterContext *ctx, AVFrame *main, ...@@ -169,6 +172,19 @@ static AVFrame *do_psnr(AVFilterContext *ctx, AVFrame *main,
set_meta(metadata, "lavfi.psnr.psnr_avg", 0, get_psnr(mse, 1, s->average_max)); set_meta(metadata, "lavfi.psnr.psnr_avg", 0, get_psnr(mse, 1, s->average_max));
if (s->stats_file) { if (s->stats_file) {
if (s->stats_version == 2 && !s->stats_header_written) {
fprintf(s->stats_file, "psnr_log_version:2 fields:n");
fprintf(s->stats_file, ",mse_avg");
for (j = 0; j < s->nb_components; j++) {
fprintf(s->stats_file, ",mse_%c", s->comps[j]);
}
fprintf(s->stats_file, ",psnr_avg");
for (j = 0; j < s->nb_components; j++) {
fprintf(s->stats_file, ",psnr_%c", s->comps[j]);
}
fprintf(s->stats_file, "\n");
s->stats_header_written = 1;
}
fprintf(s->stats_file, "n:%"PRId64" mse_avg:%0.2f ", s->nb_frames, mse); fprintf(s->stats_file, "n:%"PRId64" mse_avg:%0.2f ", s->nb_frames, mse);
for (j = 0; j < s->nb_components; j++) { for (j = 0; j < s->nb_components; j++) {
c = s->is_rgb ? s->rgba_map[j] : j; c = s->is_rgb ? s->rgba_map[j] : j;
......
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