From efb560f887955aef07d3aa475ea1c296bc5b15e6 Mon Sep 17 00:00:00 2001 From: imSp4rky Date: Mon, 29 Jun 2026 09:31:38 -0600 Subject: [PATCH] fix(hls): stream segment merges to avoid OOM on large tracks Replace whole-file read_bytes() in merge()/discontinuity merge with shutil.copyfileobj (1MB buffer); fixes MemoryError on multi-GB tracks. --- unshackle/core/manifests/hls.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/unshackle/core/manifests/hls.py b/unshackle/core/manifests/hls.py index 0b08b455..8a15f850 100644 --- a/unshackle/core/manifests/hls.py +++ b/unshackle/core/manifests/hls.py @@ -744,7 +744,8 @@ class HLS: if include_map_data and map_data and map_data[1]: x.write(map_data[1]) for file in via: - x.write(file.read_bytes()) + with open(file, "rb") as segment: + shutil.copyfileobj(segment, x, 1024 * 1024) x.flush() if delete: file.unlink() @@ -1005,8 +1006,8 @@ class HLS: else: with open(save_path, "wb") as f: for discontinuity_file in segments_to_merge: - discontinuity_data = discontinuity_file.read_bytes() - f.write(discontinuity_data) + with open(discontinuity_file, "rb") as src: + shutil.copyfileobj(src, f, 1024 * 1024) f.flush() os.fsync(f.fileno()) discontinuity_file.unlink()