]> git.sesse.net Git - ffmpeg/commitdiff
avformat/hlsenc: compute segment duration use current pts minus last segment end pts
authorSteven Liu <lq@chinaffmpeg.org>
Wed, 29 Apr 2020 12:39:22 +0000 (20:39 +0800)
committerSteven Liu <lq@chinaffmpeg.org>
Wed, 6 May 2020 03:32:26 +0000 (11:32 +0800)
segment duration is using vs duration which compute by frame per second,
that can not fix problem of VFR video stream, so compute the duration
when split the segment, set the segment target duration use
current packet pts minus the prev segment end pts..

Reported-by: Zhao Jun <barryjzhao@tencent.com>
Reviewed-by: Zhao Jun <barryjzhao@tencent.com>
Signed-off-by: Steven Liu <liuqi05@kuaishou.com>
libavformat/hlsenc.c

index 008a3f3947e99eb326d8575ec780705c2376ad8d..10984dddb8cc8120df56f9a49e2f5b60d02290f9 100644 (file)
@@ -2463,7 +2463,8 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
         }
 
         if (vs->start_pos || hls->segment_type != SEGMENT_TYPE_FMP4) {
-            ret = hls_append_segment(s, hls, vs, vs->duration, vs->start_pos, vs->size);
+            double cur_duration =  (double)(pkt->pts - vs->end_pts) * st->time_base.num / st->time_base.den;
+            ret = hls_append_segment(s, hls, vs, cur_duration, vs->start_pos, vs->size);
             vs->end_pts = pkt->pts;
             vs->duration = 0;
             if (ret < 0) {