Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions test/decoders/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,32 @@ def get_reference_frames(start_seconds, stop_seconds):
frames, get_reference_frames(start_seconds, stop_seconds)
)

@pytest.mark.parametrize("asset", (NASA_AUDIO, NASA_AUDIO_MP3))
def test_pts(self, asset):
decoder = create_from_file(str(asset.path), seek_mode="approximate")
add_audio_stream(decoder)

for frame_index in range(asset.num_frames):
frame_info = asset.get_frame_info(idx=frame_index)
start_seconds = frame_info.pts_seconds

frames, pts_seconds = get_frames_by_pts_in_range_audio(
decoder, start_seconds=start_seconds, stop_seconds=start_seconds + 1e-3
)
torch.testing.assert_close(
frames, asset.get_frame_data_by_index(frame_index)
)

if asset is NASA_AUDIO_MP3 and frame_index == 0:
# TODO This is a bug. The 0.138125 is correct while 0.072 is
# incorrect, even though it comes from the decoded AVFrame's pts
# field.
# See https://github.com/pytorch/torchcodec/issues/553
assert pts_seconds == 0.072
assert start_seconds == 0.138125
else:
assert pts_seconds == start_seconds


if __name__ == "__main__":
pytest.main()
Loading