From c45388b193e3a111b91b22245036f8715b93a4a2 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sun, 10 Dec 2006 17:12:45 +0000 Subject: [PATCH] set flags correctly in write header instead of seeking back and fixing it in write_trailer() Originally committed as revision 7267 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavformat/flvenc.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index 76fa2ca..fc332e1 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -110,12 +110,6 @@ static int flv_write_header(AVFormatContext *s) flv->hasAudio = 0; flv->hasVideo = 0; - put_tag(pb,"FLV"); - put_byte(pb,1); - put_byte(pb,0); // delayed write - put_be32(pb,9); - put_be32(pb,0); - for(i=0; inb_streams; i++){ AVCodecContext *enc = s->streams[i]->codec; if (enc->codec_type == CODEC_TYPE_VIDEO) { @@ -130,9 +124,20 @@ static int flv_write_header(AVFormatContext *s) } else { flv->hasAudio=1; samplerate = enc->sample_rate; + if(get_audio_flags(enc)<0) + return -1; } av_set_pts_info(s->streams[i], 24, 1, 1000); /* 24 bit pts in ms */ - if(enc->codec_tag == 5){ + } + put_tag(pb,"FLV"); + put_byte(pb,1); + put_byte(pb, FLV_HEADER_FLAG_HASAUDIO * flv->hasAudio + + FLV_HEADER_FLAG_HASVIDEO * flv->hasVideo); + put_be32(pb,9); + put_be32(pb,0); + + for(i=0; inb_streams; i++){ + if(s->streams[i]->codec->codec_tag == 5){ put_byte(pb,8); // message type put_be24(pb,0); // include flags put_be24(pb,0); // time stamp @@ -140,8 +145,6 @@ static int flv_write_header(AVFormatContext *s) put_be32(pb,11); // size flv->reserved=5; } - if(enc->codec_type == CODEC_TYPE_AUDIO && get_audio_flags(enc)<0) - return -1; } /* write meta_tag */ @@ -204,16 +207,11 @@ static int flv_write_header(AVFormatContext *s) static int flv_write_trailer(AVFormatContext *s) { int64_t file_size; - int flags = 0; ByteIOContext *pb = &s->pb; FLVContext *flv = s->priv_data; file_size = url_ftell(pb); - flags |= flv->hasAudio ? FLV_HEADER_FLAG_HASAUDIO : 0; - flags |= flv->hasVideo ? FLV_HEADER_FLAG_HASVIDEO : 0; - url_fseek(pb, 4, SEEK_SET); - put_byte(pb,flags); /* update informations */ url_fseek(pb, flv->duration_offset, SEEK_SET); -- 2.7.4