[FFmpeg-devel] [PATCH] Implement in lavc a flag which makes avcodec_open() to choose the best framerate
Stefano Sabatini
stefano.sabatini-lala
Sun Sep 21 18:52:23 CEST 2008
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?
> > + 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...
Regards.
--
FFmpeg = Freak Free Meaningful Portentous Eretic Guru
More information about the ffmpeg-devel
mailing list