[FFmpeg-devel] [PATCH] lavf: inspect more frames for fps when container time base is coarse

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sun Mar 27 17:04:12 CEST 2011


Ping?

On Mon, Feb 28, 2011 at 02:20:56AM +0200, Anssi Hannula wrote:
> As per issue2629, most 23.976fps matroska H.264 files are incorrectly
> detected as 24fps, as the matroska timestamps usually have only
> millisecond precision.
> 
> Fix that by doubling the amount of timestamps inspected for frame rate
> for streams that have coarse time base. This also fixes 29.970 detection
> in matroska.
> 
> ---
> 
> A preferable solution to issue2629 would be to somehow use header values
> either from the H.264 stream or from the Matroska stream.
> 
> However, AFAICS the framerate inspecting has to be fixed as well anyway
> (with e.g. this patch), for cases when we have no reliable header values.
> 
> Comments welcome.
> ---
>  libavformat/utils.c |   10 +++++++++-
>  1 files changed, 9 insertions(+), 1 deletions(-)
> 
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 1f0164f..0e73e52 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -2273,12 +2273,20 @@ int av_find_stream_info(AVFormatContext *ic)
>  
>          /* check if one codec still needs to be handled */
>          for(i=0;i<ic->nb_streams;i++) {
> +            int fps_analyze_framecount = 20;
> +
>              st = ic->streams[i];
>              if (!has_codec_parameters(st->codec))
>                  break;
> +            /* if the timebase is coarse (like the usual millisecond precision
> +               of mkv), we need to analyze more frames to reliably arrive at
> +               the correct fps */
> +            if (av_q2d(st->time_base) > 0.0005)
> +                fps_analyze_framecount *= 2;
>              /* variable fps and no guess at the real fps */
>              if(   tb_unreliable(st->codec) && !(st->r_frame_rate.num && st->avg_frame_rate.num)
> -               && st->info->duration_count<20 && st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
> +               && st->info->duration_count < fps_analyze_framecount
> +               && st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
>                  break;
>              if(st->parser && st->parser->parser->split && !st->codec->extradata)
>                  break;
> -- 
> 1.7.3
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel



More information about the ffmpeg-devel mailing list