---
 libavformat/flvenc.c |   23 ++++++++++++-----------
 1 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/libavformat/flvenc.c b/libavformat/flvenc.c
index cf77157..97d224d 100644
--- a/libavformat/flvenc.c
+++ b/libavformat/flvenc.c
@@ -57,8 +57,8 @@ typedef struct FLVContext {
     int64_t duration_offset;
     int64_t filesize_offset;
     int64_t duration;
-    int delay; ///< first dts delay for AVC
-    int64_t last_ts;
+    int delay[2];               ///< first dts delay for each stream (needed 
for AVC & Speex)
+    int64_t last_ts[2];         ///< last timestamp for each stream
 } FLVContext;
 
 static int get_audio_flags(AVCodecContext *enc){
@@ -215,7 +215,7 @@ static int flv_write_header(AVFormatContext *s)
         }
     }
 
-    flv->last_ts = -1;
+    flv->last_ts[0] = flv->last_ts[1] = -1;
 
     /* write meta_tag */
     avio_w8(pb, 18);         // tag type META
@@ -344,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_ts);
+            put_avc_eos_tag(pb, flv->last_ts[0]);
         }
     }
 
@@ -369,6 +369,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
     int size= pkt->size;
     uint8_t *data= NULL;
     int flags, flags_size;
+    int is_audio = (enc->codec_type == AVMEDIA_TYPE_AUDIO);
 
 //    av_log(s, AV_LOG_DEBUG, "type:%d pts: %"PRId64" size:%d\n", 
enc->codec_type, timestamp, size);
 
@@ -406,20 +407,20 @@ static int flv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
                 return -1;
         }
     }
-    if (!flv->delay && pkt->dts < 0)
-        flv->delay = -pkt->dts;
+    if (!flv->delay[is_audio] && pkt->dts < 0)
+        flv->delay[is_audio] = -pkt->dts;
 
-    ts = pkt->dts + flv->delay; // add delay to force positive dts
+    ts = pkt->dts + flv->delay[is_audio]; // add delay to force positive dts
 
     /* check Speex packet duration */
-    if (enc->codec_id == CODEC_ID_SPEEX && ts - flv->last_ts > 160) {
+    if (enc->codec_id == CODEC_ID_SPEEX && ts - flv->last_ts[1] > 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;
+    if (flv->last_ts[is_audio] < ts)
+        flv->last_ts[is_audio] = ts;
 
     avio_wb24(pb,size + flags_size);
     avio_wb24(pb,ts);
@@ -440,7 +441,7 @@ static int flv_write_packet(AVFormatContext *s, AVPacket 
*pkt)
     avio_write(pb, data ? data : pkt->data, size);
 
     avio_wb32(pb,size+flags_size+11); // previous tag size
-    flv->duration = FFMAX(flv->duration, pkt->pts + flv->delay + 
pkt->duration);
+    flv->duration = FFMAX(flv->duration, pkt->pts + flv->delay[is_audio] + 
pkt->duration);
 
     avio_flush(pb);
 
-- 
1.7.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to