diff --git a/tests/core/test_fps.py b/tests/core/test_fps.py index 5d6d02c5..5ee00c0c 100644 --- a/tests/core/test_fps.py +++ b/tests/core/test_fps.py @@ -4,6 +4,7 @@ from pathlib import Path import pytest +from unshackle.core.manifests import DASH from unshackle.core.tracks import Tracks, Video from unshackle.core.utilities import FPS @@ -32,6 +33,20 @@ def test_parse_rejects_non_division_operation() -> None: FPS.parse("24+1") +def test_dash_frame_rate_with_zero_denominator_gives_no_fps() -> None: + mpd = """ + + + + + + + +""" + tracks = DASH.from_text(mpd, url="https://cdn.example/manifest.mpd").to_tracks(language="en") + assert [v.fps for v in tracks.videos] == [None] + + @pytest.mark.parametrize( ("fps", "expected"), [ @@ -49,10 +64,13 @@ def test_exact_keeps_ntsc_rates(fps: float, expected: str) -> None: assert str(FPS.exact(fps)) == expected -def test_mux_passes_the_exact_rate_as_default_duration(tmp_path: Path, mux_args: Callable[..., list[str]]) -> None: - video = Video(id_="v1", url="https://example.test/v", codec=Video.Codec.HEVC, language="en", fps="24000/1001") +@pytest.mark.parametrize(("fps", "expected"), [("24000/1001", "0:24000/1001p"), ("24000/0", None)]) +def test_mux_default_duration_follows_the_rate( + fps: str, expected: str | None, tmp_path: Path, mux_args: Callable[..., list[str]] +) -> None: + video = Video(id_="v1", url="https://example.test/v", codec=Video.Codec.HEVC, language="en", fps=fps) video.needs_duration_fix = True video.path = tmp_path / "v.hevc" video.path.write_bytes(b"\x00" * 16) args = mux_args(Tracks(video)) - assert args[args.index("--default-duration") + 1] == "0:24000/1001p" + assert dict(zip(args, args[1:], strict=False)).get("--default-duration") == expected diff --git a/unshackle/core/tracks/video.py b/unshackle/core/tracks/video.py index 7e45ad7b..25c9278e 100644 --- a/unshackle/core/tracks/video.py +++ b/unshackle/core/tracks/video.py @@ -249,6 +249,7 @@ class Video(Track): fps: A number, float, or string representing the frames/s of the video. Strings may represent numbers, floats, or a fraction (num/den). All strings will be cast to either a number or float. + A zero denominator gives no fps. hdr10plus: The DV track also carries HDR10+ metadata. The HDR10+ probe sets it. hdr10_base: The DV track has an HDR10 base layer, as DV profile 8.1 does. stereo: The track is stereoscopic 3D (MV-HEVC), with a second view for the other eye. @@ -293,6 +294,9 @@ class Video(Track): try: self.fps = (FPS.parse(str(fps)) or None) if fps else None + except ZeroDivisionError: + logging.getLogger("Video").debug(f"Ignored fps {fps!r}: zero denominator") + self.fps = None except Exception as e: raise ValueError( # noqa: B904 "Expected fps to be a number, float, or a string as numerator/denominator form, " + str(e)