[FFmpeg-devel] [PATCH] Implement in lavc a flag which makes avcodec_open() to choose the best framerate

Michael Niedermayer michaelni
Sun Sep 21 22:16:56 CEST 2008


On Sun, Sep 21, 2008 at 06:52:23PM +0200, Stefano Sabatini wrote:
> On date Sunday 2008-09-21 14:09:56 +0200, Michael Niedermayer encoded:
> > On Sun, Sep 21, 2008 at 12:52:57PM +0200, Stefano Sabatini wrote:
> [...]
> > > Index: libavutil/rational.c
> > > ===================================================================
> > > --- libavutil/rational.c	(revision 15372)
> > > +++ libavutil/rational.c	(working copy)
> > > @@ -101,3 +101,81 @@
> > >  
> > >      return a;
> > >  }
> > > +
> > > +int av_is_nearest_q(AVRational q, AVRational q1, AVRational q2)
> > > +{
> > > +    if (av_cmp_q(q1, q) * av_cmp_q(q, q2) > 0) {
> > > +        /* q1 and q2 on the opposite sides of q */
> > > +        /* N/D is q, A/B is the median between q1 and q2, A/B > N/D <=> A*D/B > N */
> > 
> > > +        int64_t x = av_rescale(q1.num * (int64_t)q2.den + q2.num * (int64_t)q1.den, q.den, 2 * (int64_t)q1.den * q2.den);
> > 
> > the rounding is not correct
> 
> I see that the type of rounding choosen may change the result of the
> comparation if the result isn't exact, but I can't currently figure
> out which is the correct one to apply.
> 
> Can you suggest which should I use?

to test A*D/B > N
the left side should be rounded toward inf


> 
> > > +        if (((x > q.num ? 1 : x < q.num ? -1 : 0) * av_cmp_q(q2, q1)) > 0)
> > > +            return 1;
> > > +    }
> > 
> > > +    /* q1 and q2 on the same side of q */
> > > +    else if (av_cmp_q(q, q1) * av_cmp_q(q1, q2) > 0)
> > 
> > i dont see why these special cases would be needed
> 
> The first condition:
> cmp(M, q) * cmp(q2, q1) == 1 
> 
> catches both the conditions:
> q1 ... q ... M ... q2
> M > q && q2 > q1
> and 
> q2 ... M ... q ... q1
> M < q && q2 < q1
> 
> (x > q.num ? 1 : x < q.num ? -1 : 0) corresponds to cmp(M, q).
> 
> The second condition:
> cmp(q, q1) * cmp(q1, q2) ==  1
> cathes both the conditions:
> q2 ... q1 ... q
> q > q1 && q1 > q2
> and 
> q ... q1 ... q2
> q < q1 && q1 < q2
> 
> I can't see how to simplify this...

what is the problem with the code for the first case handling the second?


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

The worst form of inequality is to try to make unequal things equal.
-- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20080921/ec4dee83/attachment.pgp>



More information about the ffmpeg-devel mailing list