shithub: libvpx

Download patch

ref: 1d6f9305175ea1ad902a49ef527f11a46902de7d
parent: 4127799a91445b475cb66e5c7c17a46a2c567081
author: Jerome Jiang <jianj@google.com>
date: Fri Mar 30 10:15:06 EDT 2018

VP9 SVC: Write bitstream for each spatial layer in sample.

Added control for denoiser in the sample SVC encoder.

Change-Id: I8e62aa2fc13a943eb110cb33e419e912a898bbc7

--- a/examples/vp9_spatial_svc_encoder.c
+++ b/examples/vp9_spatial_svc_encoder.c
@@ -632,7 +632,7 @@
   int end_of_stream = 0;
   int frames_received = 0;
 #if OUTPUT_RC_STATS
-  VpxVideoWriter *outfile[VPX_TS_MAX_LAYERS] = { NULL };
+  VpxVideoWriter *outfile[VPX_SS_MAX_LAYERS] = { NULL };
   struct RateControlStats rc;
   vpx_svc_layer_id_t layer_id;
   vpx_svc_ref_frame_config_t ref_frame_config;
@@ -644,6 +644,8 @@
   struct vpx_usec_timer timer;
   int64_t cx_time = 0;
   memset(&svc_ctx, 0, sizeof(svc_ctx));
+  memset(&app_input, 0, sizeof(AppInput));
+  memset(&info, 0, sizeof(VpxVideoInfo));
   exec_name = argv[0];
   parse_command_line(argc, argv, &app_input, &svc_ctx, &enc_cfg);
 
@@ -692,16 +694,16 @@
       die("Failed to open %s for writing\n", app_input.output_filename);
   }
 #if OUTPUT_RC_STATS
-  // For now, just write temporal layer streams.
-  // TODO(marpan): do spatial by re-writing superframe.
+  // Write out spatial layer stream.
+  // TODO(marpan/jianj): allow for writing each spatial and temporal stream.
   if (svc_ctx.output_rc_stat) {
-    for (tl = 0; tl < enc_cfg.ts_number_layers; ++tl) {
+    for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
       char file_name[PATH_MAX];
 
-      snprintf(file_name, sizeof(file_name), "%s_t%d.ivf",
-               app_input.output_filename, tl);
-      outfile[tl] = vpx_video_writer_open(file_name, kContainerIVF, &info);
-      if (!outfile[tl]) die("Failed to open %s for writing", file_name);
+      snprintf(file_name, sizeof(file_name), "%s_s%d.ivf",
+               app_input.output_filename, sl);
+      outfile[sl] = vpx_video_writer_open(file_name, kContainerIVF, &info);
+      if (!outfile[sl]) die("Failed to open %s for writing", file_name);
     }
   }
 #endif
@@ -726,6 +728,8 @@
 
   vpx_codec_control(&codec, VP9E_SET_SVC_INTER_LAYER_PRED, 0);
 
+  vpx_codec_control(&codec, VP9E_SET_NOISE_SENSITIVITY, 0);
+
   // Encode frames
   while (!end_of_stream) {
     vpx_codec_iter_t iter = NULL;
@@ -800,6 +804,7 @@
             uint64_t sizes[8];
             uint64_t sizes_parsed[8];
             int count = 0;
+            int tot_size = 0;
             vp9_zero(sizes);
             vp9_zero(sizes_parsed);
 #endif
@@ -825,14 +830,16 @@
                     num_layers_encoded++;
                   }
                 }
+                tot_size = 0;
+                for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
+                  if (cx_pkt->data.frame.spatial_layer_encoded[sl]) {
+                    tot_size += sizes[sl];
+                    vpx_video_writer_write_frame(
+                        outfile[sl], cx_pkt->data.frame.buf, tot_size,
+                        cx_pkt->data.frame.pts);
+                  }
+                }
               }
-              for (tl = layer_id.temporal_layer_id;
-                   tl < enc_cfg.ts_number_layers; ++tl) {
-                vpx_video_writer_write_frame(
-                    outfile[tl], cx_pkt->data.frame.buf, cx_pkt->data.frame.sz,
-                    cx_pkt->data.frame.pts);
-              }
-
               for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
                 if (cx_pkt->data.frame.spatial_layer_encoded[sl]) {
                   for (tl = layer_id.temporal_layer_id;
@@ -941,8 +948,8 @@
   }
 #if OUTPUT_RC_STATS
   if (svc_ctx.output_rc_stat) {
-    for (tl = 0; tl < enc_cfg.ts_number_layers; ++tl) {
-      vpx_video_writer_close(outfile[tl]);
+    for (sl = 0; sl < enc_cfg.ss_number_layers; ++sl) {
+      vpx_video_writer_close(outfile[sl]);
     }
   }
 #endif