From patchwork Mon Aug 17 07:11:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 21687 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 6751844AE7A for ; Mon, 17 Aug 2020 10:12:03 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4ADFF68B736; Mon, 17 Aug 2020 10:12:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpproxy21.qq.com (smtpbg704.qq.com [203.205.195.105]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D2FE168B67A for ; Mon, 17 Aug 2020 10:11:56 +0300 (EEST) X-QQ-mid: bizesmtp17t1597648309txh92oum Received: from localhost (unknown [103.107.216.230]) by esmtp6.qq.com (ESMTP) with id ; Mon, 17 Aug 2020 15:11:48 +0800 (CST) X-QQ-SSF: 01100000002000Z0Z000000A0000000 X-QQ-FEAT: WFR8qqsZY3c+LzRWnDuOdCXSv1pFY4UO+pF2u9jpH4vDddcQkN++6f0TwLM7i +N3TV8ub/p6CPOOE1n0olrDeU41nm+/ZGQ6+oG5IBXJFwVmKUPop2PM8Z+4vUhvVobgAoFk c9TBRlRYKvCy2TWJ3f3MUGM32LlCGkVPbOLj1ETd4htzFxcavGLOpl6KF2efV3XnN9yEJ9a XrpkoulwLBkGjk4SP6hj2AlSxIlUZ1rOUr/5goMg5+js+3EOuwfYuzrErKPC1lCDKgNEga8 qWuQQ8TDBhYGegtsyYKduZDu54I4XTgT/IZReJcWPOVwpHvmoM0YHy2pnH1T2wOklNYw== X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 Aug 2020 15:11:46 +0800 Message-Id: <20200817071146.73636-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:chinaffmpeg.org:qybgforeign:qybgforeign5 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH] avformat/hlsenc: check the segment duration valid 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Output a warning message if the target duration of the segment is negative. Suggest user increase the hls_time value, and modify the target duration to one packet duration, because there maybe have bframe and then split not by keyframe, and the segment is very very small. Signed-off-by: Steven Liu --- libavformat/hlsenc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index cb31d6aed7..79ee39aa23 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -2512,6 +2512,12 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) if (vs->start_pos || hls->segment_type != SEGMENT_TYPE_FMP4) { double cur_duration = (double)(pkt->pts - vs->end_pts) * st->time_base.num / st->time_base.den; + if (cur_duration < 0) { + av_log(s, AV_LOG_WARNING, "The target duration incorrect, maybe you splited a too short segment, " + "you should increase the hls_time, " + "now the duration will set to 1 packet duration, but maybe incorrect too.\n"); + cur_duration = vs->duration; + } ret = hls_append_segment(s, hls, vs, cur_duration, vs->start_pos, vs->size); vs->end_pts = pkt->pts; vs->duration = 0;