[FFmpeg-cvslog] avformat/hlsenc: limit segments count to search duplicated segments filenames
Artem Smorodin
git at videolan.org
Mon Jul 28 20:06:08 EEST 2025
ffmpeg | branch: master | Artem Smorodin <artem.smorodin at dacast.com> | Sat Jul 26 19:09:54 2025 +0300| [0a108a37e15732ee61ee1f4be18553865f10bde4] | committer: Michael Niedermayer
avformat/hlsenc: limit segments count to search duplicated segments filenames
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>
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0a108a37e15732ee61ee1f4be18553865f10bde4
---
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);
}
More information about the ffmpeg-cvslog
mailing list