forked from kenzuya/unshackle
fix(manifests): skip a DASH Representation or HLS variant with an unknown codec
This commit is contained in:
@@ -57,9 +57,13 @@ def test_index_lists_every_known_failure() -> None:
|
||||
|
||||
|
||||
@pytest.mark.parametrize("entry", cases(INDEX))
|
||||
def test_manifest_parses_to_tracks(entry: dict[str, Any]) -> None:
|
||||
def test_manifest_parses_to_tracks(entry: dict[str, Any], caplog: pytest.LogCaptureFixture) -> None:
|
||||
tracks = parse(entry)
|
||||
|
||||
assert not [
|
||||
r for r in caplog.records if r.getMessage().startswith(("Skipped DASH Representation", "Skipped HLS variant"))
|
||||
]
|
||||
|
||||
assert tracks.videos or tracks.audio or tracks.subtitles
|
||||
for track in tracks:
|
||||
# HLS CODECS is only a SHOULD (RFC 8216 4.3.4.2), so an HLS track can honestly have none
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
from langcodes import Language
|
||||
|
||||
from unshackle.core.manifests import DASH, HLS
|
||||
|
||||
MPD = """<?xml version="1.0"?>
|
||||
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" type="static" mediaPresentationDuration="PT10S">
|
||||
<Period>
|
||||
<AdaptationSet contentType="video" mimeType="video/mp4" lang="en">
|
||||
<SegmentTemplate media="$RepresentationID$/$Number$.m4s" initialization="$RepresentationID$/init.mp4" duration="2" />
|
||||
<Representation id="v1" codecs="avc1.640028" bandwidth="5000000" width="1920" height="1080" />
|
||||
<Representation id="v2" codecs="zzzz" bandwidth="4000000" width="1920" height="1080" />
|
||||
</AdaptationSet>
|
||||
<AdaptationSet contentType="audio" mimeType="audio/mp4" lang="en">
|
||||
<SegmentTemplate media="$RepresentationID$/$Number$.m4s" initialization="$RepresentationID$/init.mp4" duration="2" />
|
||||
<Representation id="a1" codecs="mp4a.40.2" bandwidth="128000" />
|
||||
<Representation id="a2" codecs="zzzz" bandwidth="96000" />
|
||||
</AdaptationSet>
|
||||
<AdaptationSet contentType="text" mimeType="application/mp4" lang="en">
|
||||
<SegmentTemplate media="$RepresentationID$/$Number$.m4s" initialization="$RepresentationID$/init.mp4" duration="2" />
|
||||
<Representation id="t1" codecs="wvtt" bandwidth="1000" />
|
||||
<Representation id="t2" codecs="zzzz" bandwidth="1000" />
|
||||
</AdaptationSet>
|
||||
<AdaptationSet contentType="text" mimeType="text/zzzz" lang="en">
|
||||
<Representation id="t3" bandwidth="1000"><BaseURL>t3.zzzz</BaseURL></Representation>
|
||||
</AdaptationSet>
|
||||
</Period>
|
||||
</MPD>"""
|
||||
|
||||
MASTER = """#EXTM3U
|
||||
#EXT-X-STREAM-INF:BANDWIDTH=5000000,CODECS="avc1.640028,mp4a.40.2",RESOLUTION=1920x1080
|
||||
good.m3u8
|
||||
#EXT-X-STREAM-INF:BANDWIDTH=4000000,CODECS="zzzz",RESOLUTION=1920x1080
|
||||
bad.m3u8
|
||||
#EXT-X-STREAM-INF:BANDWIDTH=3000000,CODECS="zzzz,mp4a.40.2",RESOLUTION=1920x1080
|
||||
muxed.m3u8?sig=secret
|
||||
#EXT-X-STREAM-INF:BANDWIDTH=128000,CODECS="mp4a.40.2"
|
||||
audio.m3u8
|
||||
"""
|
||||
|
||||
|
||||
def test_dash_skips_each_representation_with_an_unknown_codec(caplog: pytest.LogCaptureFixture) -> None:
|
||||
with caplog.at_level(logging.WARNING, logger="DASH"):
|
||||
tracks = DASH.from_text(MPD, url="https://cdn.example/manifest.mpd").to_tracks(language="en")
|
||||
ids = [t.data["dash"]["representation_id"] for t in (*tracks.videos, *tracks.audio, *tracks.subtitles)]
|
||||
assert ids == ["v1", "a1", "t1"]
|
||||
warnings = [r.getMessage() for r in caplog.records if r.levelno == logging.WARNING]
|
||||
assert warnings == [
|
||||
f"Skipped DASH Representation '{i}': unsupported codec 'zzzz'" for i in ("v2", "a2", "t2", "t3")
|
||||
]
|
||||
|
||||
|
||||
def test_hls_skips_a_variant_with_an_unknown_codec(caplog: pytest.LogCaptureFixture) -> None:
|
||||
with caplog.at_level(logging.WARNING, logger="HLS"):
|
||||
tracks = HLS.from_text(MASTER, url="https://cdn.example/master.m3u8").to_tracks(Language.get("en"))
|
||||
assert [str(v.url).rsplit("/", 1)[-1] for v in tracks.videos] == ["good.m3u8"]
|
||||
assert [str(a.url).rsplit("/", 1)[-1] for a in tracks.audio] == ["audio.m3u8"]
|
||||
warnings = [r.getMessage() for r in caplog.records if r.levelno == logging.WARNING]
|
||||
assert warnings == [
|
||||
"Skipped HLS variant 'bad.m3u8': unsupported codec 'zzzz'",
|
||||
"Skipped HLS variant 'muxed.m3u8': unsupported codec 'zzzz,mp4a.40.2'",
|
||||
]
|
||||
|
||||
|
||||
def test_dash_with_no_supported_codec_raises() -> None:
|
||||
mpd = MPD.replace('codecs="avc1.640028"', 'codecs="zzzz"').replace('codecs="mp4a.40.2"', 'codecs="zzzz"')
|
||||
mpd = mpd.replace('codecs="wvtt"', 'codecs="zzzz"')
|
||||
with pytest.raises(ValueError, match="No DASH Representation has a supported codec: 7 skipped"):
|
||||
DASH.from_text(mpd, url="https://cdn.example/manifest.mpd").to_tracks(language="en")
|
||||
|
||||
|
||||
def test_hls_with_no_supported_codec_raises() -> None:
|
||||
master = '#EXTM3U\n#EXT-X-STREAM-INF:BANDWIDTH=4000000,CODECS="zzzz"\nbad.m3u8\n'
|
||||
with pytest.raises(ValueError, match="No HLS variant has a supported codec: 1 skipped"):
|
||||
HLS.from_text(master, url="https://cdn.example/master.m3u8").to_tracks(Language.get("en"))
|
||||
Reference in New Issue
Block a user