diff options
author | Baptiste Coudurier <baptiste.coudurier@gmail.com> | 2006-08-06 15:29:50 +0000 |
---|---|---|
committer | Baptiste Coudurier <baptiste.coudurier@gmail.com> | 2006-08-06 15:29:50 +0000 |
commit | 634b8cfaf4bf9eb3a8f6d99afbc1101d809f5f13 (patch) | |
tree | 385e93474a2a58a7ee891470ab7cf8131cbad4da /libavformat/flvenc.c | |
parent | fb2d9140e42d247fd679ff13c0f49aab6c913d08 (diff) | |
download | ffmpeg-634b8cfaf4bf9eb3a8f6d99afbc1101d809f5f13.tar.gz |
always write duration and file size, fix seeking, progress bar is now active
Originally committed as revision 5939 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/flvenc.c')
-rw-r--r-- | libavformat/flvenc.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index de1dd0801b..d646e49617 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -25,6 +25,9 @@ typedef struct FLVContext { 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 @@ static int flv_write_header(AVFormatContext *s) /* 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 @@ static int flv_write_header(AVFormatContext *s) 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 @@ static int flv_write_trailer(AVFormatContext *s) 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 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) 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; |