[FFmpeg-devel] [PATCH] ffmpeg/avformat: factor av_guess_frame_rate() out

Michael Niedermayer michaelni at gmx.at
Fri Mar 29 17:54:09 CET 2013


On Thu, Mar 28, 2013 at 05:36:31AM +0100, Clément Bœsch wrote:
> On Wed, Mar 27, 2013 at 10:48:50PM +0100, Michael Niedermayer wrote:
> [...]
> >  /**
> > + * Guess the frame rate, based on both the container and codec information.
> > + *
> > + * @param format the format context which the stream is part of
> > + * @param stream the stream which the frame is part of
> > + * @param frame the frame for which the frame rate should be determined, may be NULL
> > + * @return the guessed (valid) frame rate, 0/1 if no idea
> > + */
> > +AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *stream, AVFrame *frame);
> > +
> > +/**
> >   * Check if the stream st contained in s is matched by the stream specifier
> >   * spec.
> >   *
> > diff --git a/libavformat/utils.c b/libavformat/utils.c
> > index f9acc0e..025cad3 100644
> > --- a/libavformat/utils.c
> > +++ b/libavformat/utils.c
> > @@ -4276,6 +4276,22 @@ AVRational av_guess_sample_aspect_ratio(AVFormatContext *format, AVStream *strea
> >          return frame_sample_aspect_ratio;
> >  }
> >  
> > +AVRational av_guess_frame_rate(AVFormatContext *format, AVStream *st, AVFrame *frame)
> > +{
> 
> While having an unused format context can make sense for a later usage,
> I'm not sure the AVFrame parameter is relevant. In the sample aspect ratio
> it makes sense, but in the case of frame rate I doubt a single frame will
> ever. I'm happy to be proven wrong though.

left for consistency with the sample rate guessing also maybe it
will be usefull one day, frames carry interlacing info amongth other
things


> 
> > +    AVRational fr = st->r_frame_rate;
> > +
> > +    if (st->codec->ticks_per_frame>1) {
> > +        AVRational codec_fr = av_inv_q(st->codec->time_base);
> > +        AVRational   avg_fr = st->avg_frame_rate;
> > +        codec_fr.den *= st->codec->ticks_per_frame;
> > +        if (   codec_fr.num>0 && codec_fr.den>0 && av_q2d(codec_fr) < av_q2d(fr)*0.7
> > +            && fabs(1.0 - av_q2d(av_div_q(avg_fr, fr)))>0.1)
> > +            fr = codec_fr;
> > +    }
> > +
> > +    return fr;
> > +}
> > +
> 
> stylenit: please put spaces around the '>' and '<' operators. Or delete
> the spaces where they are present in that function so it can be consistent
> at least at the function level.

fixed
and pushed

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

Let us carefully observe those good qualities wherein our enemies excel us
and endeavor to excel them, by avoiding what is faulty, and imitating what
is excellent in them. -- Plutarch
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130329/d6e8e1d1/attachment.asc>


More information about the ffmpeg-devel mailing list