[FFmpeg-devel] [PATCH] avformat/hlsenc: calculate bitrate for segments with duration < 0.5
Jack Lau
jacklau1222 at qq.com
Mon Mar 24 01:13:22 EET 2025
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 at 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
More information about the ffmpeg-devel
mailing list