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

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


On Fri, Feb 27, 2009 at 02:18:12PM +0100, Reimar D?ffinger wrote:
> On Fri, Feb 27, 2009 at 01:45:39PM +0100, Michael Niedermayer wrote:
> > On Fri, Feb 27, 2009 at 08:59:14AM +0100, Reimar D?ffinger wrote:
> > > On Fri, Feb 27, 2009 at 12:28:03AM +0100, Michael Niedermayer wrote:
> 
> [concerning code to guess r_frame_rate in libavformat/utils.c]
> 
> > > > 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...
> > 
> > fix that prevents it from increasing the frame rate is welcome ...
> 
> Well, I thought the code was also there to prefer standard rates, not
> just reduce the frame rate.
> I have not extensively tested, but does attached patch fit the intended
> purpose of the code?

Sorry, here is a fixed version. The "if" looks a bit ugly though.
-------------- next part --------------
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 9ae0658..9354b75 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2194,6 +2194,7 @@ int av_find_stream_info(AVFormatContext *ic)
                && tb_unreliable(st->codec) /*&&
                //FIXME we should not special-case MPEG-2, but this needs testing with non-MPEG-2 ...
                st->time_base.num*duration_sum[i]/duration_count[i]*101LL > st->time_base.den*/){
+                int num = 0;
                 double best_error= 2*av_q2d(st->time_base);
                 best_error= best_error*best_error*duration_count[i]*1000*12*30;
 
@@ -2203,9 +2204,12 @@ int av_find_stream_info(AVFormatContext *ic)
 //                        av_log(NULL, AV_LOG_ERROR, "%f %f\n", get_std_framerate(j) / 12.0/1001, error);
                     if(error < best_error){
                         best_error= error;
-                        av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, get_std_framerate(j), 12*1001, INT_MAX);
+                        num = get_std_framerate(j);
                     }
                 }
+                // do not increase frame rate by more than 1 % in order to match a standard rate.
+                if (num && (!st->r_frame_rate.num || (double)num/(12*1001) < 1.01 * av_q2d(st->r_frame_rate)))
+                    av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, num, 12*1001, INT_MAX);
             }
 
             if (!st->r_frame_rate.num){



More information about the ffmpeg-devel mailing list