changeset 1015:99ae26ee88d8 libavformat

extract duration
author michael
date Thu, 16 Mar 2006 17:04:31 +0000
parents 90cb439ffca9
children 2e370745416d
files flvdec.c
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flvdec.c	Tue Mar 14 00:25:46 2006 +0000
+++ b/flvdec.c	Thu Mar 16 17:04:31 2006 +0000
@@ -34,7 +34,7 @@
 static int flv_read_header(AVFormatContext *s,
                            AVFormatParameters *ap)
 {
-    int offset, flags;
+    int offset, flags, size;
 
     s->ctx_flags |= AVFMTCTX_NOHEADER; //ok we have a header but theres no fps, codec type, sample_rate, ...
 
@@ -42,6 +42,17 @@
     flags = get_byte(&s->pb);
 
     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);
 
     return 0;