mirror of https://github.com/streamlink/streamlink
stream.dash: fix segment duration
Fix segment duration in representations without a segment list or segment template and add test for segments of this kind.
This commit is contained in:
parent
88772da939
commit
98355078f1
|
@ -664,7 +664,7 @@ class Representation(_RepresentationBaseType):
|
||||||
yield Segment(
|
yield Segment(
|
||||||
url=self.base_url,
|
url=self.base_url,
|
||||||
number=None,
|
number=None,
|
||||||
duration=None,
|
duration=self.period.duration.total_seconds() or self.root.mediaPresentationDuration.total_seconds(),
|
||||||
available_at=self.period.availabilityStartTime,
|
available_at=self.period.availabilityStartTime,
|
||||||
init=True,
|
init=True,
|
||||||
content=True,
|
content=True,
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<MPD
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="urn:mpeg:dash:schema:mpd:2011"
|
||||||
|
xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 DASH-MPD.xsd"
|
||||||
|
type="static"
|
||||||
|
mediaPresentationDuration="PT3256S"
|
||||||
|
minBufferTime="PT1.2S"
|
||||||
|
profiles="urn:mpeg:dash:profile:isoff-on-demand:2011"
|
||||||
|
>
|
||||||
|
<BaseURL>http://cdn1.example.com/</BaseURL>
|
||||||
|
<BaseURL>http://cdn2.example.com/</BaseURL>
|
||||||
|
<Period>
|
||||||
|
<!-- English Audio -->
|
||||||
|
<AdaptationSet mimeType="audio/mp4" codecs="mp4a.40" lang="en" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
|
||||||
|
<Representation id="1" bandwidth="64000">
|
||||||
|
<BaseURL>7657412348.mp4</BaseURL>
|
||||||
|
</Representation>
|
||||||
|
<Representation id="2" bandwidth="32000">
|
||||||
|
<BaseURL>3463646346.mp4</BaseURL>
|
||||||
|
</Representation>
|
||||||
|
</AdaptationSet>
|
||||||
|
<!-- French Audio -->
|
||||||
|
<AdaptationSet mimeType="audio/mp4" codecs="mp4a.40.2" lang="fr" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
|
||||||
|
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="dub"/>
|
||||||
|
<Representation id="3" bandwidth="64000">
|
||||||
|
<BaseURL>3463275477.mp4</BaseURL>
|
||||||
|
</Representation>
|
||||||
|
<Representation id="4" bandwidth="32000">
|
||||||
|
<BaseURL>5685763463.mp4</BaseURL>
|
||||||
|
</Representation>
|
||||||
|
</AdaptationSet>
|
||||||
|
<!-- Timed text -->
|
||||||
|
<AdaptationSet mimeType="application/ttml+xml" lang="de">
|
||||||
|
<Role schemeIdUri="urn:mpeg:dash:role" value="subtitle"/>
|
||||||
|
<Representation id="5" bandwidth="256">
|
||||||
|
<BaseURL>796735657.xml</BaseURL>
|
||||||
|
</Representation>
|
||||||
|
</AdaptationSet>
|
||||||
|
<!-- Video -->
|
||||||
|
<AdaptationSet mimeType="video/mp4" codecs="avc1.4d0228" subsegmentAlignment="true" subsegmentStartsWithSAP="2">
|
||||||
|
<Representation id="6" bandwidth="256000" width="320" height="240">
|
||||||
|
<BaseURL>8563456473.mp4</BaseURL>
|
||||||
|
</Representation>
|
||||||
|
<Representation id="7" bandwidth="512000" width="320" height="240">
|
||||||
|
<BaseURL>56363634.mp4</BaseURL>
|
||||||
|
</Representation>
|
||||||
|
<Representation id="8" bandwidth="1024000" width="640" height="480">
|
||||||
|
<BaseURL>562465736.mp4</BaseURL>
|
||||||
|
</Representation>
|
||||||
|
<Representation id="9" bandwidth="1384000" width="640" height="480">
|
||||||
|
<BaseURL>41325645.mp4</BaseURL>
|
||||||
|
</Representation>
|
||||||
|
<Representation id="A" bandwidth="1536000" width="1280" height="720">
|
||||||
|
<BaseURL>89045625.mp4</BaseURL>
|
||||||
|
</Representation>
|
||||||
|
<Representation id="B" bandwidth="2048000" width="1280" height="720">
|
||||||
|
<BaseURL>23536745734.mp4</BaseURL>
|
||||||
|
</Representation>
|
||||||
|
</AdaptationSet>
|
||||||
|
</Period>
|
||||||
|
</MPD>
|
|
@ -92,6 +92,41 @@ class TestMPDParsers(unittest.TestCase):
|
||||||
class TestMPDParser(unittest.TestCase):
|
class TestMPDParser(unittest.TestCase):
|
||||||
maxDiff = None
|
maxDiff = None
|
||||||
|
|
||||||
|
def test_no_segment_list_or_template(self):
|
||||||
|
with xml("dash/test_no_segment_list_or_template.mpd") as mpd_xml:
|
||||||
|
mpd = MPD(mpd_xml, base_url="http://test/", url="http://test/manifest.mpd")
|
||||||
|
segments = [
|
||||||
|
{
|
||||||
|
"ident": representation.ident,
|
||||||
|
"mimeType": representation.mimeType,
|
||||||
|
"segments": [
|
||||||
|
(segment.url, segment.number, segment.duration, segment.available_at, segment.init, segment.content)
|
||||||
|
for segment in itertools.islice(representation.segments(), 100)
|
||||||
|
],
|
||||||
|
}
|
||||||
|
for adaptationset in mpd.periods[0].adaptationSets for representation in adaptationset.representations
|
||||||
|
if representation.id in ("1", "5", "6")
|
||||||
|
]
|
||||||
|
availability = datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=UTC)
|
||||||
|
|
||||||
|
assert segments == [
|
||||||
|
{
|
||||||
|
"ident": (None, None, "1"),
|
||||||
|
"mimeType": "audio/mp4",
|
||||||
|
"segments": [("http://cdn1.example.com/7657412348.mp4", None, 3256.0, availability, True, True)],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ident": (None, None, "5"),
|
||||||
|
"mimeType": "application/ttml+xml",
|
||||||
|
"segments": [("http://cdn1.example.com/796735657.xml", None, 3256.0, availability, True, True)],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ident": (None, None, "6"),
|
||||||
|
"mimeType": "video/mp4",
|
||||||
|
"segments": [("http://cdn1.example.com/8563456473.mp4", None, 3256.0, availability, True, True)],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
def test_segments_number_time(self):
|
def test_segments_number_time(self):
|
||||||
with xml("dash/test_1.mpd") as mpd_xml:
|
with xml("dash/test_1.mpd") as mpd_xml:
|
||||||
mpd = MPD(mpd_xml, base_url="http://test.se/", url="http://test.se/manifest.mpd")
|
mpd = MPD(mpd_xml, base_url="http://test.se/", url="http://test.se/manifest.mpd")
|
||||||
|
|
Loading…
Reference in New Issue