[FFmpeg-cvslog] r19773 - in trunk/libavformat: seek.c seek.h
Uoti Urpala
uoti.urpala
Tue Sep 15 14:41:21 CEST 2009
On Tue, 2009-09-15 at 13:30 +0200, Michael Niedermayer wrote:
> On Tue, Sep 15, 2009 at 02:55:30AM +0300, Uoti Urpala wrote:
> > +static int convert_ts(uint64_t ts, AVRational tb_from, AVRational tb_to)
> > +{
> > + // this algorithm is copied from NUT spec and works only for non-negative numbers
> > + uint64_t ln = (uint64_t) tb_from.num * (uint64_t) tb_to.den;
> > + uint64_t d1 = tb_from.den;
> > + uint64_t d2 = tb_to.num;
> > + return (ln / d1 * ts + ln % d1 * ts / d1) / d2;
> > +}
> >
> > This takes input timestamp as uint64_t but has return type int,
>
> as ivan said, it was a typo ...
>
>
> > and it
> > wouldn't work with a larger return type (the return statement is of the
> > form "something/d2", so it cannot possibly correctly return anything
> > bigger than UINT64_MAX / d2 - or about 32 bits if d2 is assumed to have
> > full 32 bit range).
>
> yes, it works only with files of about 100 years duration
It can fail with much shorter scaled durations if the timestamp is over
32 bits. For example with ts = 20G, tb_from = 1 / 1.1G, tb_to = 1G / 1G
(G=1000000000) the "ln % d1 * ts" part will overflow and it'll fail even
though the scaled value is only 20 seconds.
More information about the ffmpeg-cvslog
mailing list