Commit 3db1b8b5 authored by Michael Niedermayer's avatar Michael Niedermayer

return optimal fraction

based on a patch by Uoti Urpala

Originally committed as revision 7186 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 8fa641f8
...@@ -51,7 +51,15 @@ int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max) ...@@ -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 a2n= x*a1.num + a0.num;
int64_t a2d= x*a1.den + a0.den; 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; a0= a1;
a1= (AVRational){a2n, a2d}; a1= (AVRational){a2n, a2d};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment