[MPlayer-dev-eng] [PATCH] MPEG-2 TS 60000/1001 FPS Conversion Error in mencoder

Bill Adams gofish at evilbill.org
Wed Nov 29 02:52:21 CET 2006


Uoti Urpala wrote:
>> So we should either fix that and make the fps numbers rationals, or (as a 
>> dirty workaround) make everything after such conversions less picky about 
>> exact matches (e.g., in find_frame_rate_index() change the "if(dmin)" to 
>> "if(dmin > 1)").
>>     
>
> Just using doubles instead of single precision floats should be enough
> as long as the frame rates do not have numerators or denominators in the
> tens of millions.
>   
When I first started down this road, I was convinced that was the 
problem. For a MPGE-2 TS conversion the code first gets the time-base 
code from the stream (libmpdemux/mpeg_hdr.c) and returns a float 
framerate. This float gets turned back into a rational number. I 
initially figured it was a rounding error:

#include <stdio.h>
int main()
{
   float  a, b, c;
   double x, y, z;
   x = (double)60000/1001;
   y = (double)1/x;
   z = (double)1/y;
   printf( "Double: %.10f\t%.10f\t%.10f\n", x, y, z );

   a = (float)60000/1001;
   b = (float)1/a;
   c = (float)1/b;
   printf( "Float: %.10f\t%.10f\t%.10f\n", a, b, c );

   return 0;
}

With the following results:
Double: 59.9400599401   0.0166833333    59.9400599401
Float: 59.9400596619    0.0166833326    59.9400634766

The illegal FPS I was getting was 19001/317 which is approximately 
59.940063 ie., the float value.

I do not know if it will fix the problem in other places and otherwise 
make mencoder better behaved, but I will happily send in some patches 
for changing the mpeg 2/mencoder framerates to doubles if there is a 
good chance the patches will be accepted. Someone just give me the word.

b.




More information about the MPlayer-dev-eng mailing list