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
This commit is contained in:
Andy
2025-11-02 20:30:06 +00:00
parent 597a8b7912
commit 27d0ca84a3

View File

@@ -384,7 +384,8 @@ class DASH:
segment_duration = float(segment_template.get("duration")) or 1 segment_duration = float(segment_template.get("duration")) or 1
if not end_number: 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): for s in range(start_number, end_number + 1):
segments.append( segments.append(