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: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
Lucas Cooper 2016-07-25 11:54:37 -07:00 committed by Michael Niedermayer
parent 0219dc6c07
commit bc9ce5f6be
1 changed files with 16 additions and 0 deletions

View File

@ -43,6 +43,8 @@ typedef struct PSNRContext {
uint64_t nb_frames;
FILE *stats_file;
char *stats_file_str;
int stats_version;
int stats_header_written;
int max[4], average_max;
int is_rgb;
uint8_t rgba_map[4];
@ -60,6 +62,7 @@ typedef struct PSNRContext {
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 },
{"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 }
};
@ -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));
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);
for (j = 0; j < s->nb_components; j++) {
c = s->is_rgb ? s->rgba_map[j] : j;