shithub: libvpx

Download patch

ref: fd4efde4899b2627da0da153294fd663168a9bb3
parent: 7042137e603e7bc98783fa4704f8d0460d66c44b
author: Peter Boström <pbos@google.com>
date: Fri Oct 28 10:50:20 EDT 2016

Add temporal-layer support to tiny_ssim.

Permits skipping 0, 1/2 or 3/4 of the frames, corresponding to
temporal layers 2, 1 and 0 of a 3-temporal-layer encoding. 1/2
corresponds to TL0 in a 2-layer encoding.

Change-Id: I7f6d131f63707e5262fc67d111bfb3a751ede90d

--- a/tools/tiny_ssim.c
+++ b/tools/tiny_ssim.c
@@ -119,18 +119,25 @@
 int main(int argc, char *argv[]) {
   FILE *f[2];
   uint8_t *buf[2];
-  int w, h, n_frames;
+  int w, h, n_frames, tl_skip = 0, tl_skips_remaining = 0;
   double ssim = 0, psnravg = 0, psnrglb = 0;
   double ssimy, ssimu, ssimv;
   uint64_t psnry, psnru, psnrv;
 
   if (argc < 4) {
-    fprintf(stderr, "Usage: %s file1.yuv file2.yuv WxH\n", argv[0]);
+    fprintf(stderr, "Usage: %s file1.yuv file2.yuv WxH [tl_skip={0,1,3}]\n",
+            argv[0]);
     return 1;
   }
   f[0] = strcmp(argv[1], "-") ? fopen(argv[1], "rb") : stdin;
   f[1] = strcmp(argv[2], "-") ? fopen(argv[2], "rb") : stdin;
   sscanf(argv[3], "%dx%d", &w, &h);
+  // Number of frames to skip from file1.yuv for every frame used. Normal values
+  // 0, 1 and 3 correspond to TL2, TL1 and TL0 respectively for a 3TL encoding
+  // in mode 10. 7 would be reasonable for comparing TL0 of a 4-layer encoding.
+  if (argc > 4) {
+    sscanf(argv[4], "%d", &tl_skip);
+  }
   if (!f[0] || !f[1]) {
     fprintf(stderr, "Could not open input files: %s\n", strerror(errno));
     return 1;
@@ -141,9 +148,20 @@
   }
   buf[0] = malloc(w * h * 3 / 2);
   buf[1] = malloc(w * h * 3 / 2);
-  for (n_frames = 0;; n_frames++) {
-    size_t r1 = fread(buf[0], w * h * 3 / 2, 1, f[0]);
-    size_t r2 = fread(buf[1], w * h * 3 / 2, 1, f[1]);
+  n_frames = 0;
+  while (1) {
+    size_t r1, r2;
+    r1 = fread(buf[0], w * h * 3 / 2, 1, f[0]);
+    if (r1) {
+      // Reading parts of file1.yuv that were not used in temporal layer.
+      if (tl_skips_remaining > 0) {
+        --tl_skips_remaining;
+        continue;
+      }
+      // Use frame, but skip |tl_skip| after it.
+      tl_skips_remaining = tl_skip;
+    }
+    r2 = fread(buf[1], w * h * 3 / 2, 1, f[1]);
     if (r1 && r2 && r1 != r2) {
       fprintf(stderr, "Failed to read data: %s [%d/%d]\n", strerror(errno),
               (int)r1, (int)r2);
@@ -161,6 +179,7 @@
     ssim += 0.8 * ssimy + 0.1 * (ssimu + ssimv);
     psnravg += vp9_mse2psnr(w * h * 6 / 4, 255.0, psnry + psnru + psnrv);
     psnrglb += psnry + psnru + psnrv;
+    n_frames++;
   }
   free(buf[0]);
   free(buf[1]);