@@ -1212,20 +1212,15 @@ def test_video_encoder_round_trip(self, tmp_path, format, method, device):
12121212 assert source_frames .shape == round_trip_frames .shape
12131213 assert source_frames .dtype == round_trip_frames .dtype
12141214
1215- # If FFmpeg selects a codec or pixel format that does lossy encoding, assert 99% of pixels
1216- # are within a higher tolerance.
1217- if ffmpeg_version == 6 or device == "cuda" :
1218- atol = 15
1219- percentage = 98 if device == "cuda" else 99
1215+ # If encoding on GPU, assert 99% of pixels are within a strict tolerance.
1216+ if device == "cuda" :
1217+ assert_close = partial (assert_tensor_close_on_at_least , atol = 3 , percentage = 99 )
1218+ else :
12201219 assert_close = partial (
1221- assert_tensor_close_on_at_least , percentage = percentage
1220+ torch . testing . assert_close , atol = 2 , rtol = 0
12221221 )
1223- else :
1224- assert_close = torch .testing .assert_close
1225- atol = 2
12261222 for s_frame , rt_frame in zip (source_frames , round_trip_frames ):
1227- assert psnr (s_frame , rt_frame ) > 30
1228- assert_close (s_frame , rt_frame , atol = atol , rtol = 0 )
1223+ assert_close (s_frame , rt_frame )
12291224
12301225 @pytest .mark .parametrize (
12311226 "format" ,
@@ -1340,14 +1335,10 @@ def test_video_encoder_against_ffmpeg_cli(self, tmp_path, format, device):
13401335
13411336 if codec_str :
13421337 ffmpeg_cmd .extend (codec_str .split ())
1338+ quality_param = "qp" if device == "cuda" else "crf"
13431339
1344- ffmpeg_cmd .extend (
1345- [
1346- "-crf" ,
1347- str (crf ),
1348- ffmpeg_encoded_path ,
1349- ]
1350- )
1340+ ffmpeg_cmd .extend ([f"-{ quality_param } " , str (crf )])
1341+ ffmpeg_cmd .extend ([ffmpeg_encoded_path ])
13511342 subprocess .run (ffmpeg_cmd , check = True )
13521343
13531344 # Encode with our video encoder
@@ -1372,8 +1363,7 @@ def test_video_encoder_against_ffmpeg_cli(self, tmp_path, format, device):
13721363
13731364 # Check that PSNR between both encoded versions is high
13741365 for ff_frame , enc_frame in zip (ffmpeg_frames , encoder_frames ):
1375- res = psnr (ff_frame , enc_frame )
1376- assert res > 30
1366+ assert psnr (ff_frame , enc_frame ) > 30
13771367 assert_tensor_close_on_at_least (
13781368 ff_frame , enc_frame , percentage = percentage , atol = 2
13791369 )
0 commit comments