feat(ffmpeg): support ffmpeg env args and hw codecs

Parse FFMPEG_ARGS and FFMPEG_OUTPUT_ARGS into arrays
  Detect 'qsv' and 'cuda' flags and map codecs to
  Hardware encoders (h264_qsv/hevc_qsv and h264_nvenc/hevc_nvenc)
  Make codec_short mutable to allow reassignment
  Log constructed ffmpeg command for visibility
  Enables runtime custom ffmpeg args and hw encoder selection
  Improves deployment flexibility and performance tuning
This commit is contained in:
Webysther Sperandio 2026-01-28 03:42:13 +01:00
parent f9261fb866
commit 8fa041a484

View file

@ -708,12 +708,44 @@ export async function convert(
message = "Done: resized to 256x256";
}
// Parse FFMPEG_ARGS environment variable into array
const ffmpegArgs = process.env.FFMPEG_ARGS ? process.env.FFMPEG_ARGS.split(/\s+/) : [];
const ffmpegOutputArgs = process.env.FFMPEG_OUTPUT_ARGS
? process.env.FFMPEG_OUTPUT_ARGS.split(/\s+/)
: [];
if (convertTo.split(".").length > 1) {
// Support av1.mkv and av1.mp4 and h265.mp4 etc.
const split = convertTo.split(".");
const codec_short = split[0];
var codec_short = split[0];
if (ffmpegArgs.includes('qsv')){
switch (codec_short) {
case "h264":
codec_short = "h264_qsv"
extraArgs.push("-c:v", codec_short);
break;
case "h265":
codec_short = "hevc_qsv"
extraArgs.push("-c:v", codec_short);
break;
}
}
if (ffmpegArgs.includes('cuda')){
switch (codec_short) {
case "h264":
codec_short = "h264_nvenc"
extraArgs.push("-c:v", codec_short);
break;
case "h265":
codec_short = "hevc_nvenc"
extraArgs.push("-c:v", codec_short);
break;
}
}
switch (codec_short) {
case "av1":
extraArgs.push("-c:v", "libaom-av1");
break;
@ -729,11 +761,7 @@ export async function convert(
}
}
// Parse FFMPEG_ARGS environment variable into array
const ffmpegArgs = process.env.FFMPEG_ARGS ? process.env.FFMPEG_ARGS.split(/\s+/) : [];
const ffmpegOutputArgs = process.env.FFMPEG_OUTPUT_ARGS
? process.env.FFMPEG_OUTPUT_ARGS.split(/\s+/)
: [];
console.log(`ffmpeg ${ffmpegArgs} -i filePath ${ffmpegOutputArgs} ${extraArgs} ${targetPath}`)
return new Promise((resolve, reject) => {
execFile(