Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def pytest_collection_modifyitems(items):
# with the @needs_cuda decorator. It will also exist if it was
# parametrized with a parameter that has the mark: for example if a test
# is parametrized with
# @pytest.mark.parametrize('device', cpu_and_cuda())
# @pytest.mark.parametrize('device', all_supported_devices())
# the "instances" of the tests where device == 'cuda' will have the
# 'needs_cuda' mark, and the ones with device == 'cpu' won't have the
# mark.
Expand Down
46 changes: 23 additions & 23 deletions test/test_decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
)

from .utils import (
all_supported_devices,
assert_frames_equal,
AV1_VIDEO,
cpu_and_cuda,
get_ffmpeg_major_version,
H264_10BITS,
H265_10BITS,
Expand Down Expand Up @@ -163,7 +163,7 @@ def test_create_fails(self):
VideoDecoder(NASA_VIDEO.path, seek_mode="blah")

@pytest.mark.parametrize("num_ffmpeg_threads", (1, 4))
@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_getitem_int(self, num_ffmpeg_threads, device, seek_mode):
decoder = VideoDecoder(
Expand Down Expand Up @@ -213,7 +213,7 @@ def test_getitem_numpy_int(self):
assert_frames_equal(ref_frame1, decoder[numpy.uint32(1)])
assert_frames_equal(ref_frame180, decoder[numpy.uint32(180)])

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_getitem_slice(self, device, seek_mode):
decoder = VideoDecoder(NASA_VIDEO.path, device=device, seek_mode=seek_mode)
Expand Down Expand Up @@ -373,7 +373,7 @@ def test_device_instance(self):
decoder = VideoDecoder(NASA_VIDEO.path, device=torch.device("cpu"))
assert isinstance(decoder.metadata, VideoStreamMetadata)

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_getitem_fails(self, device, seek_mode):
decoder = VideoDecoder(NASA_VIDEO.path, device=device, seek_mode=seek_mode)
Expand All @@ -390,7 +390,7 @@ def test_getitem_fails(self, device, seek_mode):
with pytest.raises(TypeError, match="Unsupported key type"):
frame = decoder[2.3] # noqa

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_iteration(self, device, seek_mode):
decoder = VideoDecoder(NASA_VIDEO.path, device=device, seek_mode=seek_mode)
Expand Down Expand Up @@ -437,7 +437,7 @@ def test_iteration_slow(self):

assert iterations == len(decoder) == 390

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_get_frame_at(self, device, seek_mode):
decoder = VideoDecoder(NASA_VIDEO.path, device=device, seek_mode=seek_mode)
Expand Down Expand Up @@ -475,7 +475,7 @@ def test_get_frame_at(self, device, seek_mode):
frame9 = decoder.get_frame_at(numpy.uint32(9))
assert_frames_equal(ref_frame9, frame9.data)

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
def test_get_frame_at_tuple_unpacking(self, device):
decoder = VideoDecoder(NASA_VIDEO.path, device=device)

Expand All @@ -486,7 +486,7 @@ def test_get_frame_at_tuple_unpacking(self, device):
assert frame.pts_seconds == pts
assert frame.duration_seconds == duration

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_get_frame_at_fails(self, device, seek_mode):
decoder = VideoDecoder(NASA_VIDEO.path, device=device, seek_mode=seek_mode)
Expand All @@ -500,7 +500,7 @@ def test_get_frame_at_fails(self, device, seek_mode):
with pytest.raises(IndexError, match="must be less than"):
frame = decoder.get_frame_at(10000) # noqa

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_get_frames_at(self, device, seek_mode):
decoder = VideoDecoder(NASA_VIDEO.path, device=device, seek_mode=seek_mode)
Expand Down Expand Up @@ -551,7 +551,7 @@ def test_get_frames_at(self, device, seek_mode):
frames.duration_seconds, expected_duration_seconds, atol=1e-4, rtol=0
)

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_get_frames_at_fails(self, device, seek_mode):
decoder = VideoDecoder(NASA_VIDEO.path, device=device, seek_mode=seek_mode)
Expand All @@ -568,7 +568,7 @@ def test_get_frames_at_fails(self, device, seek_mode):
with pytest.raises(RuntimeError, match="Expected a value of type"):
decoder.get_frames_at([0.3])

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
def test_get_frame_at_av1(self, device):
if device == "cuda" and get_ffmpeg_major_version() == 4:
return
Expand All @@ -581,7 +581,7 @@ def test_get_frame_at_av1(self, device):
assert decoded_frame10.pts_seconds == ref_frame_info10.pts_seconds
assert_frames_equal(decoded_frame10.data, ref_frame10.to(device=device))

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_get_frame_played_at(self, device, seek_mode):
decoder = VideoDecoder(NASA_VIDEO.path, device=device, seek_mode=seek_mode)
Expand Down Expand Up @@ -610,7 +610,7 @@ def test_get_frame_played_at_h265(self):
ref_frame6 = H265_VIDEO.get_frame_data_by_index(5)
assert_frames_equal(ref_frame6, decoder.get_frame_played_at(0.5).data)

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_get_frame_played_at_fails(self, device, seek_mode):
decoder = VideoDecoder(NASA_VIDEO.path, device=device, seek_mode=seek_mode)
Expand All @@ -621,7 +621,7 @@ def test_get_frame_played_at_fails(self, device, seek_mode):
with pytest.raises(IndexError, match="Invalid pts in seconds"):
frame = decoder.get_frame_played_at(100.0) # noqa

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_get_frames_played_at(self, device, seek_mode):

Expand Down Expand Up @@ -660,7 +660,7 @@ def test_get_frames_played_at(self, device, seek_mode):
frames.duration_seconds, expected_duration_seconds, atol=1e-4, rtol=0
)

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_get_frames_played_at_fails(self, device, seek_mode):
decoder = VideoDecoder(NASA_VIDEO.path, device=device, seek_mode=seek_mode)
Expand All @@ -674,7 +674,7 @@ def test_get_frames_played_at_fails(self, device, seek_mode):
with pytest.raises(RuntimeError, match="Expected a value of type"):
decoder.get_frames_played_at(["bad"])

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("stream_index", [0, 3, None])
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_get_frames_in_range(self, stream_index, device, seek_mode):
Expand Down Expand Up @@ -779,7 +779,7 @@ def test_get_frames_in_range(self, stream_index, device, seek_mode):
empty_frames.duration_seconds, NASA_VIDEO.empty_duration_seconds
)

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_get_frames_in_range_slice_indices_syntax(self, device, seek_mode):
decoder = VideoDecoder(
Expand Down Expand Up @@ -831,7 +831,7 @@ def test_get_frames_in_range_slice_indices_syntax(self, device, seek_mode):
).to(device)
assert_frames_equal(frames387_None.data, reference_frame387_389)

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
@patch("torchcodec._core._metadata._get_stream_json_metadata")
def test_get_frames_with_missing_num_frames_metadata(
Expand Down Expand Up @@ -894,7 +894,7 @@ def test_get_frames_with_missing_num_frames_metadata(
lambda decoder: decoder.get_frames_played_in_range(0, 1).data,
),
)
@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_dimension_order(self, dimension_order, frame_getter, device, seek_mode):
decoder = VideoDecoder(
Expand Down Expand Up @@ -922,7 +922,7 @@ def test_dimension_order_fails(self):
VideoDecoder(NASA_VIDEO.path, dimension_order="NCDHW")

@pytest.mark.parametrize("stream_index", [0, 3, None])
@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_get_frames_by_pts_in_range(self, stream_index, device, seek_mode):
decoder = VideoDecoder(
Expand Down Expand Up @@ -1061,7 +1061,7 @@ def test_get_frames_by_pts_in_range(self, stream_index, device, seek_mode):
)
assert_frames_equal(all_frames.data, decoder[:])

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
def test_get_frames_by_pts_in_range_fails(self, device, seek_mode):
decoder = VideoDecoder(NASA_VIDEO.path, device=device, seek_mode=seek_mode)
Expand All @@ -1075,7 +1075,7 @@ def test_get_frames_by_pts_in_range_fails(self, device, seek_mode):
with pytest.raises(ValueError, match="Invalid stop seconds"):
frame = decoder.get_frames_played_in_range(0, 23) # noqa

@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
def test_get_key_frame_indices(self, device):
decoder = VideoDecoder(NASA_VIDEO.path, device=device, seek_mode="exact")
key_frame_indices = decoder._get_key_frame_indices()
Expand Down Expand Up @@ -1120,7 +1120,7 @@ def test_get_key_frame_indices(self, device):

# TODO investigate why this fails internally.
@pytest.mark.skipif(in_fbcode(), reason="Compile test fails internally.")
@pytest.mark.parametrize("device", cpu_and_cuda())
@pytest.mark.parametrize("device", all_supported_devices())
def test_compile(self, device):
decoder = VideoDecoder(NASA_VIDEO.path, device=device)

Expand Down
Loading
Loading