fix(tracks): treat a zero-denominator video frame rate as unknown

This commit is contained in:
imSp4rky
2026-11-29 06:24:01 -07:00
parent 82991dd823
commit 6b662d4fc0
2 changed files with 25 additions and 3 deletions
+21 -3
View File
@@ -4,6 +4,7 @@ from pathlib import Path
import pytest import pytest
from unshackle.core.manifests import DASH
from unshackle.core.tracks import Tracks, Video from unshackle.core.tracks import Tracks, Video
from unshackle.core.utilities import FPS from unshackle.core.utilities import FPS
@@ -32,6 +33,20 @@ def test_parse_rejects_non_division_operation() -> None:
FPS.parse("24+1") FPS.parse("24+1")
def test_dash_frame_rate_with_zero_denominator_gives_no_fps() -> None:
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" frameRate="24000/0" />
</AdaptationSet>
</Period>
</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( @pytest.mark.parametrize(
("fps", "expected"), ("fps", "expected"),
[ [
@@ -49,10 +64,13 @@ def test_exact_keeps_ntsc_rates(fps: float, expected: str) -> None:
assert str(FPS.exact(fps)) == expected 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: @pytest.mark.parametrize(("fps", "expected"), [("24000/1001", "0:24000/1001p"), ("24000/0", None)])
video = Video(id_="v1", url="https://example.test/v", codec=Video.Codec.HEVC, language="en", fps="24000/1001") 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.needs_duration_fix = True
video.path = tmp_path / "v.hevc" video.path = tmp_path / "v.hevc"
video.path.write_bytes(b"\x00" * 16) video.path.write_bytes(b"\x00" * 16)
args = mux_args(Tracks(video)) 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
+4
View File
@@ -249,6 +249,7 @@ class Video(Track):
fps: A number, float, or string representing the frames/s of the video. fps: A number, float, or string representing the frames/s of the video.
Strings may represent numbers, floats, or a fraction (num/den). Strings may represent numbers, floats, or a fraction (num/den).
All strings will be cast to either a number or float. 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. 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. 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. stereo: The track is stereoscopic 3D (MV-HEVC), with a second view for the other eye.
@@ -293,6 +294,9 @@ class Video(Track):
try: try:
self.fps = (FPS.parse(str(fps)) or None) if fps else None 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: except Exception as e:
raise ValueError( # noqa: B904 raise ValueError( # noqa: B904
"Expected fps to be a number, float, or a string as numerator/denominator form, " + str(e) "Expected fps to be a number, float, or a string as numerator/denominator form, " + str(e)