[MPlayer-dev-eng] enhancement for yuv4mpeg output driver

Trent Piepho xyzzy at speakeasy.org
Thu Jan 20 22:18:50 CET 2005


On Thu, 20 Jan 2005, D Richard Felker III wrote:
> > any fraction that was converted to a floating point number back into a
> > fraction, that is theoretically impossible.
> 
> of course. but if you know a bound on the denominator, and the bound
> is small enough, it IS possible to losslessly reverse the conversion
> to float.

Only if the number of bits in the mantissa is smaller than the number of bits
in the original denominator.  Secondly, you don't know the original bound on the
denominator.  

If you have one fraction num1/den1, there may exist another fraction
num2/den2, when den2 > den1.  The floating point approximation of num1/den1,
that is num1/den1 converted to a float and rounded to n bits of precision, may
be closer to the true value of num2/den2 than to num1/den1.  In this case you
have no way of knowing which was the original fraction.  If you choose the
fraction that is closest to the floating point approximation, you will choose
the wrong value.

> > I came up with a simple routine for converting floats to fractions that works
> > correctly for any frame rate you are ever likely to see.  The routine in lavc
> 
> your code is idiotic. it will produce wrong results for avi files with
> broken near-ntsc framerates in their headers.

Do a google search for mplayer and yuv4mpeg.  I think you'll find that
every single example of people ysing the yuv4mpeg output driver involves them
overriding the incorrect yuv4mpeg header mplayer generates with one that uses
a standard frame-rate.  I dare you to find a counter example.

> > does not even work for all 18 of the ATSC standard formats, much less typical
> > avi files, while being more complex.  Why do you want me to cut and paste the
> > code from lavc into vo_yuv4mpeg?
> > 
> > If you want to replace what's in lavc with my code, that's really a different
> > issue than getting the yuv4mpeg output driver to create a working header.
> 
> rotfl!! no thanks. lavc's code already works perfectly.

You said I'm probably doing something else wrong, and that's why lavc isn't
always correct.  So, what was I doing wrong?  Try my patch, av_d2q doesn't
always give the correct fraction.  Did you try it and find that it works for
mpeg files with frame-rate codes 1, 4, and 7?  Or do you simply believe it
will work on faith and refuse to look at my evidence that it doesn't?

This is what happens if you use av_d2q on mpeg files.
frame rate code 1:
av_d2q to 2997/125
my method to 24000/1001

frame rate code 4:
av_d2q to 2997/100
my method to 30000/1001

frame rate code 7:
av_d2q to 2997/50
my method to 60000/1001

This is when I specify a fraction on the command line with -fps:
24000/1001
av_d2q to 31001/1293
my method to 24000/1001

30000/1001
av_d2q to 30000/1001
my method to 30000/1001

60000/1001
av_d2q to 60000/1001
my method to 60000/1001

Do you get different results, or not?




More information about the MPlayer-dev-eng mailing list