aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2006-11-30 01:18:57 +0000
committerMichael Niedermayer <michaelni@gmx.at>2006-11-30 01:18:57 +0000
commit3db1b8b5386d7d9c79008df4a64c4d871f575c3c (patch)
tree2af55a3bbb66efe70556b8f84f4f3c4178b0e14e /libavutil
parent8fa641f8e8b38d48ddad7f58772aa06bc8b4bdf6 (diff)
downloadffmpeg-3db1b8b5386d7d9c79008df4a64c4d871f575c3c.tar.gz
return optimal fraction
based on a patch by Uoti Urpala Originally committed as revision 7186 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/rational.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/libavutil/rational.c b/libavutil/rational.c
index 4f343f7e32..9fcf621f0b 100644
--- a/libavutil/rational.c
+++ b/libavutil/rational.c
@@ -51,7 +51,15 @@ int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max)
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};