changeset 1233:99a34915d15a libavformat

always write duration and file size, fix seeking, progress bar is now active
author bcoudurier
date Sun, 06 Aug 2006 15:29:50 +0000
parents 3b4d01890ada
children 765ab959c70d
files flvenc.c
diffstat 1 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/flvenc.c	Thu Aug 03 16:22:01 2006 +0000
+++ b/flvenc.c	Sun Aug 06 15:29:50 2006 +0000
@@ -25,6 +25,9 @@
     int hasAudio;
     int hasVideo;
     int reserved;
+    offset_t duration_offset;
+    offset_t filesize_offset;
+    int64_t duration;
 } FLVContext;
 
 static int get_audio_flags(AVCodecContext *enc){
@@ -160,12 +163,11 @@
 
     /* mixed array (hash) with size and string/type/data tuples */
     put_byte(pb, AMF_MIXED_ARRAY);
-    put_be32(pb, 4*flv->hasVideo + flv->hasAudio + (!!s->file_size) + (s->duration != AV_NOPTS_VALUE && s->duration));
+    put_be32(pb, 4*flv->hasVideo + flv->hasAudio + 2); // +2 for duration and file size
 
-    if (s->duration != AV_NOPTS_VALUE && s->duration) {
-        put_amf_string(pb, "duration");
-        put_amf_double(pb, s->duration / (double)AV_TIME_BASE);
-    }
+    put_amf_string(pb, "duration");
+    flv->duration_offset= url_ftell(pb);
+    put_amf_double(pb, 0); // delayed write
 
     if(flv->hasVideo){
         put_amf_string(pb, "width");
@@ -186,10 +188,9 @@
         put_amf_double(pb, samplerate);
     }
 
-    if(s->file_size){
-        put_amf_string(pb, "filesize");
-        put_amf_double(pb, s->file_size);
-    }
+    put_amf_string(pb, "filesize");
+    flv->filesize_offset= url_ftell(pb);
+    put_amf_double(pb, 0); // delayed write
 
     put_amf_string(pb, "");
     put_byte(pb, 9); // end marker 1 byte
@@ -217,6 +218,13 @@
     flags |= flv->hasVideo ? 1 : 0;
     url_fseek(pb, 4, SEEK_SET);
     put_byte(pb,flags);
+
+    /* update informations */
+    url_fseek(pb, flv->duration_offset, SEEK_SET);
+    put_amf_double(pb, flv->duration / (double)1000);
+    url_fseek(pb, flv->filesize_offset, SEEK_SET);
+    put_amf_double(pb, file_size);
+
     url_fseek(pb, file_size, SEEK_SET);
     return 0;
 }
@@ -250,6 +258,7 @@
     put_byte(pb,flags);
     put_buffer(pb, pkt->data, size);
     put_be32(pb,size+1+11); // previous tag size
+    flv->duration = pkt->pts + pkt->duration;
 
     put_flush_packet(pb);
     return 0;