From 4ee247a2bdf2fbe81026a428d4affc46c81f28db Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 19 Oct 2011 13:20:15 -0400 Subject: flvenc: check packet duration in speex using timestamps Using AVCodecContext.frame_size is not reliable. --- libavformat/flvenc.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'libavformat/flvenc.c') diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c index 851ce491b0..cf77157636 100644 --- a/libavformat/flvenc.c +++ b/libavformat/flvenc.c @@ -58,7 +58,7 @@ typedef struct FLVContext { int64_t filesize_offset; int64_t duration; int delay; ///< first dts delay for AVC - int64_t last_video_ts; + int64_t last_ts; } FLVContext; static int get_audio_flags(AVCodecContext *enc){ @@ -75,11 +75,6 @@ static int get_audio_flags(AVCodecContext *enc){ av_log(enc, AV_LOG_ERROR, "flv only supports mono Speex audio\n"); return -1; } - if (enc->frame_size / 320 > 8) { - av_log(enc, AV_LOG_WARNING, "Warning: Speex stream has more than " - "8 frames per packet. Adobe Flash " - "Player cannot handle this!\n"); - } return FLV_CODECID_SPEEX | FLV_SAMPLERATE_11025HZ | FLV_SAMPLESSIZE_16BIT; } else { switch (enc->sample_rate) { @@ -220,7 +215,7 @@ static int flv_write_header(AVFormatContext *s) } } - flv->last_video_ts = -1; + flv->last_ts = -1; /* write meta_tag */ avio_w8(pb, 18); // tag type META @@ -349,7 +344,7 @@ static int flv_write_trailer(AVFormatContext *s) AVCodecContext *enc = s->streams[i]->codec; if (enc->codec_type == AVMEDIA_TYPE_VIDEO && enc->codec_id == CODEC_ID_H264) { - put_avc_eos_tag(pb, flv->last_video_ts); + put_avc_eos_tag(pb, flv->last_ts); } } @@ -415,10 +410,17 @@ static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) flv->delay = -pkt->dts; ts = pkt->dts + flv->delay; // add delay to force positive dts - if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { - if (flv->last_video_ts < ts) - flv->last_video_ts = ts; + + /* check Speex packet duration */ + if (enc->codec_id == CODEC_ID_SPEEX && ts - flv->last_ts > 160) { + av_log(s, AV_LOG_WARNING, "Warning: Speex stream has more than " + "8 frames per packet. Adobe Flash " + "Player cannot handle this!\n"); } + + if (flv->last_ts < ts) + flv->last_ts = ts; + avio_wb24(pb,size + flags_size); avio_wb24(pb,ts); avio_w8(pb,(ts >> 24) & 0x7F); // timestamps are 32bits _signed_ -- cgit v1.2.3