Skip to content

Commit 4af1f53

Browse files
committed
parametrize other nvenc
1 parent 43c6221 commit 4af1f53

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

test/test_encoders.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,15 +1270,28 @@ def test_extra_options_utilized(self, tmp_path, profile, colorspace, color_range
12701270

12711271
@pytest.mark.needs_cuda
12721272
@pytest.mark.skipif(in_fbcode(), reason="ffmpeg CLI not available")
1273-
@pytest.mark.parametrize("preset", ("slow", "fast"))
12741273
@pytest.mark.parametrize("pixel_format", ("nv12", "yuv420p"))
1275-
@pytest.mark.parametrize("format", ("mov", "mp4", "avi", "mkv", "flv"))
1274+
@pytest.mark.parametrize("format_codec", [
1275+
("mov", "h264_nvenc"),
1276+
("mp4", "hevc_nvenc"),
1277+
("avi", "h264_nvenc"),
1278+
pytest.param(
1279+
("mkv", "av1_nvenc"),
1280+
marks=pytest.mark.skipif(
1281+
get_ffmpeg_major_version() <= 5,
1282+
reason="av1_nvenc not supported in FFmpeg 4 and 5"
1283+
)
1284+
),
1285+
("flv", "h264_nvenc")
1286+
])
12761287
@pytest.mark.parametrize("method", ("to_file", "to_tensor", "to_file_like"))
12771288
def test_nvenc_against_ffmpeg_cli(
1278-
self, tmp_path, preset, pixel_format, format, method
1289+
self, tmp_path, pixel_format, format_codec, method
12791290
):
1280-
# Encode with FFmpeg CLI using h264_nvenc
1291+
# Encode with FFmpeg CLI using nvenc codecs
1292+
format, codec = format_codec
12811293
device = "cuda"
1294+
qp = 1 # Lossless (qp=0) is not supported on av1_nvenc, so we use 1
12821295
source_frames = self.decode(TEST_SRC_2_720P.path).data.to(device)
12831296

12841297
temp_raw_path = str(tmp_path / "temp_input.raw")
@@ -1302,12 +1315,13 @@ def test_nvenc_against_ffmpeg_cli(
13021315
"-i",
13031316
temp_raw_path,
13041317
"-c:v",
1305-
"h264_nvenc", # Use NVENC hardware encoder
1318+
codec, # Use specified NVENC hardware encoder
13061319
]
13071320

13081321
ffmpeg_cmd.extend(["-pix_fmt", pixel_format]) # Output format
1309-
ffmpeg_cmd.extend(["-preset", preset]) # Use parametrized preset
1310-
ffmpeg_cmd.extend(["-qp", "0"]) # Use lossless qp for consistency
1322+
if codec == "av1_nvenc":
1323+
ffmpeg_cmd.extend(["-rc", "constqp"]) # Set rate control mode for AV1 else:
1324+
ffmpeg_cmd.extend(["-qp", str(qp)]) # Use lossless qp for other codecs
13111325
ffmpeg_cmd.extend([ffmpeg_encoded_path])
13121326

13131327
# Will this prevent CI from treating test as failed if NVENC is not available?
@@ -1323,33 +1337,32 @@ def test_nvenc_against_ffmpeg_cli(
13231337
frames=source_frames, frame_rate=frame_rate, device=device
13241338
)
13251339

1326-
encoder_extra_options = {"qp": 0}
1340+
encoder_extra_options = {"qp": qp}
1341+
if codec == "av1_nvenc":
1342+
encoder_extra_options["rc"] = 0 # constqp mode
13271343
if method == "to_file":
13281344
encoder_output_path = str(tmp_path / f"nvenc_output.{format}")
13291345
encoder.to_file(
13301346
dest=encoder_output_path,
1331-
codec="h264_nvenc",
1347+
codec=codec,
13321348
pixel_format=pixel_format,
1333-
preset=preset,
13341349
extra_options=encoder_extra_options,
13351350
)
13361351
encoder_output = encoder_output_path
13371352
elif method == "to_tensor":
13381353
encoder_output = encoder.to_tensor(
13391354
format=format,
1340-
codec="h264_nvenc",
1355+
codec=codec,
13411356
pixel_format=pixel_format,
1342-
preset=preset,
13431357
extra_options=encoder_extra_options,
13441358
)
13451359
elif method == "to_file_like":
13461360
file_like = io.BytesIO()
13471361
encoder.to_file_like(
13481362
file_like=file_like,
13491363
format=format,
1350-
codec="h264_nvenc",
1364+
codec=codec,
13511365
pixel_format=pixel_format,
1352-
preset=preset,
13531366
extra_options=encoder_extra_options,
13541367
)
13551368
encoder_output = file_like.getvalue()

0 commit comments

Comments
 (0)