[FFmpeg-devel] [PATCH] simplify ipmovie.c pts calculation

Reimar Döffinger Reimar.Doeffinger
Fri Feb 27 08:59:14 CET 2009


On Fri, Feb 27, 2009 at 12:28:03AM +0100, Michael Niedermayer wrote:
> > diff --git a/libavformat/utils.c b/libavformat/utils.c
> > index 073e6da..9960fcd 100644
> > --- a/libavformat/utils.c
> > +++ b/libavformat/utils.c
> > @@ -2006,6 +2006,7 @@ int av_find_stream_info(AVFormatContext *ic)
> >      AVStream *st;
> >      AVPacket pkt1, *pkt;
> >      int64_t last_dts[MAX_STREAMS];
> > +    int64_t duration_gcd[MAX_STREAMS]={0};
> >      int duration_count[MAX_STREAMS]={0};
> >      double (*duration_error)[MAX_STD_TIMEBASES];
> >      int64_t old_offset = url_ftell(ic->pb);
> > @@ -2127,6 +2128,7 @@ int av_find_stream_info(AVFormatContext *ic)
> >                      double error= dur - ticks*1001*12/(double)framerate;
> >                      duration_error[index][i] += error*error;
> >                  }
> > +                duration_gcd[index] = av_gcd(duration_gcd[index], duration);
> >                  duration_count[index]++;
> >              }
> >              if(last == AV_NOPTS_VALUE || duration_count[index]<=1)
> > @@ -2181,6 +2183,8 @@ int av_find_stream_info(AVFormatContext *ic)
> >              if(st->codec->codec_id == CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_coded_sample)
> >                  st->codec->codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt);
> >  
> > +            if (duration_count[i] > 5 && duration_gcd[i] > 1)
> > +                av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time_base.den, st->time_base.num * duration_gcd[i], INT_MAX);
> 
> maybe this should be under tb_unreliable() and the number should be higher
> than 5 (patch ok with  <- these)

Applied with these fixed and some additional comments.

> also if you ignore the first 1-2 durations then this might fix the fps of
> h264_acc_in_flv.flv i think

I set the code to ignore the first 4, for that file it gives a frame
rate of 22.2222... which seems not really right either, though I don't
actually know what the right value is.
It does not make a difference though, since the get_std_framerate-based
code after it overwrites it...




More information about the ffmpeg-devel mailing list