From 5ec86d624f7155eea1a94d7345526dd5147f4977 Mon Sep 17 00:00:00 2001 From: rob_otman <11605437+Rob-Otman@users.noreply.github.com> Date: Tue, 13 Jan 2026 15:56:38 +0000 Subject: [PATCH] refactor: update codec detection logic to focus on container formats - Replaced the previous imageFormats set with a new containerFormats set to optimize ffprobe usage. - Updated the isCudaSupportedCodec function to only probe container formats that can contain video streams, improving performance and clarity in codec detection. These changes enhance the efficiency of the codec detection process for CUDA hardware acceleration. --- src/converters/ffmpeg.ts | 65 +++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/src/converters/ffmpeg.ts b/src/converters/ffmpeg.ts index 546b0e0..2a65721 100644 --- a/src/converters/ffmpeg.ts +++ b/src/converters/ffmpeg.ts @@ -691,33 +691,36 @@ export const properties = { // CUDA-supported codec names (as detected by ffprobe) const cudaSupportedCodecs = new Set(["h264", "hevc", "vp9", "vp8", "mpeg2video", "mpeg4", "av1"]); -// Known image formats that should skip ffprobe (no video codec to detect) -const imageFormats = new Set([ - "jpg", - "jpeg", - "png", - "gif", - "bmp", - "webp", - "ico", - "tiff", - "tif", - "svg", - "avif", - "jxl", - "heic", - "heif", - "raw", - "cr2", - "nef", - "orf", - "sr2", - "arw", - "dng", - "psd", - "xcf", - "exr", - "hdr", +// Container formats that can contain video streams with unknown codecs (run ffprobe) +const containerFormats = new Set([ + // Most common/popular video containers + "avi", + "mkv", + "mov", + "mp4", + "m4v", // MPEG-4 video + "m4a", // MPEG-4 audio + "webm", + "flv", + "wmv", + "vob", // DVD video + // MPEG transport streams + "m2ts", + "ts", + "mts", + // MPEG containers + "mpeg", + "mpg", + "m2v", // MPEG-2 video + // Mobile/legacy formats + "3gp", + "3g2", + // Other containers + "nut", + "ogv", // OGG video + "asf", + "mxf", // Professional video + "f4v", // Flash video ]); // Cache NVIDIA GPU availability to avoid repeated checks @@ -767,7 +770,7 @@ async function checkNvidiaGpuAvailable(execFile: ExecFileFn = execFileOriginal): /** * Uses ffprobe to detect if the video codec in a file is supported by CUDA hardware acceleration. - * Returns false for image formats without probing (performance optimization). + * Only probes container formats that can contain video streams with unknown codecs. * Falls back to false if probing fails (safe default). */ async function isCudaSupportedCodec( @@ -775,9 +778,9 @@ async function isCudaSupportedCodec( fileType: string, execFile: ExecFileFn = execFileOriginal, ): Promise { - // Skip ffprobe for known image formats (no video codec to detect) - if (imageFormats.has(fileType.toLowerCase())) { - console.log(`Skipping CUDA detection for image format: ${fileType}`); + // Only run ffprobe on container formats that can contain video streams + if (!containerFormats.has(fileType.toLowerCase())) { + console.log(`Skipping CUDA detection for non-container format: ${fileType}`); return false; }