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

Michael Niedermayer michaelni
Fri Sep 19 01:13:51 CEST 2008


On Thu, Sep 11, 2008 at 11:44:18PM +0200, Stefano Sabatini wrote:
> On date Thursday 2008-09-11 05:52:01 +0200, Michael Niedermayer encoded:
> > On Sun, Aug 31, 2008 at 08:58:53PM +0200, Stefano Sabatini wrote:
> [...]
> > > 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.
> 
> Yes my only doubt is about the name:
> is av_find_nearest_q_idx OK?
> 
> Regards.
> -- 
> FFmpeg = Friendly and Foolish Multimedia Prodigious Extreme Gem

> Index: libavutil/rational.h
> ===================================================================
> --- libavutil/rational.h	(revision 15295)
> +++ 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 index of the nearest value found in the array
> + */
> +int av_find_nearest_q_idx(AVRational q, AVRational* q_list);

q_list should be const


> +
>  #endif /* AVUTIL_RATIONAL_H */
> Index: libavutil/rational.c
> ===================================================================
> --- libavutil/rational.c	(revision 15295)
> +++ libavutil/rational.c	(working copy)
> @@ -101,3 +101,49 @@
>  
>      return a;
>  }
> +
> +int av_find_nearest_q_idx(AVRational q, AVRational* q_list)
> +{
> +    int i, nearest_q_idx = 0;
> +    AVRational best_error= (AVRational){INT_MAX, 1};
> +    for(i=0; q_list[i].den; i++) {
> +        AVRational error= av_sub_q(q, q_list[i]);
> +        if(error.num <0) error.num *= -1;
> +        if(av_cmp_q(error, best_error) < 0) {
> +            best_error= error;
> +            nearest_q_idx = i;
> +        }
> +    }
> +    return nearest_q_idx;
> +}

This implementation isnt exact, it in many corner cases will not
return the correct element.
Examples would be, when it is farther away than INT_MAX
another example may be a list of
1/INT_MAX, 1/(INT_MAX-1), ...
compared to INT_MAX
your code would fail to be to seperate them


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

I have often repented speaking, but never of holding my tongue.
-- Xenocrates
-------------- 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/20080919/a98d06da/attachment.pgp>



More information about the ffmpeg-devel mailing list