From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id 20A654879F
	for <ffmpegdev@gitmailbox.com>; Sun, 23 Mar 2025 23:13:42 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 46D91687B09;
	Mon, 24 Mar 2025 01:13:39 +0200 (EET)
Received: from out162-62-57-210.mail.qq.com (out162-62-57-210.mail.qq.com
 [162.62.57.210])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 217BC687A4A
 for <ffmpeg-devel@ffmpeg.org>; Mon, 24 Mar 2025 01:13:31 +0200 (EET)
Received: from localhost.localdomain ([111.30.83.130])
 by newxmesmtplogicsvrszb16-1.qq.com (NewEsmtp) with SMTP
 id 35990020; Mon, 24 Mar 2025 07:13:25 +0800
X-QQ-mid: xmsmtpt1742771605t2nx3q0y5
Message-ID: <tencent_1D2850575A172F11274023BAB3497C3D6308@qq.com>
X-QQ-XMAILINFO: N89bjyf9tBCOdTFlAZCQ9KOA9y7dgmkkqqAfs8vBAN83lcwBGbPevCALu/8IR8
 fnaM+VFvvHXYTOSb6ODD/v7X7+MGjV2+OnOqjSnmm8nEws9iHPSRMXGw3dzOfJu9wQUaztkT8ncu
 xX3j8UbxW5E0Re4x3Lz4EN78hO+ZiIIYzekJeQpqeKgs8KC2/295MVyuoyWGz+yrYzrKYddEmnVw
 BQvoIF0c6j9CZhKRUDZ9uVAGeB2brkSgnc/Dd+nsI4+WF5d1ALwbNQ5zxspZb6h/t7dN9ByTADtQ
 bG+Oj16DHtCMstKjGS4AjDUPecst/5mj0kOcLGDelIAC1abUmpMtRiUVEjZzzW51zRoxHzPX3LDJ
 B+rg4ISwt3efIq9NT+IgtDPN6FN9KZ5s5ZBYSgqE5ZtUh2IKGssnF7v1B9IAmM6yF3aLsLo38BT9
 6XKKKKWtSophNpTSUQKOtb6SNiyKDkeYtchaBXJxxuTB6babYXZIUQ6/DC648F//yyXE6kdMU5zq
 md/GwNX/+hjWc7pwW6FZKHPxkTXu2yqQxzO2ijAfoCJhP9FnnVk/ofhYaq81HVDObsQpYzhMEBll
 iXSNmJ+7DH7ieaY30LmJu7So7+3cenQbmbXQQfbv1nq+QYzsGg43EDKLO5mSLwWmZWndP3oRyO/1
 EHmohwl93Jy3dCdk0v/wYeQ/s0VMLJdd+hqVdocstg8/tik6V6L0SD9Gl0uug45vH2AsAftVT07B
 /8+YzoSyxkY+YUdtZp/I5hw+L0szlJ8z3wtAmwf3lqEPyJDzAfIApnSv5em1mY5xofHRigJBUQoW
 aiK3JHHD8SJxzzB5cNuLquCL1rTIJISLgqwAijDwFxfCoQDWWZwpKSFnrIF4ciXG1/ijmqXa9NOq
 udRBrp4r+oPQnRP+nQYkq+CL0c7fxIeGCs/GuUJ1lYMZyCLvlfGPfV7TtlEe33JQ==
X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk=
To: ffmpeg-devel@ffmpeg.org
Date: Mon, 24 Mar 2025 07:13:22 +0800
X-OQ-MSGID: <20250323231322.32467-1-jacklau1222@qq.com>
X-Mailer: git-send-email 2.47.1
MIME-Version: 1.0
Subject: [FFmpeg-devel] [PATCH] avformat/hlsenc: calculate bitrate for
 segments with duration < 0.5
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
From: Jack Lau via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Jack Lau <jacklau1222@qq.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/tencent_1D2850575A172F11274023BAB3497C3D6308@qq.com/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

The previous code sets the bitrate to be calculated only when duration>0.5, which is obviously not general enough.

In some scenarios, we may need to set hls_time<0.5, then the generated segments are all <0.5. At this time, because the bitrate is not calculated, max_bitrate is empty, and ff_hls_write_stream_info cannot write stream info normally, causing master_pl to be unavailable.

Signed-off-by: Jack Lau <jacklau1222@qq.com>
---
 libavformat/hlsenc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index c6ffdb99e5..223c516103 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1150,9 +1150,7 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls,
 
     vs->total_size += size;
     vs->total_duration += duration;
-    if (duration > 0.5) {
-        // Don't include the final, possibly very short segment in the
-        // calculation of the max bitrate.
+    if (duration > 0) {
         int cur_bitrate = (int)(8 * size / duration);
         if (cur_bitrate > vs->max_bitrate)
             vs->max_bitrate = cur_bitrate;
-- 
2.47.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".