shithub: libvpx

Download patch

ref: 9dadf3189ac6d0798f12bdf2ba2d2408b2825b1d
parent: b255d47775336f2bce6ce4c62a87ffcff7d9f2da
author: angiebird <angiebird@google.com>
date: Fri Oct 11 14:49:27 EDT 2019

Correct the num_frams of fps_init_first_pass_info

Note the last packet is cumulative first pass stats.
So the number of frames is packet number minus one

Change-Id: I5f617e7eeb63d17204beaaeb6422902ec076caeb

--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -2365,6 +2365,7 @@
         const int layer_id = (int)last_packet_for_layer->spatial_layer_id;
         const int packets_in_layer = (int)last_packet_for_layer->count + 1;
         if (layer_id >= 0 && layer_id < oxcf->ss_number_layers) {
+          int num_frames;
           LAYER_CONTEXT *const lc = &cpi->svc.layer_context[layer_id];
 
           vpx_free(lc->rc_twopass_stats_in.buf);
@@ -2376,9 +2377,11 @@
           lc->twopass.stats_in = lc->twopass.stats_in_start;
           lc->twopass.stats_in_end =
               lc->twopass.stats_in_start + packets_in_layer - 1;
+          // Note the last packet is cumulative first pass stats.
+          // So the number of frames is packet number minus one
+          num_frames = packets_in_layer - 1;
           fps_init_first_pass_info(&lc->twopass.first_pass_info,
-                                   lc->rc_twopass_stats_in.buf,
-                                   packets_in_layer);
+                                   lc->rc_twopass_stats_in.buf, num_frames);
           stats_copy[layer_id] = lc->rc_twopass_stats_in.buf;
         }
       }
@@ -2394,6 +2397,7 @@
 
       vp9_init_second_pass_spatial_svc(cpi);
     } else {
+      int num_frames;
 #if CONFIG_FP_MB_STATS
       if (cpi->use_fp_mb_stats) {
         const size_t psz = cpi->common.MBs * sizeof(uint8_t);
@@ -2410,8 +2414,11 @@
       cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf;
       cpi->twopass.stats_in = cpi->twopass.stats_in_start;
       cpi->twopass.stats_in_end = &cpi->twopass.stats_in[packets - 1];
+      // Note the last packet is cumulative first pass stats.
+      // So the number of frames is packet number minus one
+      num_frames = packets - 1;
       fps_init_first_pass_info(&cpi->twopass.first_pass_info,
-                               oxcf->two_pass_stats_in.buf, packets);
+                               oxcf->two_pass_stats_in.buf, num_frames);
 
       vp9_init_second_pass(cpi);
     }