[FFmpeg-devel] [PATCH] Implement in lavc a flag which makes avcodec_open() to choose the best framerate
Michael Niedermayer
michaelni
Thu Sep 11 05:52:01 CEST 2008
On Sun, Aug 31, 2008 at 08:58:53PM +0200, Stefano Sabatini wrote:
> On date Sunday 2008-08-31 17:09:12 +0200, Michael Niedermayer encoded:
> > On Sun, Aug 31, 2008 at 01:19:31PM +0200, Stefano Sabatini wrote:
> > > On date Sunday 2008-08-31 00:11:03 +0200, Michael Niedermayer encoded:
> > > [...]
> > > > I think we should add a function that takes a list of AVRational and a AVRational
> > > > and finds the closest match for that. Its return value should indicate if the
> > > > match is exact or approximate
> > > > Such function might be usefull for other things as well ...
> > >
> > > Yes it's the best solution I can see, it's even simpler
> > > application-level-wise, I would like to have thought that!
> > >
> > > I also thought about to return the comparation code rather than an
> > > "exact" flag like in av_reduce(), I slightly prefer the attached
> > > solution but let me know.
> >
> > what about returning the actually found value, the user could then run
> > av_cmp_q() over it himself when he needs.
>
> Mmh, OK it also simplify the interface.
[...]
> > > + }
> > > + }
> > > + return !av_cmp_q(*nearest_q, q);
> > > +}
> > > +
> >
> > > +#if TEST
> > > +int main (void) {
> > > +
> > > + AVRational list_q[] = {
> > > + {24000, 1001},
> > > + { 24, 1},
> > > + { 25, 1},
> > > + {30000, 1001},
> > > + { 30, 1},
> > > + { 50, 1},
> > > + {60000, 1001},
> > > + { 60, 1},
> > > + // Xing's 15fps: (9)
> > > + { 15, 1},
> > > + // libmpeg3's "Unofficial economy rates": (10-13)
> > > + { 5, 1},
> > > + { 10, 1},
> > > + { 12, 1},
> > > + { 15, 1},
> > > + { 0, 0},
> > > + };
> > > +
> > > + AVRational q = { 5, 1};
> > > + AVRational nearest_q;
> > > + int exact= av_find_nearest_q(&nearest_q, q, list_q);
> > > +#undef printf
> > > + printf ("q=%d/%d(%f), nearest_q=%d/%d(%f), exact=%d\n",
> > > + q.num, q.den, (double)q.num/q.den,
> > > + nearest_q.num, nearest_q.den, (double)nearest_q.num/nearest_q.den,
> > > + exact);
> > > +
> > > + q.num= 42, q.den = 1;
> > > + exact= av_find_nearest_q(&q, q, list_q);
> > > + printf ("q=%d/%d(%f), nearest_q=%d/%d(%f), exact=%d\n",
> > > + q.num, q.den, (double)q.num/q.den,
> > > + q.num, q.den, (double)q.num/q.den,
> > > + exact);
> > > +}
> > > +#endif /* TEST */
> >
> > hmm, i think if you cant come up with a shorter self test then drop it.
>
> OK, I'm keeping it for practical and pedagogical reasons, I'm going to
> remove it before the commit.
[...]
> Index: libavutil/rational.h
> ===================================================================
> --- libavutil/rational.h (revision 15120)
> +++ libavutil/rational.h (working copy)
> @@ -113,4 +113,11 @@
> */
> AVRational av_d2q(double d, int max) av_const;
>
> +/**
> + * Finds the nearest value in \p q_list to \p q.
> + * @param q_list an array of rationals terminated by {0, 0}
> + * @return the nearest value found
> + */
> +AVRational av_find_nearest_q(AVRational q, AVRational* q_list);
maybe returning an index into the list would be more flexible.
Its easy to convert a index to the AVRational not easy though
the other way around.
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Democracy is the form of government in which you can choose your dictator
-------------- 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/20080911/936fade4/attachment.pgp>
More information about the ffmpeg-devel
mailing list