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

Michael Niedermayer michaelni
Thu Sep 25 01:00:11 CEST 2008


On Wed, Sep 24, 2008 at 09:55:14PM +0200, Stefano Sabatini wrote:
> On date Tuesday 2008-09-23 04:24:46 +0200, Michael Niedermayer encoded:
> > On Mon, Sep 22, 2008 at 11:36:54PM +0200, Stefano Sabatini wrote:
> 
> > > Index: libavutil/rational.h
> > > ===================================================================
> > > --- libavutil/rational.h	(revision 15372)
> > > +++ libavutil/rational.h	(working copy)
> > > @@ -113,4 +113,17 @@
> > >   */
> > >  AVRational av_d2q(double d, int max) av_const;
> > >  
> > > +/**
> > > + * @return 1 if \q1 is nearer to \p than \p q2, 0 if \p q1 and \p q2
> > > + * have the same distance, -1 otherwise.
> > > + */
> > > +int av_near_cmp_q(AVRational q, AVRational q1, AVRational q2);
> > 
> > av_nearer_q()
> 
> Fixed.
> 
> [...]
> > > +int av_near_cmp_q(AVRational q, AVRational q1, AVRational q2)
> > > +{
> > > +    /* 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_rnd(q1.num * (int64_t)q2.den + q2.num * (int64_t)q1.den, q.den, 2 * (int64_t)q1.den * q2.den, AV_ROUND_UP);
> > > +
> > > +    return (x > q.num ? 1 : x < q.num ? -1 : 0) * av_cmp_q(q2, q1);
> > 
> > I think only one of the 2 checks is correct for AV_ROUND_UP, the other would
> > be correct for AV_ROUND_DOWN.
> > 
> > example:
> > q=1/1
> > q1= 0/1
> > q2= 1/2
> > 
> > x= 1
> > x == q.num
> 
> Yes, now it's obvious to me, now code and comments should be idiot
> proof...
> 
> If it's fine to commit I'll strip the test and update minor version.

[..]
> ===================================================================
> --- libavutil/rational.c	(revision 15400)
> +++ libavutil/rational.c	(working copy)
> @@ -101,3 +101,80 @@
>  
>      return a;
>  }
> +
> +int av_nearer_q(AVRational q, AVRational q1, AVRational q2)
> +{
> +    /* n/d is q, a/b is the median between q1 and q2 */
> +    int64_t a = q1.num * (int64_t)q2.den + q2.num * (int64_t)q1.den;
> +    int64_t b = 2 * (int64_t)q1.den * q2.den;
> +
> +    /* rnd_up(a*d/b) > n => a*d/b > n */
> +    int64_t x_up = av_rescale_rnd(a, q.den, b, AV_ROUND_UP);
> +
> +    /* rnd_down(a*d/b) < n => a*d/b < n */
> +    int64_t x_down = av_rescale_rnd(a, q.den, b, AV_ROUND_DOWN);
> +

> +    return (x_up > q.num ? 1 : x_down < q.num ? -1 : 0) * av_cmp_q(q2, q1);

return ((x_up > q.num) - (x_down < q.num)) * av_cmp_q(q2, q1);

except that iam ok with the patch i think ...


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

Everything should be made as simple as possible, but not simpler.
-- Albert Einstein
-------------- 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/20080925/11b50172/attachment.pgp>



More information about the ffmpeg-devel mailing list