[Ffmpeg-cvslog] r7186 - trunk/libavutil/rational.c

michael subversion
Thu Nov 30 02:18:57 CET 2006


Author: michael
Date: Thu Nov 30 02:18:57 2006
New Revision: 7186

Modified:
   trunk/libavutil/rational.c

Log:
return optimal fraction
based on a patch by Uoti Urpala


Modified: trunk/libavutil/rational.c
==============================================================================
--- trunk/libavutil/rational.c	(original)
+++ trunk/libavutil/rational.c	Thu Nov 30 02:18:57 2006
@@ -51,7 +51,15 @@
         int64_t a2n= x*a1.num + a0.num;
         int64_t a2d= x*a1.den + a0.den;
 
-        if(a2n > max || a2d > max) break;
+        if(a2n > max || a2d > max){
+            if(a1.num) x= (max - a0.num) / a1.num;
+            if(a1.den) x= FFMIN(x, (max - a0.den) / a1.den);
+
+            // Won't overflow, sum == original denominator
+            if (den*(2*x*a1.den + a0.den) > nom*a1.den)
+                a1 = (AVRational){x*a1.num + a0.num, x*a1.den + a0.den};
+            break;
+        }
 
         a0= a1;
         a1= (AVRational){a2n, a2d};




More information about the ffmpeg-cvslog mailing list