[FFmpeg-devel] [PATCH] opt: Do not clip numerator / denominator arbitrarily in write_number

Michael Niedermayer michaelni at gmx.at
Tue Feb 18 21:48:13 CET 2014


On Tue, Feb 18, 2014 at 02:16:57PM -0500, Mashiat Sarker Shakkhar wrote:
> It is not clear why this has to be `1 << 24` and can't be INT_MAX. Making
> this change fixes decoding of files with very large timebase.
> 
> This also updates one FATE test ref. Although the tb num / den are
> different now, they still evaluate to the same number.
> ---
>  libavutil/opt.c          |    2 +-
>  tests/ref/fate/zmbv-8bit |    2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libavutil/opt.c b/libavutil/opt.c
> index 6ecc14e..7a6a58a 100644
> --- a/libavutil/opt.c
> +++ b/libavutil/opt.c
> @@ -121,7 +121,7 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int
>      case AV_OPT_TYPE_DOUBLE:*(double    *)dst= num*intnum/den;         break;
>      case AV_OPT_TYPE_RATIONAL:
>          if ((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den};
> -        else                 *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24);
> +        else                 *(AVRational*)dst= av_d2q(num*intnum/den, INT_MAX);
>          break;
>      default:
>          return AVERROR(EINVAL);
> diff --git a/tests/ref/fate/zmbv-8bit b/tests/ref/fate/zmbv-8bit
> index f104c98..9f02ae3 100644
> --- a/tests/ref/fate/zmbv-8bit
> +++ b/tests/ref/fate/zmbv-8bit
> @@ -1,4 +1,4 @@
> -#tb 0: 15967/1119068
> +#tb 0: 1000000/70086303

These differ by .00000000000001275

that is even with a 100 years long video you would be only off by
3 milli seconds

so thats certainly doesnt "fix" decoding of anything, you wouldnt
notice the difference

but theres indeed a bug in there, ill push a fix for that in a
second.
Changing 1<<24 to INT_MAX though would likely result in platform
specific differences for what comes out due to float rounding
issues

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
then the original author, trying to rewrite it will not make it better.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140218/67ecf8d5/attachment.asc>


More information about the ffmpeg-devel mailing list