mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-17 22:45:06 +00:00
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.
This commit is contained in:
@@ -744,7 +744,8 @@ class HLS:
|
|||||||
if include_map_data and map_data and map_data[1]:
|
if include_map_data and map_data and map_data[1]:
|
||||||
x.write(map_data[1])
|
x.write(map_data[1])
|
||||||
for file in via:
|
for file in via:
|
||||||
x.write(file.read_bytes())
|
with open(file, "rb") as segment:
|
||||||
|
shutil.copyfileobj(segment, x, 1024 * 1024)
|
||||||
x.flush()
|
x.flush()
|
||||||
if delete:
|
if delete:
|
||||||
file.unlink()
|
file.unlink()
|
||||||
@@ -1005,8 +1006,8 @@ class HLS:
|
|||||||
else:
|
else:
|
||||||
with open(save_path, "wb") as f:
|
with open(save_path, "wb") as f:
|
||||||
for discontinuity_file in segments_to_merge:
|
for discontinuity_file in segments_to_merge:
|
||||||
discontinuity_data = discontinuity_file.read_bytes()
|
with open(discontinuity_file, "rb") as src:
|
||||||
f.write(discontinuity_data)
|
shutil.copyfileobj(src, f, 1024 * 1024)
|
||||||
f.flush()
|
f.flush()
|
||||||
os.fsync(f.fileno())
|
os.fsync(f.fileno())
|
||||||
discontinuity_file.unlink()
|
discontinuity_file.unlink()
|
||||||
|
|||||||
Reference in New Issue
Block a user