mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-16 14:05:10 +00:00
feat(dash): flag dv profile 8 tracks from supplementalCodecs and use hdr10+dv as the hybrid
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from unshackle.core.manifests import DASH
|
||||
from unshackle.core.tracks import Video
|
||||
|
||||
MPD = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" xmlns:scte214="urn:scte:dash:scte214-extensions"
|
||||
type="static" mediaPresentationDuration="PT4S">
|
||||
<Period id="p0">
|
||||
<AdaptationSet contentType="video" mimeType="video/mp4">
|
||||
<EssentialProperty schemeIdUri="urn:mpeg:mpegB:cicp:ColourPrimaries" value="9"/>
|
||||
<EssentialProperty schemeIdUri="urn:mpeg:mpegB:cicp:TransferCharacteristics" value="16"/>
|
||||
<EssentialProperty schemeIdUri="urn:mpeg:mpegB:cicp:MatrixCoefficients" value="9"/>
|
||||
<Representation id="hdr" codecs="hvc1.2.4.L150.90" width="3840" height="1920" bandwidth="7000000"
|
||||
supplementalCodecs="dvh1.08.06" supplementalProfiles="db1p">
|
||||
<BaseURL>hdr.mp4</BaseURL><SegmentBase indexRange="0-99"/>
|
||||
</Representation>
|
||||
<Representation id="scte" codecs="hvc1.2.4.L120.90" width="1600" height="800" bandwidth="700000"
|
||||
scte214:supplementalCodecs="dvh1.08.03">
|
||||
<BaseURL>scte.mp4</BaseURL><SegmentBase indexRange="0-99"/>
|
||||
</Representation>
|
||||
<Representation id="plain" codecs="hvc1.2.4.L90.90" width="1024" height="512" bandwidth="400000">
|
||||
<BaseURL>plain.mp4</BaseURL><SegmentBase indexRange="0-99"/>
|
||||
</Representation>
|
||||
</AdaptationSet>
|
||||
<AdaptationSet contentType="video" mimeType="video/mp4">
|
||||
<Representation id="dv" codecs="dvh1.05.06" width="3840" height="1920" bandwidth="6800000"
|
||||
supplementalCodecs="dvh1.05.06">
|
||||
<BaseURL>dv.mp4</BaseURL><SegmentBase indexRange="0-99"/>
|
||||
</Representation>
|
||||
</AdaptationSet>
|
||||
</Period>
|
||||
</MPD>"""
|
||||
|
||||
|
||||
def test_a_dv_codec_in_supplemental_codecs_marks_an_hdr10_track_dv_compatible() -> None:
|
||||
videos = {
|
||||
v.data["dash"]["representation_id"]: v
|
||||
for v in DASH.from_text(MPD, url="https://example.test/m.mpd").to_tracks("en").videos
|
||||
}
|
||||
|
||||
assert {k: (v.range, v.dv_compatible_bitstream) for k, v in videos.items()} == {
|
||||
"hdr": (Video.Range.HDR10, True),
|
||||
"scte": (Video.Range.HDR10, True),
|
||||
"plain": (Video.Range.HDR10, False),
|
||||
"dv": (Video.Range.DV, False),
|
||||
}
|
||||
assert "[H.265, HDR10+DV]" in str(videos["hdr"])
|
||||
assert "[H.265, HDR10]" in str(videos["plain"])
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("codecs", "expected"),
|
||||
[
|
||||
("dvh1.08.06/db1p", True),
|
||||
("hvc1.2.4 dvhe.08.06", True),
|
||||
("hvc1.2.4.L150.90,DVH1.08.06", True),
|
||||
("cdm4", False),
|
||||
("hvc1.2.4.L150.90", False),
|
||||
(None, False),
|
||||
],
|
||||
)
|
||||
def test_has_dv_codec(codecs: str | None, expected: bool) -> None:
|
||||
assert Video.has_dv_codec(codecs) is expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("codec", "codecs", "supplemental", "expected"),
|
||||
[
|
||||
(Video.Codec.HEVC, "hvc1.2.4.L150.90", "dvh1.08.06", True),
|
||||
(Video.Codec.HEVC, "hev1.2.4.L150.90", "dvhe.08.06/db1p", True),
|
||||
(Video.Codec.AVC, "avc1.640028", "dvav.09.05/db2g", False),
|
||||
(Video.Codec.HEVC, "hvc1.2.4.L150.90", "dvav.09.05", False),
|
||||
(Video.Codec.HEVC, "dvh1.05.06", "dvh1.05.06", False),
|
||||
(None, None, "dvh1.08.06", False),
|
||||
],
|
||||
)
|
||||
def test_only_an_hevc_track_with_an_hevc_dv_supplemental_codec_is_dv_composite(
|
||||
codec: Video.Codec | None, codecs: str | None, supplemental: str, expected: bool
|
||||
) -> None:
|
||||
assert Video.is_dv_composite(codec, codecs, supplemental) is expected
|
||||
|
||||
|
||||
def test_an_hdr10p_track_with_a_dv_rpu_lists_as_hdr10p_plus_dv() -> None:
|
||||
video = Video(url="https://example.test/v.mp4", language="en", codec=Video.Codec.HEVC, range_=Video.Range.HDR10P)
|
||||
video.dv_compatible_bitstream = True
|
||||
assert "[H.265, HDR10P+DV]" in str(video)
|
||||
@@ -158,6 +158,44 @@ def test_a_dv_hdr10p_track_used_only_for_its_rpu_stays_an_ingredient() -> None:
|
||||
assert all(t.hybrid_base_only for t in chosen) and ids(chosen) == {"hdr10-1080", "dvp-360"}
|
||||
|
||||
|
||||
def dv_hdr10(track_id: str, height: int, bitrate: int, range_: Video.Range = Video.Range.HDR10) -> Video:
|
||||
video = make_video(track_id, range_=range_, height=height, bitrate=bitrate, codec=Video.Codec.HEVC)
|
||||
video.dv_compatible_bitstream = True
|
||||
return video
|
||||
|
||||
|
||||
def test_select_hybrid_takes_a_dv_hdr10_track_and_no_profile_5_donor() -> None:
|
||||
H = Video.Codec.HEVC
|
||||
tracks = [
|
||||
dv_hdr10("dvhdr-2160", 2160, 7_000_000),
|
||||
make_video("dv5-2160", range_=Video.Range.DV, height=2160, bitrate=6_800_000, codec=H),
|
||||
make_video("dv5-512", range_=Video.Range.DV, height=512, bitrate=400_000, codec=H),
|
||||
]
|
||||
chosen = list(filter(Tracks().select_hybrid(tracks, [2160]), tracks))
|
||||
assert ids(chosen) == {"dvhdr-2160"} and chosen[0].native_hybrid
|
||||
|
||||
|
||||
def test_select_hybrid_prefers_a_finished_hybrid_that_carries_hdr10p() -> None:
|
||||
tracks = [
|
||||
dv_hdr10("dvhdr-2160", 2160, 9_000_000),
|
||||
dv_hdr10("dvhdrp-2160", 2160, 7_000_000, Video.Range.HDR10P),
|
||||
dv_hdr10p("dvp-2160", 2160, 6_000_000),
|
||||
]
|
||||
assert ids(list(filter(Tracks().select_hybrid(tracks, [2160]), tracks))) == {"dvhdrp-2160"}
|
||||
assert ids(list(filter(Tracks().select_hybrid(tracks, [2160], worst=True), tracks))) == {"dvp-2160"}
|
||||
|
||||
|
||||
def test_select_hybrid_picks_no_base_that_has_no_dv_track_to_take_an_rpu_from() -> None:
|
||||
H = Video.Codec.HEVC
|
||||
tracks = [
|
||||
dv_hdr10("dvhdr-2160", 2160, 7_000_000),
|
||||
make_video("hdr10p-1080", range_=Video.Range.HDR10P, height=1080, bitrate=4_000_000, codec=H),
|
||||
]
|
||||
assert ids(list(filter(Tracks().select_hybrid(tracks, [2160, 1080]), tracks))) == {"dvhdr-2160"}
|
||||
with_generate = Tracks().select_hybrid(tracks, [2160, 1080], generate_dv=True)
|
||||
assert ids(list(filter(with_generate, tracks))) == {"dvhdr-2160", "hdr10p-1080"}
|
||||
|
||||
|
||||
def test_merge_dedups_shared_ingredient_and_deliverable() -> None:
|
||||
H = Video.Codec.HEVC
|
||||
dv = make_video("dv-1080", range_=Video.Range.DV, height=1080, bitrate=9_000_000, codec=H)
|
||||
|
||||
Reference in New Issue
Block a user