flvdec: perform duration search just once
authorMichael Niedermayer <michaelni@gmx.at>
Fri, 3 Aug 2012 12:39:46 +0000 (14:39 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Fri, 3 Aug 2012 12:50:26 +0000 (14:50 +0200)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavformat/flvdec.c

index 5b81f39..fb356b8 100644 (file)
@@ -52,6 +52,7 @@ typedef struct {
     } validate_index[2];
     int validate_next;
     int validate_count;
+    int searched_for_end;
 } FLVContext;
 
 static int flv_probe(AVProbeData *p)
@@ -744,7 +745,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
  }
 
     // if not streamed and no duration from metadata then seek to end to find the duration from the timestamps
-    if(s->pb->seekable && (!s->duration || s->duration==AV_NOPTS_VALUE)){
+    if(s->pb->seekable && (!s->duration || s->duration==AV_NOPTS_VALUE) && !flv->searched_for_end){
         int size;
         const int64_t pos= avio_tell(s->pb);
         const int64_t fsize= avio_size(s->pb);
@@ -757,6 +758,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
             s->duration = ts * (int64_t)AV_TIME_BASE / 1000;
         }
         avio_seek(s->pb, pos, SEEK_SET);
+        flv->searched_for_end = 1;
     }
 
     if(stream_type == FLV_STREAM_TYPE_AUDIO){