[libav-devel] [PATCH] hls: Correctly compute the duration

Luca Barbato lu_zero at gentoo.org
Fri Aug 14 17:02:03 CEST 2015


Use only the video packets to compute the duration the video
track is present.
---
 libavformat/hlsenc.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 21c9526..ee84032 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -278,9 +278,13 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
     }
     if (pkt->pts == AV_NOPTS_VALUE)
         can_split = 0;
-    else
-        hls->duration = av_rescale(pkt->pts - hls->end_pts,
-                                   st->time_base.num, st->time_base.den);
+    else {
+        if (!hls->has_video ||
+            st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+            hls->duration = av_rescale(pkt->pts - hls->end_pts,
+                                       st->time_base.num, st->time_base.den);
+    I   }
+    }
 
     if (can_split && av_compare_ts(pkt->pts - hls->start_pts, st->time_base,
                                    end_pts, AV_TIME_BASE_Q) >= 0) {
-- 
2.5.0



More information about the libav-devel mailing list