Simplify framerate representation

Running aomenc / aomdec on a file like crowd_run_360_10,
with webm as the intermediate container, will result in a
file with a framerate of F49000000:980000. This is correct, but
easier to read as 50:1.

Change-Id: I36844473b4044d7db9359015af00234d7b7fd2d3
diff --git a/common/webmdec.cc b/common/webmdec.cc
index 17ac53c..33bda59 100644
--- a/common/webmdec.cc
+++ b/common/webmdec.cc
@@ -197,6 +197,17 @@
   return frame.Read(reader, *buffer) ? -1 : 0;
 }
 
+// Calculate the greatest common divisor between two numbers.
+static int gcd(int a, int b) {
+  int remainder;
+  while (b > 0) {
+    remainder = a % b;
+    a = b;
+    b = remainder;
+  }
+  return a;
+}
+
 int webm_guess_framerate(struct WebmInputContext *webm_ctx,
                          struct AvxInputContext *aom_ctx) {
   uint32_t i = 0;
@@ -213,6 +224,14 @@
   aom_ctx->framerate.numerator = (i - 1) * 1000000;
   aom_ctx->framerate.denominator =
       static_cast<int>(webm_ctx->timestamp_ns / 1000);
+  // Fraction might be represented in large numbers, like 49000000/980000
+  // for 50fps. Simplify as much as possible.
+  int g = gcd(aom_ctx->framerate.numerator, aom_ctx->framerate.denominator);
+  if (g != 0) {
+    aom_ctx->framerate.numerator /= g;
+    aom_ctx->framerate.denominator /= g;
+  }
+
   delete[] buffer;
   webm_ctx->buffer = NULL;