]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/commitdiff
try to guess the fps if they are variable
authormichael <michael@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Sun, 19 Dec 2004 01:23:22 +0000 (01:23 +0000)
committermichael <michael@9553f0bf-9b14-0410-a0b8-cfaf0461ba5b>
Sun, 19 Dec 2004 01:23:22 +0000 (01:23 +0000)
git-svn-id: file:///var/local/repositories/ffmpeg/trunk@3760 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b

ffmpeg.c
libavformat/flvdec.c
libavformat/utils.c

index abf90ef6a5b2102eb0bd3b09bf76767313db9be3..38191689106bb514b75321cceb6de6b9e995ee4f 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -2881,14 +2881,13 @@ static void opt_input_file(const char *filename)
             if(me_threshold)
                 enc->debug |= FF_DEBUG_MV;
 
-            assert(enc->frame_rate_base == rfps_base); // should be true for now
-            if (enc->frame_rate != rfps) { 
+            if (enc->frame_rate != rfps || enc->frame_rate_base != rfps_base) { 
 
                 if (verbose >= 0)
-                    fprintf(stderr,"\nSeems that stream %d comes from film source: %2.2f->%2.2f\n",
-                            i, (float)enc->frame_rate / enc->frame_rate_base,
+                    fprintf(stderr,"\nSeems that stream %d comes from film source: %2.2f (%d/%d) -> %2.2f (%d/%d)\n",
+                            i, (float)enc->frame_rate / enc->frame_rate_base, enc->frame_rate, enc->frame_rate_base,
 
-                    (float)rfps / rfps_base);
+                    (float)rfps / rfps_base, rfps, rfps_base);
             }
             /* update the current frame rate to match the stream frame rate */
             frame_rate      = rfps;
index 48d1719c5c2b748521494dd341f2c1660a4718d4..3664f8a024b3580aa047df710b6a748e8685d0e7 100644 (file)
@@ -103,7 +103,8 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
             return AVERROR_NOMEM;
 
         av_set_pts_info(st, 24, 1, 1000); /* 24 bit pts in ms */
-        st->codec.frame_rate_base= 0;
+        st->codec.frame_rate_base= 1;
+        st->codec.frame_rate= 1000;
     }
     break;
  }
@@ -123,19 +124,12 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
             }
         }
     }else{
-        if(st->codec.frame_rate_base == 0){
             st->codec.codec_type = CODEC_TYPE_VIDEO;
-            //guess the frame rate
-            if(pts){
-                st->codec.frame_rate_base=1;
-                st->codec.frame_rate= (1000 + pts/2)/pts;
-            }
             switch(flags & 0xF){
             case 2: st->codec.codec_id = CODEC_ID_FLV1; break;
             default:
                 st->codec.codec_tag= flags & 0xF;
             }
-        }
     }
 
     if (av_new_packet(pkt, size) < 0)
index da5348644f88d0c5fcf9d371115b61cab16593ce..efed2e41dec0ad0e5fb92110707c389c0e81692d 100644 (file)
@@ -1726,7 +1726,14 @@ int av_find_stream_info(AVFormatContext *ic)
     AVStream *st;
     AVPacket pkt1, *pkt;
     AVPacketList *pktl=NULL, **ppktl;
+    int64_t last_dts[MAX_STREAMS];
+    int64_t best_duration[MAX_STREAMS];
 
+    for(i=0;i<MAX_STREAMS;i++){
+        last_dts[i]= AV_NOPTS_VALUE;
+        best_duration[i]= INT64_MAX;
+    }
+    
     count = 0;
     read_size = 0;
     ppktl = &ic->packet_buffer;
@@ -1792,6 +1799,15 @@ int av_find_stream_info(AVFormatContext *ic)
         if (pkt->duration != 0)
             st->codec_info_nb_frames++;
 
+        if(st->codec.codec_type == CODEC_TYPE_VIDEO){
+            int64_t last= last_dts[pkt->stream_index];
+            
+            if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && last < pkt->dts && 
+               best_duration[pkt->stream_index] > pkt->dts - last){
+                best_duration[pkt->stream_index] = pkt->dts - last;
+            }
+            last_dts[pkt->stream_index]= pkt->dts;
+        }
         /* if still no information, we try to open the codec and to
            decompress the frame. We try to avoid that in most cases as
            it takes longer and uses more memory. For MPEG4, we need to
@@ -1823,6 +1839,13 @@ int av_find_stream_info(AVFormatContext *ic)
         if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
             if(st->codec.codec_id == CODEC_ID_RAWVIDEO && !st->codec.codec_tag && !st->codec.bits_per_sample)
                 st->codec.codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec.pix_fmt);
+
+            if(best_duration[i] < INT64_MAX && st->codec.frame_rate_base*1000 <= st->codec.frame_rate){
+                st->r_frame_rate= st->codec.frame_rate;
+                st->r_frame_rate_base= av_rescale(best_duration[i], st->codec.frame_rate, AV_TIME_BASE);
+                av_reduce(&st->r_frame_rate, &st->r_frame_rate_base, st->r_frame_rate, st->r_frame_rate_base, 1<<15);
+            }
+
             /* set real frame rate info */
             /* compute the real frame rate for telecine */
             if ((st->codec.codec_id == CODEC_ID_MPEG1VIDEO ||