Skip to content

Commit d7bb786

Browse files
author
Daniel Flores
committed
incorporate comment suggestions in test_ops
1 parent d2b2f14 commit d7bb786

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

test/test_ops.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,7 @@ def decode(self, file_path) -> torch.Tensor:
13861386

13871387
@pytest.mark.parametrize("format", ("mov", "mp4", "avi", "mkv", "webm", "flv"))
13881388
def test_video_encoder_round_trip(self, tmp_path, format):
1389+
# Test that decode(encode(decode(asset))) == decode(asset)
13891390
ffmpeg_version = get_ffmpeg_major_version()
13901391
if format == "webm":
13911392
if ffmpeg_version == 4:
@@ -1397,7 +1398,6 @@ def test_video_encoder_round_trip(self, tmp_path, format):
13971398
"Codec for webm is not available in the FFmpeg6/7 installation on Windows."
13981399
)
13991400
asset = TEST_SRC_2_720P
1400-
# Test that decode(encode(decode(asset))) == decode(asset)
14011401
source_frames = self.decode(str(asset.path)).data
14021402

14031403
encoded_path = str(tmp_path / f"encoder_output.{format}")
@@ -1406,12 +1406,8 @@ def test_video_encoder_round_trip(self, tmp_path, format):
14061406
frames=source_frames, frame_rate=frame_rate, filename=encoded_path, crf=0
14071407
)
14081408
round_trip_frames = self.decode(encoded_path).data
1409-
assert (
1410-
source_frames.shape == round_trip_frames.shape
1411-
), f"Shape mismatch: source {source_frames.shape} vs round_trip {round_trip_frames.shape}"
1412-
assert (
1413-
source_frames.dtype == round_trip_frames.dtype
1414-
), f"Dtype mismatch: source {source_frames.dtype} vs round_trip {round_trip_frames.dtype}"
1409+
assert source_frames.shape == round_trip_frames.shape
1410+
assert source_frames.dtype == round_trip_frames.dtype
14151411

14161412
# If FFmpeg selects a codec or pixel format that does lossy encoding, assert 99% of pixels
14171413
# are within a higher tolerance.
@@ -1421,13 +1417,10 @@ def test_video_encoder_round_trip(self, tmp_path, format):
14211417
else:
14221418
assert_close = torch.testing.assert_close
14231419
atol = 2
1424-
# Check that PSNR for decode(encode(samples)) is above 30
14251420
for s_frame, rt_frame in zip(source_frames, round_trip_frames):
1426-
res = psnr(s_frame, rt_frame)
1427-
assert res > 30
1421+
assert psnr(s_frame, rt_frame) > 30
14281422
assert_close(s_frame, rt_frame, atol=atol, rtol=0)
14291423

1430-
@pytest.mark.skipif(in_fbcode(), reason="ffmpeg CLI not available")
14311424
@pytest.mark.skipif(in_fbcode(), reason="ffmpeg CLI not available")
14321425
@pytest.mark.parametrize(
14331426
"format", ("mov", "mp4", "avi", "mkv", "webm", "flv", "gif")
@@ -1453,7 +1446,6 @@ def test_video_encoder_against_ffmpeg_cli(self, tmp_path, format):
14531446
f.write(source_frames.permute(0, 2, 3, 1).cpu().numpy().tobytes())
14541447

14551448
ffmpeg_encoded_path = str(tmp_path / f"ffmpeg_output.{format}")
1456-
# Test that lossless encoding is identical
14571449
crf = 0
14581450
quality_params = ["-crf", str(crf)]
14591451
# Some codecs (ex. MPEG4) do not support CRF, qscale is used for lossless encoding.

0 commit comments

Comments
 (0)