From a981cb2809e14cde251e212d388148bcdc89a79b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Peter=20Bostr=C3=B6m?= Date: Fri, 13 Jan 2017 07:56:43 -0500 Subject: [PATCH] Add CSV per-frame stats to vpxdec. Used with --framestats=file.csv. Currently prints raw codec QP (not internal 0-63 range) and bytes per frame. Change-Id: Ifbb90129c218dda869eaf5b810bad12a32ebd82d --- vpxdec.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/vpxdec.c b/vpxdec.c index 2cdb69d5a..cb5c1b2a0 100644 --- a/vpxdec.c +++ b/vpxdec.c @@ -94,16 +94,21 @@ static const arg_def_t outbitdeptharg = #endif static const arg_def_t svcdecodingarg = ARG_DEF( NULL, "svc-decode-layer", 1, "Decode SVC stream up to given spatial layer"); +static const arg_def_t framestatsarg = + ARG_DEF(NULL, "framestats", 1, "Output per-frame stats (.csv format)"); static const arg_def_t *all_args[] = { - &codecarg, &use_yv12, &use_i420, &flipuvarg, &rawvideo, - &noblitarg, &progressarg, &limitarg, &skiparg, &postprocarg, - &summaryarg, &outputfile, &threadsarg, &frameparallelarg, &verbosearg, - &scalearg, &fb_arg, &md5arg, &error_concealment, &continuearg, + &codecarg, &use_yv12, &use_i420, + &flipuvarg, &rawvideo, &noblitarg, + &progressarg, &limitarg, &skiparg, + &postprocarg, &summaryarg, &outputfile, + &threadsarg, &frameparallelarg, &verbosearg, + &scalearg, &fb_arg, &md5arg, + &error_concealment, &continuearg, #if CONFIG_VP9_HIGHBITDEPTH &outbitdeptharg, #endif - &svcdecodingarg, NULL + &svcdecodingarg, &framestatsarg, NULL }; #if CONFIG_VP8_DECODER @@ -527,6 +532,8 @@ static int main_loop(int argc, const char **argv_) { char outfile_name[PATH_MAX] = { 0 }; FILE *outfile = NULL; + FILE *framestats_file = NULL; + MD5Context md5_ctx; unsigned char md5_digest[16]; @@ -603,6 +610,12 @@ static int main_loop(int argc, const char **argv_) { else if (arg_match(&arg, &svcdecodingarg, argi)) { svc_decoding = 1; svc_spatial_layer = arg_parse_uint(&arg); + } else if (arg_match(&arg, &framestatsarg, argi)) { + framestats_file = fopen(arg.val, "w"); + if (!framestats_file) { + die("Error: Could not open --framestats file (%s) for writing.\n", + arg.val); + } } #if CONFIG_VP8_DECODER else if (arg_match(&arg, &addnoise_level, argi)) { @@ -761,6 +774,8 @@ static int main_loop(int argc, const char **argv_) { frame_avail = 1; got_data = 0; + if (framestats_file) fprintf(framestats_file, "bytes,qp\n"); + /* Decode file */ while (frame_avail || got_data) { vpx_codec_iter_t iter = NULL; @@ -786,6 +801,16 @@ static int main_loop(int argc, const char **argv_) { if (!keep_going) goto fail; } + if (framestats_file) { + int qp; + if (vpx_codec_control(&decoder, VPXD_GET_LAST_QUANTIZER, &qp)) { + warn("Failed VPXD_GET_LAST_QUANTIZER: %s", + vpx_codec_error(&decoder)); + if (!keep_going) goto fail; + } + fprintf(framestats_file, "%d,%d\n", (int)bytes_in_buffer, qp); + } + vpx_usec_timer_mark(&timer); dx_time += vpx_usec_timer_elapsed(&timer); } else { @@ -1018,6 +1043,8 @@ fail2: free(ext_fb_list.ext_fb); fclose(infile); + if (framestats_file) fclose(framestats_file); + free(argv); return ret; -- 2.40.0