[FFmpeg-devel] [PATCH] avfilter: Add new format for PSNR stats log
Lucas Cooper
bobobo at google.com
Mon Jul 25 21:54:37 EEST 2016
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.
---
libavfilter/vf_psnr.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/libavfilter/vf_psnr.c b/libavfilter/vf_psnr.c
index 89acd3c..999f14d 100644
--- a/libavfilter/vf_psnr.c
+++ b/libavfilter/vf_psnr.c
@@ -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;
--
2.8.0.rc3.226.g39d4020
More information about the ffmpeg-devel
mailing list