feat: add NVENC hardware encoding support for FFmpeg

Add FFMPEG_PREFER_HARDWARE env var to enable hardware acceleration
Use h264_nvenc and hevc_nvenc encoders when hardware preferred
Fall back to software encoders (libx264/libx265) when disabled
Add comprehensive tests for hardware/software encoding modes
Update README with new environment variable documentation
This enables GPU-accelerated video encoding for better performance on systems with NVIDIA GPUs.
This commit is contained in:
rob_otman 2025-12-17 14:12:13 -07:00
parent 911587ea68
commit 6cca431a76
3 changed files with 75 additions and 2 deletions

View file

@ -712,15 +712,27 @@ export async function convert(
const split = convertTo.split(".");
const codec_short = split[0];
// Check if hardware encoding is preferred (NVENC, VAAPI, etc.)
const preferHardware = process.env.FFMPEG_PREFER_HARDWARE === "true" ||
process.env.FFMPEG_PREFER_HARDWARE === "1";
switch (codec_short) {
case "av1":
extraArgs.push("-c:v", "libaom-av1");
break;
case "h264":
extraArgs.push("-c:v", "libx264");
if (preferHardware) {
extraArgs.push("-c:v", "h264_nvenc");
} else {
extraArgs.push("-c:v", "libx264");
}
break;
case "h265":
extraArgs.push("-c:v", "libx265");
if (preferHardware) {
extraArgs.push("-c:v", "hevc_nvenc");
} else {
extraArgs.push("-c:v", "libx265");
}
break;
case "h266":
extraArgs.push("-c:v", "libx266");