[Ffmpeg-cvslog] r7272 - trunk/libavformat/flvdec.c

michael subversion
Sun Dec 10 18:53:01 CET 2006


Author: michael
Date: Sun Dec 10 18:53:01 2006
New Revision: 7272

Modified:
   trunk/libavformat/flvdec.c

Log:
move duration finding code into read_packet() so it can be skiped if duration has already been set


Modified: trunk/libavformat/flvdec.c
==============================================================================
--- trunk/libavformat/flvdec.c	(original)
+++ trunk/libavformat/flvdec.c	Sun Dec 10 18:53:01 2006
@@ -57,7 +57,7 @@
 static int flv_read_header(AVFormatContext *s,
                            AVFormatParameters *ap)
 {
-    int offset, flags, size;
+    int offset, flags;
     AVStream *st;
 
     url_fskip(&s->pb, 4);
@@ -79,17 +79,6 @@
     }
 
     offset = get_be32(&s->pb);
-
-    if(!url_is_streamed(&s->pb)){
-        const int fsize= url_fsize(&s->pb);
-        url_fseek(&s->pb, fsize-4, SEEK_SET);
-        size= get_be32(&s->pb);
-        url_fseek(&s->pb, fsize-3-size, SEEK_SET);
-        if(size == get_be24(&s->pb) + 11){
-            s->duration= get_be24(&s->pb) * (int64_t)AV_TIME_BASE / 1000;
-        }
-    }
-
     url_fseek(&s->pb, offset, SEEK_SET);
 
     s->start_time = 0;
@@ -190,6 +179,20 @@
     break;
  }
 
+    // if not streamed and no duration from metadata then seek to end to find the duration from the timestamps
+    if(!url_is_streamed(&s->pb) && s->duration==AV_NOPTS_VALUE){
+        int size;
+        const int pos= url_ftell(&s->pb);
+        const int fsize= url_fsize(&s->pb);
+        url_fseek(&s->pb, fsize-4, SEEK_SET);
+        size= get_be32(&s->pb);
+        url_fseek(&s->pb, fsize-3-size, SEEK_SET);
+        if(size == get_be24(&s->pb) + 11){
+            s->duration= get_be24(&s->pb) * (int64_t)AV_TIME_BASE / 1000;
+        }
+        url_fseek(&s->pb, pos, SEEK_SET);
+    }
+
     if(is_audio){
         if(st->codec->sample_rate == 0){
             st->codec->channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1;




More information about the ffmpeg-cvslog mailing list