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

Clément Bœsch ubitux at gmail.com
Thu Mar 28 05:36:31 CET 2013


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.

> +    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.

[...]

Rest LGTM, thank you

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130328/08ded341/attachment.asc>


More information about the ffmpeg-devel mailing list