@@ -1386,6 +1386,7 @@ def decode(self, file_path) -> torch.Tensor:
1386
1386
1387
1387
@pytest .mark .parametrize ("format" , ("mov" , "mp4" , "avi" , "mkv" , "webm" , "flv" ))
1388
1388
def test_video_encoder_round_trip (self , tmp_path , format ):
1389
+ # Test that decode(encode(decode(asset))) == decode(asset)
1389
1390
ffmpeg_version = get_ffmpeg_major_version ()
1390
1391
if format == "webm" :
1391
1392
if ffmpeg_version == 4 :
@@ -1397,7 +1398,6 @@ def test_video_encoder_round_trip(self, tmp_path, format):
1397
1398
"Codec for webm is not available in the FFmpeg6/7 installation on Windows."
1398
1399
)
1399
1400
asset = TEST_SRC_2_720P
1400
- # Test that decode(encode(decode(asset))) == decode(asset)
1401
1401
source_frames = self .decode (str (asset .path )).data
1402
1402
1403
1403
encoded_path = str (tmp_path / f"encoder_output.{ format } " )
@@ -1406,12 +1406,8 @@ def test_video_encoder_round_trip(self, tmp_path, format):
1406
1406
frames = source_frames , frame_rate = frame_rate , filename = encoded_path , crf = 0
1407
1407
)
1408
1408
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
1415
1411
1416
1412
# If FFmpeg selects a codec or pixel format that does lossy encoding, assert 99% of pixels
1417
1413
# are within a higher tolerance.
@@ -1421,13 +1417,10 @@ def test_video_encoder_round_trip(self, tmp_path, format):
1421
1417
else :
1422
1418
assert_close = torch .testing .assert_close
1423
1419
atol = 2
1424
- # Check that PSNR for decode(encode(samples)) is above 30
1425
1420
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
1428
1422
assert_close (s_frame , rt_frame , atol = atol , rtol = 0 )
1429
1423
1430
- @pytest .mark .skipif (in_fbcode (), reason = "ffmpeg CLI not available" )
1431
1424
@pytest .mark .skipif (in_fbcode (), reason = "ffmpeg CLI not available" )
1432
1425
@pytest .mark .parametrize (
1433
1426
"format" , ("mov" , "mp4" , "avi" , "mkv" , "webm" , "flv" , "gif" )
@@ -1453,7 +1446,6 @@ def test_video_encoder_against_ffmpeg_cli(self, tmp_path, format):
1453
1446
f .write (source_frames .permute (0 , 2 , 3 , 1 ).cpu ().numpy ().tobytes ())
1454
1447
1455
1448
ffmpeg_encoded_path = str (tmp_path / f"ffmpeg_output.{ format } " )
1456
- # Test that lossless encoding is identical
1457
1449
crf = 0
1458
1450
quality_params = ["-crf" , str (crf )]
1459
1451
# Some codecs (ex. MPEG4) do not support CRF, qscale is used for lossless encoding.
0 commit comments