From ad41f64ed930e177399d7a9106640f3284559db1 Mon Sep 17 00:00:00 2001 From: Matthias Grundmann Date: Fri, 14 Apr 2017 11:32:16 -0700 Subject: [PATCH] Fix rounding mode inconsistency double calculation is using rounding, vs. int using truncation. --- src/mp4util.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mp4util.cpp b/src/mp4util.cpp index 47bd74e..932b22d 100644 --- a/src/mp4util.cpp +++ b/src/mp4util.cpp @@ -259,7 +259,8 @@ uint64_t MP4ConvertTime(uint64_t t, // check if we can safely use integer operations if (ilog2(t) + ilog2(newTimeScale) <= 64) { - return (t * newTimeScale) / oldTimeScale; + // convert with rounding. + return (t * newTimeScale + oldTimeScale / 2) / oldTimeScale; } // final resort is to use floating point