[FFmpeg-devel] [PATCH] avformat/hlsenc: limit segments count to search duplicated segments filenames
Artem Smorodin
artem.smorodin at dacast.com
Sat Jul 26 19:09:54 EEST 2025
This linear search has a complexity of O(n). When ffmpeg attempts to
parse a playlist containing approximately 100,000 segments, it
effectively causes a hang for several minutes.
This patch limits the allowed size for duplicate searches to a
reasonable value. Now it takes between 0.5 and a few seconds (tested on
different devices) instead of several minutes.
Signed-off-by: Artem Smorodin <artem.smorodin at dacast.com>
---
libavformat/hlsenc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index a93d35ab75..d3db83093c 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -1172,7 +1172,7 @@ static int hls_append_segment(struct
AVFormatContext *s, HLSContext *hls,
if (hls->use_localtime_mkdir) {
filename = vs->avf->url;
}
- if ((find_segment_by_filename(vs->segments, filename) ||
find_segment_by_filename(vs->old_segments, filename))
+ if (vs->nb_entries <= 5000 &&
(find_segment_by_filename(vs->segments, filename) ||
find_segment_by_filename(vs->old_segments, filename))
&& !byterange_mode) {
av_log(hls, AV_LOG_WARNING, "Duplicated segment filename
detected: %s\n", filename);
}
--
2.43.0
More information about the ffmpeg-devel
mailing list