fix: ensure GPU availability is checked before using hardware acceleration

- Check both preferHardware AND gpuAvailable before using NVENC codecs (h264_nvenc, hevc_nvenc)
- Check gpuAvailable before adding CUDA hwaccel flag for input decoding
- Fix test assertion to check correct call index for CUDA hwaccel verification

This prevents hardware acceleration attempts when GPU is unavailable, addressing code review feedback.
This commit is contained in:
rob_otman 2025-12-17 16:05:25 -07:00
parent db3acff4f7
commit 00931098c1
2 changed files with 5 additions and 4 deletions

View file

@ -867,14 +867,14 @@ export async function convert(
extraArgs.push("-c:v", "libaom-av1");
break;
case "h264":
if (preferHardware) {
if (preferHardware && gpuAvailable) {
extraArgs.push("-c:v", "h264_nvenc");
} else {
extraArgs.push("-c:v", "libx264");
}
break;
case "h265":
if (preferHardware) {
if (preferHardware && gpuAvailable) {
extraArgs.push("-c:v", "hevc_nvenc");
} else {
extraArgs.push("-c:v", "libx265");
@ -893,7 +893,7 @@ export async function convert(
// This only applies if FFMPEG_ARGS doesn't already specify a hardware accelerator
const hasHardwareAccel = ffmpegArgs.includes("-hwaccel");
if (preferHardware && !hasHardwareAccel) {
if (preferHardware && gpuAvailable && !hasHardwareAccel) {
const supportsCuda = await isCudaSupportedCodec(filePath, fileType, execFile);
if (supportsCuda) {
ffmpegArgs.push("-hwaccel", "cuda");