From 27d0ca84a3a0e8bf1d0b408a1328ad5aa78728fa Mon Sep 17 00:00:00 2001 From: Andy Date: Sun, 2 Nov 2025 20:30:06 +0000 Subject: [PATCH] fix(dash): correct segment count calculation for startNumber=0 Fix off-by-one error in SegmentTemplate segment enumeration when startNumber is 0. Previously, the code would request one extra segment beyond what exists, causing 404 errors on the final segment. The issue was that end_number was calculated as a segment count via math.ceil(), but then used incorrectly with range(start_number, end_number + 1), treating it as both a count and an inclusive endpoint. Changed to explicitly calculate segment_count first, then derive end_number as: start_number + segment_count - 1 Example: - Duration: 3540.996s, segment duration: 4s - Before: segments 0-886 (887 segments) - segment 886 doesn't exist - After: segments 0-885 (886 segments) - correct --- unshackle/core/manifests/dash.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unshackle/core/manifests/dash.py b/unshackle/core/manifests/dash.py index 56fec08..152c274 100644 --- a/unshackle/core/manifests/dash.py +++ b/unshackle/core/manifests/dash.py @@ -384,7 +384,8 @@ class DASH: segment_duration = float(segment_template.get("duration")) or 1 if not end_number: - end_number = math.ceil(period_duration / (segment_duration / segment_timescale)) + segment_count = math.ceil(period_duration / (segment_duration / segment_timescale)) + end_number = start_number + segment_count - 1 for s in range(start_number, end_number + 1): segments.append(