From patchwork Mon Jan 9 17:06:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 2143 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp7141131vsb; Mon, 9 Jan 2017 09:06:53 -0800 (PST) X-Received: by 10.194.103.5 with SMTP id fs5mr66170776wjb.227.1483981613336; Mon, 09 Jan 2017 09:06:53 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id d83si4098254wmc.151.2017.01.09.09.06.52; Mon, 09 Jan 2017 09:06:53 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C5F5B68A570; Mon, 9 Jan 2017 19:06:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbguseast2.qq.com (smtpbguseast2.qq.com [54.204.34.130]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3EEB1689FC0 for ; Mon, 9 Jan 2017 19:06:36 +0200 (EET) X-QQ-mid: bizesmtp13t1483981576tkqir7w8 Received: from localhost (unknown [47.90.47.25]) by esmtp4.qq.com (ESMTP) with id ; Tue, 10 Jan 2017 01:06:15 +0800 (CST) X-QQ-SSF: 01100000008000F0F621B00A0000000 X-QQ-FEAT: 6dXuswn9i1VlCpXY+b4xGko1o/YjKJ7vWfFmuOdgpMJxKqqSNyaELLNupYU/x t1CePFXTg3Iaxc3WVS2cBNjm6hvWgP9oAv+nhI7BU7/H++IdJoShUnk+MKDArlve0i5Ifch tjwdWuq6vc0tDn10qOmvbMUwf+uPrlK5Srwf1gDAzz0i8w9PJ2/qglNax7ptiHjZ217BxRs nmRk27mhgE7uPTJ/hMt0MKD0t43rlRE8ssIQvi++4fovybhpYmVdaoIpweH/q10mt7y7KgR 1ETw== X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Tue, 10 Jan 2017 01:06:04 +0800 Message-Id: <20170109170604.26801-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.10.1.382.ga23ca1b.dirty X-QQ-SENDSIZE: 520 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH] avformat/hlsenc: fix hls start and tail segment duration problem X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Steven Liu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" fix ticket: #6067 Signed-off-by: Steven Liu --- libavformat/hlsenc.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index eeb450a..0fcb699 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -103,6 +103,7 @@ typedef struct HLSContext { int64_t recording_time; int has_video; int has_subtitle; + double dpp; // duration per packet int64_t start_pts; int64_t end_pts; double duration; // last segment duration computed so far, in seconds @@ -1216,10 +1217,16 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) if (pkt->pts == AV_NOPTS_VALUE) is_ref_pkt = can_split = 0; - if (is_ref_pkt) - hls->duration = (double)(pkt->pts - hls->end_pts) - * st->time_base.num / st->time_base.den; + if (is_ref_pkt) { + if (!hls->start_pos) { + hls->duration = (double)(pkt->pts - hls->end_pts) + * st->time_base.num / st->time_base.den; + hls->dpp = (double)(pkt->duration) * st->time_base.num / st->time_base.den; + } else { + hls->duration += (double)(pkt->duration) * st->time_base.num / st->time_base.den; + } + } if (can_split && av_compare_ts(pkt->pts - hls->start_pts, st->time_base, end_pts, AV_TIME_BASE_Q) >= 0) { int64_t new_start_pos; @@ -1289,7 +1296,8 @@ static int hls_write_trailer(struct AVFormatContext *s) if (oc->pb) { hls->size = avio_tell(hls->avf->pb) - hls->start_pos; ff_format_io_close(s, &oc->pb); - hls_append_segment(s, hls, hls->duration, hls->start_pos, hls->size); + /* after av_write_trailer, then duration + 1 duration per packet */ + hls_append_segment(s, hls, hls->duration + hls->dpp, hls->start_pos, hls->size); } if (vtt_oc) {