Skip to content

Commit aa27992

Browse files
committed
StreamMetadata.pixel_aspect_ratio: rename from sample_aspect_ratio
1 parent 9f9db90 commit aa27992

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/torchcodec/_core/_metadata.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ class VideoStreamMetadata(StreamMetadata):
8181
average_fps_from_header: Optional[float]
8282
"""Averate fps of the stream, obtained from the header (float or None).
8383
We recommend using the ``average_fps`` attribute instead."""
84-
sample_aspect_ratio: Optional[Fraction]
85-
"""Sample Aspect Ratio (SAR), also known as Pixel Aspect Ratio
86-
(PAR), is the ratio between the width and height of each pixel
84+
pixel_aspect_ratio: Optional[Fraction]
85+
"""Pixel Aspect Ratio (PAR), also known as Sample Aspect Ratio
86+
(SAR --- not to be confused with Sample Aspect Ratio, also SAR),
87+
is the ratio between the width and height of each pixel
8788
(``fractions.Fraction`` or None)."""
8889

8990
@property
@@ -262,7 +263,7 @@ def get_container_metadata(decoder: torch.Tensor) -> ContainerMetadata:
262263
num_frames_from_header=stream_dict.get("numFramesFromHeader"),
263264
num_frames_from_content=stream_dict.get("numFramesFromContent"),
264265
average_fps_from_header=stream_dict.get("averageFpsFromHeader"),
265-
sample_aspect_ratio=_get_optional_sar_fraction(stream_dict),
266+
pixel_aspect_ratio=_get_optional_par_fraction(stream_dict),
266267
**common_meta,
267268
)
268269
)

test/test_metadata.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_get_metadata(metadata_getter):
8282
assert best_video_stream_metadata.begin_stream_seconds_from_header == 0
8383
assert best_video_stream_metadata.bit_rate == 128783
8484
assert best_video_stream_metadata.average_fps == pytest.approx(29.97, abs=0.001)
85-
assert best_video_stream_metadata.sample_aspect_ratio is None
85+
assert best_video_stream_metadata.pixel_aspect_ratio is None
8686
assert best_video_stream_metadata.codec == "h264"
8787
assert best_video_stream_metadata.num_frames_from_content == (
8888
390 if with_scan else None
@@ -139,7 +139,7 @@ def test_num_frames_fallback(
139139
width=123,
140140
height=321,
141141
average_fps_from_header=30,
142-
sample_aspect_ratio=Fraction(1, 1),
142+
pixel_aspect_ratio=Fraction(1, 1),
143143
stream_index=0,
144144
)
145145

@@ -164,7 +164,7 @@ def test_repr():
164164
num_frames_from_header: 390
165165
num_frames_from_content: 390
166166
average_fps_from_header: 29.97003
167-
sample_aspect_ratio: 1
167+
pixel_aspect_ratio: 1
168168
duration_seconds: 13.013
169169
begin_stream_seconds: 0.0
170170
end_stream_seconds: 13.013

0 commit comments

Comments
 (0)