mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-12-01 21:45:10 +00:00
feat(core): add HDR Vivid hybrids and a MonaLisa command builder
This commit is contained in:
@@ -221,6 +221,14 @@ def make_hybrid() -> Hybrid:
|
||||
return obj
|
||||
|
||||
|
||||
def hybrid_track(path: Path, range_: Video.Range, transfer: str | None = None, **probe: Any) -> Any:
|
||||
"""A downloaded track as the hybrid step reads it, with the FFprobe result given."""
|
||||
colour = {"color_transfer": transfer, **probe} if transfer else probe
|
||||
return SimpleNamespace(
|
||||
id="b", path=path, width=None, height=2160, range=range_, sample_start=0.0, _probe_colour=lambda: colour
|
||||
)
|
||||
|
||||
|
||||
def stub_hybrid_steps(monkeypatch: pytest.MonkeyPatch, *steps: str, tool: str | None = "hdr10plus_tool") -> None:
|
||||
"""Make the stream, Level 5 and inject steps (and those named) do nothing, with a fixed active area."""
|
||||
for name in ("extract_stream", "level_5", "injecting", *steps):
|
||||
@@ -445,7 +453,7 @@ def test_a_conversion_run_removes_its_rpus_so_the_next_base_makes_its_own(
|
||||
monkeypatch.setattr(Hybrid, "convert_hdr10plus_to_dv", convert)
|
||||
monkeypatch.setattr(Hybrid, "level_6", level_6)
|
||||
|
||||
Hybrid([SimpleNamespace(id="b", path=base, width=None, height=2160, range=Video.Range.HDR10P)], "TEST")
|
||||
Hybrid([hybrid_track(base, Video.Range.HDR10P)], "TEST")
|
||||
|
||||
assert seen == {"stale_l6": False, "active_fraction": 0.9}
|
||||
assert not (tmp_path / "RPU.bin").exists() and not (tmp_path / "RPU_L6.bin").exists()
|
||||
@@ -467,12 +475,81 @@ def test_a_base_without_usable_hdr10plus_is_measured_inside_its_crop(
|
||||
stub_hybrid_steps(monkeypatch, "level_6", tool=tool)
|
||||
monkeypatch.setattr(Hybrid, "measure_dv", measure)
|
||||
|
||||
Hybrid([SimpleNamespace(id="b", path=base, width=None, height=2160, range=range_)], "TEST")
|
||||
Hybrid([hybrid_track(base, range_)], "TEST")
|
||||
|
||||
assert seen == {"crop": (0, 100, 0, 100), "stale_l6": False}
|
||||
assert not (tmp_path / "RPU.bin").exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("transfer", ["smpte2084", None, "arib-std-b67", "bt2020-10"])
|
||||
def test_a_vivid_base_makes_a_hybrid_only_on_pq(
|
||||
transfer: str | None, quiet: None, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
"""HDR Vivid sits on PQ or HLG, and the injected profile 8.1 RPU needs PQ."""
|
||||
path = tmp_path / "base.mkv"
|
||||
path.write_bytes(b"")
|
||||
extracted: list[str] = []
|
||||
stub_hybrid_steps(monkeypatch, "level_6", "measure_dv")
|
||||
monkeypatch.setattr(Hybrid, "extract_stream", lambda self, path, type_: extracted.append(type_))
|
||||
base = hybrid_track(path, Video.Range.VIVID, transfer)
|
||||
if transfer == "smpte2084":
|
||||
hybrid = Hybrid([base], "TEST")
|
||||
assert (hybrid.hdr_type, extracted) == ("VIVID", ["HDR10"])
|
||||
else:
|
||||
with pytest.raises(ValueError, match="needs a PQ base"):
|
||||
Hybrid([base], "TEST")
|
||||
assert not extracted
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("base", "dv", "refused"),
|
||||
[
|
||||
("60/1", "24/1", True),
|
||||
("50/1", "25/1", True),
|
||||
("24000/1001", "24/1", False),
|
||||
("0/0", "24/1", False),
|
||||
(None, "24/1", False),
|
||||
("junk", "24/1", False),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("range_", [Video.Range.VIVID, Video.Range.HDR10])
|
||||
def test_two_frame_rates_make_no_hybrid(base: str | None, dv: str, refused: bool, range_: Video.Range) -> None:
|
||||
tracks = [
|
||||
hybrid_track(Path("b.mp4"), range_, "smpte2084", avg_frame_rate=base),
|
||||
hybrid_track(Path("d.mp4"), Video.Range.DV, avg_frame_rate=dv),
|
||||
]
|
||||
if refused:
|
||||
with pytest.raises(ValueError, match="fps and the Dolby Vision track"):
|
||||
Hybrid.check_base(*tracks)
|
||||
else:
|
||||
Hybrid.check_base(*tracks)
|
||||
|
||||
|
||||
def test_a_raw_stream_has_no_frame_rate_to_compare() -> None:
|
||||
base = hybrid_track(Path("b.hevc"), Video.Range.HDR10, avg_frame_rate="25/1")
|
||||
Hybrid.check_base(base, hybrid_track(Path("d.mp4"), Video.Range.DV, avg_frame_rate="24/1"))
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"probe",
|
||||
[{"transfer": "arib-std-b67"}, {"side_data_list": [{"dv_profile": 8, "dv_bl_signal_compatibility_id": 4}]}],
|
||||
)
|
||||
def test_an_hlg_dv_track_makes_no_hybrid(probe: dict[str, Any]) -> None:
|
||||
base = hybrid_track(Path("b.mp4"), Video.Range.HDR10, "smpte2084")
|
||||
with pytest.raises(ValueError, match="profile 8.4"):
|
||||
Hybrid.check_base(base, hybrid_track(Path("d.mp4"), Video.Range.DV, **probe))
|
||||
|
||||
|
||||
def test_vivid_is_the_last_choice_of_hybrid_base_and_takes_no_generate_dv_range() -> None:
|
||||
videos = [
|
||||
video("v2160", Video.Range.VIVID),
|
||||
video("h2160", Video.Range.HDR10),
|
||||
video("v1080", Video.Range.VIVID, 1080),
|
||||
]
|
||||
assert [v.id for v in select_hybrid_bases(videos)] == ["h2160", "v1080"]
|
||||
assert generated_dv_ranges([Video.Range.VIVID], True) == ([Video.Range.VIVID], [])
|
||||
|
||||
|
||||
def test_an_hdr10plus_label_without_metadata_is_measured(
|
||||
quiet: None, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
||||
) -> None:
|
||||
@@ -487,7 +564,7 @@ def test_an_hdr10plus_label_without_metadata_is_measured(
|
||||
monkeypatch.setattr(Hybrid, "measure_dv", lambda self, crop=None: measured.append(crop))
|
||||
monkeypatch.setattr(hybrid_mod, "run_step", no_metadata)
|
||||
|
||||
hybrid = Hybrid([SimpleNamespace(id="b", path=base, width=None, height=2160, range=Video.Range.HDR10P)], "TEST")
|
||||
hybrid = Hybrid([hybrid_track(base, Video.Range.HDR10P)], "TEST")
|
||||
|
||||
assert measured == [(0, 100, 0, 100)] and hybrid.hdr10plus_to_dv is False
|
||||
|
||||
@@ -658,12 +735,8 @@ def test_a_failed_resolution_removes_its_crop_edits_and_keeps_the_dv_files(
|
||||
monkeypatch.setattr(Hybrid, "injecting", failed_inject)
|
||||
monkeypatch.setattr(hybrid_mod.console, "print", lambda *a, **k: None)
|
||||
videos = [
|
||||
SimpleNamespace(
|
||||
id="b", path=tmp_path / "base.mkv", width=None, height=2160, range=Video.Range.HDR10, sample_start=0.0
|
||||
),
|
||||
SimpleNamespace(
|
||||
id="d", path=tmp_path / "dv.mkv", width=None, height=1080, range=Video.Range.DV, sample_start=0.0
|
||||
),
|
||||
hybrid_track(tmp_path / "base.mkv", Video.Range.HDR10),
|
||||
hybrid_track(tmp_path / "dv.mkv", Video.Range.DV),
|
||||
]
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
@@ -729,7 +802,7 @@ def test_a_hybrid_that_fills_the_temp_volume_names_the_free_space_before_its_fil
|
||||
stub_hybrid_steps(monkeypatch, "measure_dv", "level_6")
|
||||
monkeypatch.setattr(Hybrid, "injecting", full)
|
||||
monkeypatch.setattr(temp.shutil, "disk_usage", usage)
|
||||
video = SimpleNamespace(id="b", path=base, width=None, height=2160, range=Video.Range.HDR10)
|
||||
video = hybrid_track(base, Video.Range.HDR10)
|
||||
|
||||
error = hybrid_step_error([video], "TEST", "HDR10-DV-2160p.hevc") # type: ignore[list-item]
|
||||
|
||||
@@ -753,7 +826,7 @@ def test_a_working_hybrid_reports_no_error_and_an_exit_passes_through(monkeypatc
|
||||
def test_a_title_without_a_hybrid_file_fails() -> None:
|
||||
bases = [video("h2160", Video.Range.HDR10), video("h1080", Video.Range.HDR10, 1080)]
|
||||
assert missing_hybrid_error(bases, 1) is None
|
||||
assert missing_hybrid_error([], 0) == "No HEVC HDR10 or HDR10+ track to make a hybrid from"
|
||||
assert missing_hybrid_error([], 0) == "No HEVC HDR10, HDR10+ or VIVID track to make a hybrid from"
|
||||
assert missing_hybrid_error(bases, 0) == ("Every hybrid failed (2160p, 1080p), so the title has no hybrid file")
|
||||
|
||||
|
||||
@@ -889,14 +962,14 @@ def video(
|
||||
|
||||
def test_hybrid_fails_with_neither_a_base_nor_dv() -> None:
|
||||
assert hybrid_gate_failure([video("sdr", Video.Range.SDR)], True) == (
|
||||
"HYBRID needs HDR10/HDR10+ and DV tracks, available ranges: SDR"
|
||||
"HYBRID needs HDR10/HDR10+/VIVID and DV tracks, available ranges: SDR"
|
||||
)
|
||||
assert hybrid_gate_failure([], True) == "HYBRID needs HDR10/HDR10+ and DV tracks, available ranges: none"
|
||||
assert hybrid_gate_failure([], True) == "HYBRID needs HDR10/HDR10+/VIVID and DV tracks, available ranges: none"
|
||||
|
||||
|
||||
def test_hybrid_fails_with_dv_only() -> None:
|
||||
assert hybrid_gate_failure([video("dv", Video.Range.DV)], True) == (
|
||||
"HYBRID needs HDR10/HDR10+ and DV tracks, available ranges: DV"
|
||||
"HYBRID needs HDR10/HDR10+/VIVID and DV tracks, available ranges: DV"
|
||||
)
|
||||
|
||||
|
||||
@@ -913,14 +986,14 @@ def test_hybrid_goes_on_with_a_base_and_dv_whatever_the_flag() -> None:
|
||||
def test_hybrid_fails_up_front_when_no_base_is_hevc() -> None:
|
||||
"""dovi_tool injects into HEVC, so an all-AV1 title fails before it downloads anything."""
|
||||
videos = [video("av1", Video.Range.HDR10P, codec=Video.Codec.AV1), video("dv", Video.Range.DV)]
|
||||
assert hybrid_gate_failure(videos, False) == "HYBRID needs an HEVC HDR10/HDR10+ base, available codecs: AV1"
|
||||
assert hybrid_gate_failure(videos, False) == "HYBRID needs an HEVC HDR10/HDR10+/VIVID base, available codecs: AV1"
|
||||
assert hybrid_gate_failure(videos + [video("h", Video.Range.HDR10, codec=None)], False) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize("range_", [Video.Range.HDR10P, Video.Range.HDR10])
|
||||
def test_hybrid_fails_without_dv_and_hints_at_the_flag(range_: Video.Range) -> None:
|
||||
assert hybrid_gate_failure([video("v", range_)], False) == (
|
||||
f"HYBRID needs HDR10/HDR10+ and DV tracks, available ranges: {range_.name}; add --generate-dv to make DV"
|
||||
f"HYBRID needs HDR10/HDR10+/VIVID and DV tracks, available ranges: {range_.name}; add --generate-dv to make DV"
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user