如何计算DASH媒体段名称中的$Time$变量?结合MPD播放列表示例详解
Calculating
$Time$ for DASH Segments & Getting Next Segment URL Let's walk through exactly how to compute the $Time$ variable for each segment in your provided MPD, plus how to find the next segment's URL.
First, let's recap the key parts of your MPD snippet for context:
<SegmentTemplate timescale="10000000" initialization="Video-$RepresentationID$-init.mp4" media="Video-$RepresentationID$-$Time$.mp4"> <SegmentTimeline> <S t="2083838574453329" d="100053337" /> <S d="100053332" r="1" /> <S d="99839999" /> <S d="100053337" /> </SegmentTimeline> </SegmentTemplate>
Core Definitions You Need to Know
Before diving into calculations, let's clarify what each attribute means:
timescale="10000000": This is the time unit all timestamps (t) and durations (d) use. You don't need to convert this value for$Time$—it's directly used in the media URL.<S>elements: Each represents a segment (or a repeating pattern of segments)t: The start timestamp of the segment (intimescaleunits). Only required for the first segment (or if there's a gap in the timeline).d: The duration of the segment (intimescaleunits).r: Number of times the segment is repeated. For example,r="1"means the segment pattern runs twice total (original + 1 repeat).
Step-by-Step $Time$ Calculation for Each Segment
Let's compute the $Time$ value for every segment in your timeline:
Segment 1 (first
<S>element)- The
tvalue is explicitly given:2083838574453329 $Time$ = 2083838574453329- Media URL:
Video-[YourRepresentationID]-2083838574453329.mp4
- The
Segment 2 (second
<S>element, first instance)- No
tprovided, so we calculate it as the end time of the previous segment:- Previous segment's end time = Segment 1's
t+ Segment 1'sd=2083838574453329 + 100053337 = 2083838674506666
- Previous segment's end time = Segment 1's
$Time$ = 2083838674506666
- No
Segment 3 (second
<S>element, repeated instance,r="1")- Since
r="1", we repeat the segment once. Calculate using the end time of Segment 2:- Segment 2's end time =
2083838674506666 + 100053332 = 2083838774559998
- Segment 2's end time =
$Time$ = 2083838774559998
- Since
Segment 4 (third
<S>element)- Use the end time of Segment 3:
2083838774559998 + 100053332 = 2083838874613330
$Time$ = 2083838874613330
- Use the end time of Segment 3:
Segment 5 (fourth
<S>element)- Use the end time of Segment 4:
2083838874613330 + 99839999 = 2083838974453329
$Time$ = 2083838974453329
- Use the end time of Segment 4:
Getting the Next Segment URL
To get the next segment's URL:
- Track which segment you're currently playing (e.g., if you're on Segment 3, next is Segment 4)
- Calculate the
$Time$value for the next segment using the rules above - Replace
$RepresentationID$with your target quality's ID (e.g.,1080p,720p) and$Time$with the calculated timestamp in themediatemplate string.
Quick Recap of Rules
- For the first segment: Use the explicit
tvalue if provided - For all subsequent segments:
$Time$ = Previous Segment's $Time$ + Previous Segment's $d$ - If a segment has
r="N": GenerateN+1total segments for that<S>element, each with$Time$incremented by the element'sdeach time
内容的提问来源于stack exchange,提问作者Boy
相关产品推荐
相关产品推荐

