🎥 Make videos programmatically with React
`@remotion/renderer`: Add NVENC hardware encoding for H.264/H.265 on Linux/Windows (#7733)
willy-scrd1f99f8ddc2a
diff --git a/packages/compositor-darwin-arm64/libavcodec.dylib b/packages/compositor-darwin-arm64/libavcodec.dylibindex 847a686c1f..29e996b5c7 100755Binary files a/packages/compositor-darwin-arm64/libavcodec.dylib and b/packages/compositor-darwin-arm64/libavcodec.dylib differdiff --git a/packages/compositor-darwin-arm64/remotion b/packages/compositor-darwin-arm64/remotionindex 8253f04a35..5f7f4b4326 100755Binary files a/packages/compositor-darwin-arm64/remotion and b/packages/compositor-darwin-arm64/remotion differdiff --git a/packages/compositor-darwin-x64/libavcodec.dylib b/packages/compositor-darwin-x64/libavcodec.dylibindex 07e837bc11..f36b50f84d 100755Binary files a/packages/compositor-darwin-x64/libavcodec.dylib and b/packages/compositor-darwin-x64/libavcodec.dylib differdiff --git a/packages/compositor-darwin-x64/remotion b/packages/compositor-darwin-x64/remotionindex 906d383cd0..1d85f06fd7 100755Binary files a/packages/compositor-darwin-x64/remotion and b/packages/compositor-darwin-x64/remotion differdiff --git a/packages/compositor-linux-arm64-gnu/ffmpeg b/packages/compositor-linux-arm64-gnu/ffmpegindex 6acf8d228d..63ead14b14 100755Binary files a/packages/compositor-linux-arm64-gnu/ffmpeg and b/packages/compositor-linux-arm64-gnu/ffmpeg differdiff --git a/packages/compositor-linux-arm64-gnu/ffprobe b/packages/compositor-linux-arm64-gnu/ffprobeindex a0f209b600..b4fc1693d6 100755Binary files a/packages/compositor-linux-arm64-gnu/ffprobe and b/packages/compositor-linux-arm64-gnu/ffprobe differdiff --git a/packages/compositor-linux-arm64-gnu/libavcodec.so b/packages/compositor-linux-arm64-gnu/libavcodec.soindex dfc374c0a1..ae42dfd254 100755Binary files a/packages/compositor-linux-arm64-gnu/libavcodec.so and b/packages/compositor-linux-arm64-gnu/libavcodec.so differdiff --git a/packages/compositor-linux-arm64-gnu/libavformat.so b/packages/compositor-linux-arm64-gnu/libavformat.soindex b45cf03784..4090a1dc15 100755Binary files a/packages/compositor-linux-arm64-gnu/libavformat.so and b/packages/compositor-linux-arm64-gnu/libavformat.so differdiff --git a/packages/compositor-linux-arm64-gnu/libavutil.so b/packages/compositor-linux-arm64-gnu/libavutil.soindex e6769e52a2..d671d875cf 100755Binary files a/packages/compositor-linux-arm64-gnu/libavutil.so and b/packages/compositor-linux-arm64-gnu/libavutil.so differdiff --git a/packages/compositor-linux-arm64-gnu/remotion b/packages/compositor-linux-arm64-gnu/remotionindex 14991846bd..fd903f881e 100755Binary files a/packages/compositor-linux-arm64-gnu/remotion and b/packages/compositor-linux-arm64-gnu/remotion differdiff --git a/packages/compositor-linux-arm64-musl/libavcodec.so b/packages/compositor-linux-arm64-musl/libavcodec.soindex a5c629e3c5..ae94bb83e4 100755Binary files a/packages/compositor-linux-arm64-musl/libavcodec.so and b/packages/compositor-linux-arm64-musl/libavcodec.so differdiff --git a/packages/compositor-linux-arm64-musl/remotion b/packages/compositor-linux-arm64-musl/remotionindex 9a0ee57553..7bbb10edbc 100755Binary files a/packages/compositor-linux-arm64-musl/remotion and b/packages/compositor-linux-arm64-musl/remotion differdiff --git a/packages/compositor-linux-x64-gnu/ffmpeg b/packages/compositor-linux-x64-gnu/ffmpegindex 530eb2dab3..d66fbd53e1 100755Binary files a/packages/compositor-linux-x64-gnu/ffmpeg and b/packages/compositor-linux-x64-gnu/ffmpeg differdiff --git a/packages/compositor-linux-x64-gnu/ffprobe b/packages/compositor-linux-x64-gnu/ffprobeindex 3608a90999..65ef48b9ae 100755Binary files a/packages/compositor-linux-x64-gnu/ffprobe and b/packages/compositor-linux-x64-gnu/ffprobe differdiff --git a/packages/compositor-linux-x64-gnu/libavcodec.so b/packages/compositor-linux-x64-gnu/libavcodec.soindex bae16392aa..f51285918c 100755Binary files a/packages/compositor-linux-x64-gnu/libavcodec.so and b/packages/compositor-linux-x64-gnu/libavcodec.so differdiff --git a/packages/compositor-linux-x64-gnu/libavdevice.so b/packages/compositor-linux-x64-gnu/libavdevice.soindex 70a1874ce9..b15dd71459 100755Binary files a/packages/compositor-linux-x64-gnu/libavdevice.so and b/packages/compositor-linux-x64-gnu/libavdevice.so differdiff --git a/packages/compositor-linux-x64-gnu/libavfilter.so b/packages/compositor-linux-x64-gnu/libavfilter.soindex 129681c709..d650c6a1f7 100755Binary files a/packages/compositor-linux-x64-gnu/libavfilter.so and b/packages/compositor-linux-x64-gnu/libavfilter.so differdiff --git a/packages/compositor-linux-x64-gnu/libavformat.so b/packages/compositor-linux-x64-gnu/libavformat.soindex c2727e5e64..641d5e3546 100755Binary files a/packages/compositor-linux-x64-gnu/libavformat.so and b/packages/compositor-linux-x64-gnu/libavformat.so differdiff --git a/packages/compositor-linux-x64-gnu/libavutil.so b/packages/compositor-linux-x64-gnu/libavutil.soindex 733fad96c3..d7ccca4492 100755Binary files a/packages/compositor-linux-x64-gnu/libavutil.so and b/packages/compositor-linux-x64-gnu/libavutil.so differdiff --git a/packages/compositor-linux-x64-gnu/libswresample.so b/packages/compositor-linux-x64-gnu/libswresample.soindex 2fd472796f..f6343ad30f 100755Binary files a/packages/compositor-linux-x64-gnu/libswresample.so and b/packages/compositor-linux-x64-gnu/libswresample.so differdiff --git a/packages/compositor-linux-x64-gnu/libswscale.so b/packages/compositor-linux-x64-gnu/libswscale.soindex 2bf83a9aec..8f7f08950a 100755Binary files a/packages/compositor-linux-x64-gnu/libswscale.so and b/packages/compositor-linux-x64-gnu/libswscale.so differdiff --git a/packages/compositor-linux-x64-gnu/remotion b/packages/compositor-linux-x64-gnu/remotionindex 10880cc74d..4a73ff4ea8 100755Binary files a/packages/compositor-linux-x64-gnu/remotion and b/packages/compositor-linux-x64-gnu/remotion differdiff --git a/packages/compositor-linux-x64-musl/ffmpeg b/packages/compositor-linux-x64-musl/ffmpegindex b590645b26..410b107656 100755Binary files a/packages/compositor-linux-x64-musl/ffmpeg and b/packages/compositor-linux-x64-musl/ffmpeg differdiff --git a/packages/compositor-linux-x64-musl/ffprobe b/packages/compositor-linux-x64-musl/ffprobeindex 2e0e385fe4..62816dbceb 100755Binary files a/packages/compositor-linux-x64-musl/ffprobe and b/packages/compositor-linux-x64-musl/ffprobe differdiff --git a/packages/compositor-linux-x64-musl/libavcodec.so b/packages/compositor-linux-x64-musl/libavcodec.soindex 6d2d90eff4..c4ca1db6ee 100755Binary files a/packages/compositor-linux-x64-musl/libavcodec.so and b/packages/compositor-linux-x64-musl/libavcodec.so differdiff --git a/packages/compositor-linux-x64-musl/libavdevice.so b/packages/compositor-linux-x64-musl/libavdevice.soindex f05d5b8cda..e2eff401a9 100755Binary files a/packages/compositor-linux-x64-musl/libavdevice.so and b/packages/compositor-linux-x64-musl/libavdevice.so differdiff --git a/packages/compositor-linux-x64-musl/libavfilter.so b/packages/compositor-linux-x64-musl/libavfilter.soindex a3158b05d9..89c128f354 100755Binary files a/packages/compositor-linux-x64-musl/libavfilter.so and b/packages/compositor-linux-x64-musl/libavfilter.so differdiff --git a/packages/compositor-linux-x64-musl/libavformat.so b/packages/compositor-linux-x64-musl/libavformat.soindex 4084523f7b..2f58b6072b 100755Binary files a/packages/compositor-linux-x64-musl/libavformat.so and b/packages/compositor-linux-x64-musl/libavformat.so differdiff --git a/packages/compositor-linux-x64-musl/libavutil.so b/packages/compositor-linux-x64-musl/libavutil.soindex a7245b6426..5be7bbe498 100755Binary files a/packages/compositor-linux-x64-musl/libavutil.so and b/packages/compositor-linux-x64-musl/libavutil.so differdiff --git a/packages/compositor-linux-x64-musl/libswresample.so b/packages/compositor-linux-x64-musl/libswresample.soindex 59678e114a..9115742abc 100755Binary files a/packages/compositor-linux-x64-musl/libswresample.so and b/packages/compositor-linux-x64-musl/libswresample.so differdiff --git a/packages/compositor-linux-x64-musl/libswscale.so b/packages/compositor-linux-x64-musl/libswscale.soindex 31d56475a0..f4310e59eb 100755Binary files a/packages/compositor-linux-x64-musl/libswscale.so and b/packages/compositor-linux-x64-musl/libswscale.so differdiff --git a/packages/compositor-linux-x64-musl/remotion b/packages/compositor-linux-x64-musl/remotionindex eca3dcd80c..266b78ed84 100755Binary files a/packages/compositor-linux-x64-musl/remotion and b/packages/compositor-linux-x64-musl/remotion differdiff --git a/packages/compositor-win32-x64-msvc/avcodec-61.dll b/packages/compositor-win32-x64-msvc/avcodec-61.dllindex fde939f164..d74aa3f2b4 100755Binary files a/packages/compositor-win32-x64-msvc/avcodec-61.dll and b/packages/compositor-win32-x64-msvc/avcodec-61.dll differdiff --git a/packages/compositor-win32-x64-msvc/avdevice-61.dll b/packages/compositor-win32-x64-msvc/avdevice-61.dllindex 00b1978c46..a71e370f6c 100755Binary files a/packages/compositor-win32-x64-msvc/avdevice-61.dll and b/packages/compositor-win32-x64-msvc/avdevice-61.dll differdiff --git a/packages/compositor-win32-x64-msvc/avfilter-10.dll b/packages/compositor-win32-x64-msvc/avfilter-10.dllindex 5ee208e5b4..a33e538674 100755Binary files a/packages/compositor-win32-x64-msvc/avfilter-10.dll and b/packages/compositor-win32-x64-msvc/avfilter-10.dll differdiff --git a/packages/compositor-win32-x64-msvc/avformat-61.dll b/packages/compositor-win32-x64-msvc/avformat-61.dllindex 3f0deadc51..f57e0f51df 100755Binary files a/packages/compositor-win32-x64-msvc/avformat-61.dll and b/packages/compositor-win32-x64-msvc/avformat-61.dll differdiff --git a/packages/compositor-win32-x64-msvc/avutil-59.dll b/packages/compositor-win32-x64-msvc/avutil-59.dllindex 1f454e4e78..b63f939dcb 100755Binary files a/packages/compositor-win32-x64-msvc/avutil-59.dll and b/packages/compositor-win32-x64-msvc/avutil-59.dll differdiff --git a/packages/compositor-win32-x64-msvc/ffmpeg.exe b/packages/compositor-win32-x64-msvc/ffmpeg.exeindex 6899098cce..3d5e53d465 100755Binary files a/packages/compositor-win32-x64-msvc/ffmpeg.exe and b/packages/compositor-win32-x64-msvc/ffmpeg.exe differdiff --git a/packages/compositor-win32-x64-msvc/ffprobe.exe b/packages/compositor-win32-x64-msvc/ffprobe.exeindex 6ecbd25642..110ee48cf7 100755Binary files a/packages/compositor-win32-x64-msvc/ffprobe.exe and b/packages/compositor-win32-x64-msvc/ffprobe.exe differdiff --git a/packages/compositor-win32-x64-msvc/libgcc_s_seh-1.dll b/packages/compositor-win32-x64-msvc/libgcc_s_seh-1.dllindex 03aaf66a5a..d39dcd447e 100644Binary files a/packages/compositor-win32-x64-msvc/libgcc_s_seh-1.dll and b/packages/compositor-win32-x64-msvc/libgcc_s_seh-1.dll differdiff --git a/packages/compositor-win32-x64-msvc/libstdc++-6.dll b/packages/compositor-win32-x64-msvc/libstdc++-6.dllindex 18dc683361..921ea1b0a2 100644Binary files a/packages/compositor-win32-x64-msvc/libstdc++-6.dll and b/packages/compositor-win32-x64-msvc/libstdc++-6.dll differdiff --git a/packages/compositor-win32-x64-msvc/libvpx-1.dll b/packages/compositor-win32-x64-msvc/libvpx-1.dllindex c3ac173c94..9b4dcea701 100755Binary files a/packages/compositor-win32-x64-msvc/libvpx-1.dll and b/packages/compositor-win32-x64-msvc/libvpx-1.dll differdiff --git a/packages/compositor-win32-x64-msvc/libwinpthread-1.dll b/packages/compositor-win32-x64-msvc/libwinpthread-1.dllindex 020da4f7ee..52df15b9bb 100644Binary files a/packages/compositor-win32-x64-msvc/libwinpthread-1.dll and b/packages/compositor-win32-x64-msvc/libwinpthread-1.dll differdiff --git a/packages/compositor-win32-x64-msvc/swresample-5.dll b/packages/compositor-win32-x64-msvc/swresample-5.dllindex 90897e4232..902de128be 100755Binary files a/packages/compositor-win32-x64-msvc/swresample-5.dll and b/packages/compositor-win32-x64-msvc/swresample-5.dll differdiff --git a/packages/compositor-win32-x64-msvc/swscale-8.dll b/packages/compositor-win32-x64-msvc/swscale-8.dllindex 5d89ee0adb..b1a1d7aadd 100755Binary files a/packages/compositor-win32-x64-msvc/swscale-8.dll and b/packages/compositor-win32-x64-msvc/swscale-8.dll differdiff --git a/packages/compositor-win32-x64-msvc/zlib1.dll b/packages/compositor-win32-x64-msvc/zlib1.dllindex bc7d15559d..8a9be60e3a 100644Binary files a/packages/compositor-win32-x64-msvc/zlib1.dll and b/packages/compositor-win32-x64-msvc/zlib1.dll differdiff --git a/packages/compositor/Cargo.lock b/packages/compositor/Cargo.lockindex 5b885c2e3e..6da43410aa 100644--- a/packages/compositor/Cargo.lock+++ b/packages/compositor/Cargo.lock@@ -167,7 +167,7 @@ dependencies = [[[package]]name = "ffmpeg-next"version = "7.1.0"-source = "git+https://github.com/remotion-dev/rust-ffmpeg?rev=873696322d49c429bee3ba018e8e0512a53f8ff3#873696322d49c429bee3ba018e8e0512a53f8ff3"+source = "git+https://github.com/remotion-dev/rust-ffmpeg?rev=edc24627a8416b14e1259fe047ec2e9c8e9a2e18#edc24627a8416b14e1259fe047ec2e9c8e9a2e18"dependencies = ["bitflags 2.6.0","ffmpeg-sys-next",@@ -177,7 +177,7 @@ dependencies = [[[package]]name = "ffmpeg-sys-next"version = "7.1.0"-source = "git+https://github.com/remotion-dev/rust-ffmpeg-sys?rev=73b853fd67aaa48c929db647c5e8045dca9b491a#73b853fd67aaa48c929db647c5e8045dca9b491a"+source = "git+https://github.com/remotion-dev/rust-ffmpeg-sys?rev=b8edd4d52a09894d73888ea5f9281224c296c445#b8edd4d52a09894d73888ea5f9281224c296c445"dependencies = ["bindgen","cc",diff --git a/packages/compositor/Cargo.toml b/packages/compositor/Cargo.tomlindex 4c6dcbc2ec..3f8d22c62d 100644--- a/packages/compositor/Cargo.toml+++ b/packages/compositor/Cargo.toml@@ -15,9 +15,8 @@ lazy_static = "1.4"rayon-core = "1.12.1"sysinfo = "0.30.7"mp4 = { git = "https://github.com/jonnyburger/mp4-rust", rev = "92ba375738cc2f05a4d754e1f968cf2e97d06641" }-ffmpeg-next = { git = "https://github.com/remotion-dev/rust-ffmpeg", rev = "873696322d49c429bee3ba018e8e0512a53f8ff3" }+ffmpeg-next = { git = "https://github.com/remotion-dev/rust-ffmpeg", rev = "edc24627a8416b14e1259fe047ec2e9c8e9a2e18" }[[bin]]name = "remotion"path = "rust/main.rs"-diff --git a/packages/docs/docs/encoding.mdx b/packages/docs/docs/encoding.mdxindex d0bed6ccb8..e9f146626f 100644--- a/packages/docs/docs/encoding.mdx+++ b/packages/docs/docs/encoding.mdx@@ -35,7 +35,7 @@ Remotion supports 6 video codecs: `h264` (_default_), `h265`, `vp8`, `vp9`, `av1Very good</a></td>- <td>No</td>+ <td>macOS, Linux, Windows (NVIDIA GPU)</td></tr><tr><td>@@ -52,7 +52,7 @@ Remotion supports 6 video codecs: `h264` (_default_), `h265`, `vp8`, `vp9`, `av1Very poor</a></td>- <td>No</td>+ <td>macOS, Linux, Windows (NVIDIA GPU)</td></tr><tr><td>VP8</td>diff --git a/packages/docs/docs/hardware-acceleration.mdx b/packages/docs/docs/hardware-acceleration.mdxindex 830acaf55b..86c24ed27a 100644--- a/packages/docs/docs/hardware-acceleration.mdx+++ b/packages/docs/docs/hardware-acceleration.mdx@@ -12,7 +12,8 @@ Besides rendering frames, encoding is one of the two steps required to create aFrom Remotion v4.0.228, Remotion supports hardware-accelerated encoding in some cases.Since encoding is platform- and codec-specific, only a few scenarios are supported at the moment.-- Currently, only macOS is supported (Acceleration using VideoToolbox)+- macOS: Acceleration using VideoToolbox+- Linux and Windows: Acceleration using NVENC (requires an NVIDIA GPU)<AvailableFrom v="4.0.484" inline />- ProRes is supported from v4.0.228, H.264 and H.265 are supported from v4.0.236## Enable hardware accelerated encoding@@ -55,7 +56,7 @@ await renderMedia({### In the CLI-Use the [`--hardware-acceleration`](/docs/cli/render#--hardware-acceleration) option in the `npx remotion studio` command.+Use the [`--hardware-acceleration`](/docs/cli/render#--hardware-acceleration) option in the `npx remotion render` command.```bashnpx remotion render MyComp --codec prores --hardware-acceleration if-possible@@ -79,6 +80,21 @@ Config.setHardwareAcceleration('if-possible');These options are not supported in Remotion Lambda and Cloud Run, because those cloud services do not support hardware acceleration.+## Prerequisites for NVENC (Linux/Windows)++To use hardware-accelerated encoding on Linux and Windows, you need:++- An NVIDIA GPU (GeForce, Quadro, or Tesla)+- NVIDIA drivers installed (version 525+ recommended)+- FFmpeg compiled with `h264_nvenc` or `hevc_nvenc` encoder support++The FFmpeg binaries bundled with Remotion include NVENC support on Linux x64 only. NVENC on Linux ARM64 is not supported. On Windows, point Remotion to an FFmpeg build that includes NVENC using [`--binaries-directory`](/docs/cli/render#--binaries-directory) or [`binariesDirectory`](/docs/renderer/render-media#binariesdirectory).++Set `--hardware-acceleration if-possible` and Remotion will use NVENC if the configured FFmpeg build supports it.++Note that NVENC encoding is only available for H.264 and H.265 codecs. Other codecs will fall back to software encoding.++## Controlling quality using `--video-bitrate`Note that the file size is significantly larger by default when using hardware acceleration, likely because less compression is applied.@@ -95,6 +111,7 @@ If the render is using hardware acceleration, you will see a log message like th```Encoder: prores_videotoolbox, hardware accelerated: true+Encoder: h264_nvenc, hardware accelerated: true```Don't rely on the exact wording of the log message to determine if hardware acceleration is being used.diff --git a/packages/renderer/src/crf.ts b/packages/renderer/src/crf.tsindex b733782e77..3b71de759c 100644--- a/packages/renderer/src/crf.ts+++ b/packages/renderer/src/crf.ts@@ -60,6 +60,7 @@ export const validateQualitySettings = ({encodingMaxRate,encodingBufferSize,hardwareAcceleration,+ hardwareAccelerated,}: {crf: unknown;codec: Codec;@@ -67,14 +68,21 @@ export const validateQualitySettings = ({encodingMaxRate: string | null;encodingBufferSize: string | null;hardwareAcceleration: HardwareAccelerationOption;+ hardwareAccelerated: boolean;}): string[] => {- if (crf && videoBitrate) {+ const hasExplicitCrf = crf !== null && typeof crf !== 'undefined';++ if (hasExplicitCrf && videoBitrate) {throw new Error('"crf" and "videoBitrate" can not both be set. Choose one of either.',);}- if (crf && hardwareAcceleration === 'required') {+ if (hasExplicitCrf && hardwareAcceleration === 'required') {+ throw new Error('"crf" option is not supported with hardware acceleration');+ }++ if (hasExplicitCrf && hardwareAccelerated) {throw new Error('"crf" option is not supported with hardware acceleration');}@@ -104,6 +112,10 @@ export const validateQualitySettings = ({}if (crf === null || typeof crf === 'undefined') {+ if (hardwareAccelerated) {+ return [...bufSizeArray, ...maxRateArray];+ }+const actualCrf = getDefaultCrfForCodec(codec);if (actualCrf === null) {return [...bufSizeArray, ...maxRateArray];diff --git a/packages/renderer/src/ffmpeg-args.ts b/packages/renderer/src/ffmpeg-args.tsindex 93780cbead..1911484cc5 100644--- a/packages/renderer/src/ffmpeg-args.ts+++ b/packages/renderer/src/ffmpeg-args.ts@@ -22,6 +22,7 @@ const firstEncodingStepOnly = ({encodingMaxRate,encodingBufferSize,hardwareAcceleration,+ hardwareAccelerated,}: {hasPreencoded: boolean;proResProfileName: string | null;@@ -34,6 +35,7 @@ const firstEncodingStepOnly = ({encodingMaxRate: string | null;encodingBufferSize: string | null;hardwareAcceleration: HardwareAccelerationOption;+ hardwareAccelerated: boolean;}): string[][] => {if (hasPreencoded || codec === 'gif') {return [];@@ -60,6 +62,7 @@ const firstEncodingStepOnly = ({encodingMaxRate,encodingBufferSize,hardwareAcceleration,+ hardwareAccelerated,}),].filter(truthy);};@@ -173,6 +176,7 @@ export const generateFfmpegArgs = ({x264Preset,gopSize,hardwareAcceleration,+ hardwareAccelerated,}),].filter(truthy);};diff --git a/packages/renderer/src/get-codec-name.ts b/packages/renderer/src/get-codec-name.tsindex 25cff3e615..e0a6ec239d 100644--- a/packages/renderer/src/get-codec-name.ts+++ b/packages/renderer/src/get-codec-name.ts@@ -84,6 +84,18 @@ export const getCodecName = ({return {encoderName: 'prores_videotoolbox', hardwareAccelerated: true};}+ if (+ preferredHwAcceleration &&+ process.platform !== 'darwin' &&+ !unsupportedQualityOption+ ) {+ if (hardwareAcceleration === 'required') {+ throw new Error(+ `Codec "prores" does not support hardware acceleration on ${process.platform}, but "hardwareAcceleration" is set to "required"`,+ );+ }+ }+warnAboutDisabledHardwareAcceleration();return {encoderName: 'prores_ks', hardwareAccelerated: false};@@ -98,6 +110,15 @@ export const getCodecName = ({return {encoderName: 'h264_videotoolbox', hardwareAccelerated: true};}+ // NVENC for Linux/Windows+ if (+ preferredHwAcceleration &&+ (process.platform === 'linux' || process.platform === 'win32') &&+ !unsupportedQualityOption+ ) {+ return {encoderName: 'h264_nvenc', hardwareAccelerated: true};+ }+warnAboutDisabledHardwareAcceleration();return {encoderName: 'libx264', hardwareAccelerated: false};@@ -112,6 +133,15 @@ export const getCodecName = ({return {encoderName: 'hevc_videotoolbox', hardwareAccelerated: true};}+ // NVENC for Linux/Windows+ if (+ preferredHwAcceleration &&+ (process.platform === 'linux' || process.platform === 'win32') &&+ !unsupportedQualityOption+ ) {+ return {encoderName: 'hevc_nvenc', hardwareAccelerated: true};+ }+warnAboutDisabledHardwareAcceleration();return {encoderName: 'libx265', hardwareAccelerated: false};@@ -150,10 +180,22 @@ export const getCodecName = ({}if (codec === 'h264-mkv') {+ if (hardwareAcceleration === 'required') {+ throw new Error(+ `Codec "h264-mkv" does not support hardware acceleration on ${process.platform}, but "hardwareAcceleration" is set to "required"`,+ );+ }+return {encoderName: 'libx264', hardwareAccelerated: false};}if (codec === 'h264-ts') {+ if (hardwareAcceleration === 'required') {+ throw new Error(+ `Codec "h264-ts" does not support hardware acceleration on ${process.platform}, but "hardwareAcceleration" is set to "required"`,+ );+ }+return {encoderName: 'libx264', hardwareAccelerated: false};}diff --git a/packages/renderer/src/prespawn-ffmpeg.ts b/packages/renderer/src/prespawn-ffmpeg.tsindex 31b83610e8..987a4d1bd9 100644--- a/packages/renderer/src/prespawn-ffmpeg.ts+++ b/packages/renderer/src/prespawn-ffmpeg.ts@@ -18,6 +18,7 @@ import {DEFAULT_PIXEL_FORMAT,validateSelectedPixelFormatAndCodecCombination,} from './pixel-format';+import {resolveHardwareAcceleration} from './probe-encoder';import {validateDimension, validateFps} from './validate';import {validateEvenDimensionsWithCodec} from './validate-even-dimensions-with-codec';@@ -89,6 +90,17 @@ export const prespawnFfmpeg = (options: PreStitcherOptions) => {validateSelectedPixelFormatAndCodecCombination(pixelFormat, codec);+ const resolvedHardwareAcceleration = resolveHardwareAcceleration({+ codec,+ hardwareAcceleration: options.hardwareAcceleration,+ binariesDirectory: options.binariesDirectory,+ indent: options.indent,+ logLevel: options.logLevel,+ crf: options.crf,+ encodingMaxRate: options.encodingMaxRate,+ encodingBufferSize: options.encodingBufferSize,+ });+const ffmpegArgs = [['-r', options.fps],...[@@ -111,7 +123,7 @@ export const prespawnFfmpeg = (options: PreStitcherOptions) => {encodingMaxRate: options.encodingMaxRate,encodingBufferSize: options.encodingBufferSize,colorSpace: options.colorSpace,- hardwareAcceleration: options.hardwareAcceleration,+ hardwareAcceleration: resolvedHardwareAcceleration,indent: options.indent,logLevel: options.logLevel,}),diff --git a/packages/renderer/src/probe-encoder.ts b/packages/renderer/src/probe-encoder.tsnew file mode 100644index 0000000000..f7836e165f--- /dev/null+++ b/packages/renderer/src/probe-encoder.ts@@ -0,0 +1,140 @@+import {execFileSync} from 'node:child_process';+import path from 'path';+import type {Codec} from './codec';+import {getExecutablePath} from './compositor/get-executable-path';+import {getExplicitEnv} from './compositor/get-explicit-env';+import {makeFileExecutableIfItIsNot} from './compositor/make-file-executable';+import {getCodecName} from './get-codec-name';+import type {LogLevel} from './log-level';+import {Log} from './logger';+import type {HardwareAccelerationOption} from './options/hardware-acceleration';++/**+ * Probes FFmpeg to check if a specific encoder is available.+ * Returns true if the encoder is supported, false otherwise.+ */+export const probeEncoderAvailability = ({+ encoderName,+ binariesDirectory,+ indent,+ logLevel,+}: {+ encoderName: string;+ binariesDirectory: string | null;+ indent: boolean;+ logLevel: LogLevel;+}): boolean => {+ try {+ const executablePath = getExecutablePath({+ type: 'ffmpeg',+ indent,+ logLevel,+ binariesDirectory,+ });+ makeFileExecutableIfItIsNot(executablePath);++ const cwd = path.dirname(executablePath);+ const result = execFileSync(executablePath, ['-encoders'], {+ encoding: 'utf-8',+ env: getExplicitEnv(cwd),+ stdio: ['pipe', 'pipe', 'pipe'],+ timeout: 10000,+ });++ // FFmpeg -encoders output format: " V..... encoder_name"+ // Escape regex metacharacters and use word-boundary to avoid false positives+ const escaped = encoderName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');+ const encoderRegex = new RegExp(`\\b${escaped}\\b`);+ const hasEncoder = encoderRegex.test(result);+ if (!hasEncoder) {+ Log.verbose(+ {indent, logLevel, tag: 'probeEncoderAvailability()'},+ `Encoder "${encoderName}" not found in FFmpeg build. Falling back to software encoding.`,+ );+ }++ return hasEncoder;+ } catch (err) {+ Log.verbose(+ {indent, logLevel, tag: 'probeEncoderAvailability()'},+ `Failed to probe FFmpeg for encoder "${encoderName}": ${err}. Falling back to software encoding.`,+ );+ return false;+ }+};++/**+ * Resolves the effective hardware acceleration setting by probing FFmpeg+ * for encoder availability. If the preferred hw encoder is not available:+ * - `if-possible` mode: falls back to software encoding+ * - `required` mode: throws a clear error+ */+export const resolveHardwareAcceleration = ({+ codec,+ hardwareAcceleration,+ binariesDirectory,+ indent,+ logLevel,+ crf,+ encodingMaxRate,+ encodingBufferSize,+}: {+ codec: Codec;+ hardwareAcceleration: HardwareAccelerationOption;+ binariesDirectory: string | null;+ indent: boolean;+ logLevel: LogLevel;+ crf: unknown;+ encodingMaxRate: string | null;+ encodingBufferSize: string | null;+}): HardwareAccelerationOption => {+ if (hardwareAcceleration === 'disable') {+ return 'disable';+ }++ const preferred = getCodecName({+ codec,+ hardwareAcceleration,+ crf,+ encodingMaxRate,+ encodingBufferSize,+ logLevel,+ indent,+ });++ // Audio codecs return null, no probing needed+ if (preferred === null) {+ return hardwareAcceleration;+ }++ // Only probe if getCodecName selected a hardware-accelerated encoder+ if (!preferred.hardwareAccelerated) {+ return hardwareAcceleration;+ }++ const encoderAvailable = probeEncoderAvailability({+ encoderName: preferred.encoderName,+ binariesDirectory,+ indent,+ logLevel,+ });++ if (encoderAvailable) {+ return hardwareAcceleration;+ }++ // Encoder not available in FFmpeg+ if (hardwareAcceleration === 'if-possible') {+ Log.verbose(+ {indent, logLevel, tag: 'resolveHardwareAcceleration()'},+ `Hardware encoder "${preferred.encoderName}" not available. Falling back to software encoding.`,+ );+ return 'disable';+ }++ // hardwareAcceleration === 'required'+ throw new Error(+ `Hardware encoder "${preferred.encoderName}" is not available in your FFmpeg build. ` ++ `Install an FFmpeg with ${preferred.encoderName} support, or use "if-possible" mode instead of "required".`,+ );+};diff --git a/packages/renderer/src/render-media.ts b/packages/renderer/src/render-media.tsindex d795244c61..0d11ea9f3e 100644--- a/packages/renderer/src/render-media.ts+++ b/packages/renderer/src/render-media.ts@@ -315,6 +315,7 @@ const internalRenderMediaRaw = ({encodingMaxRate,encodingBufferSize,hardwareAcceleration,+ hardwareAccelerated: false,});validateGopSize(gopSize);validateBitrate(audioBitrate, 'audioBitrate');diff --git a/packages/renderer/src/stitch-frames-to-video.ts b/packages/renderer/src/stitch-frames-to-video.tsindex 8be53c40af..24d60f4595 100644--- a/packages/renderer/src/stitch-frames-to-video.ts+++ b/packages/renderer/src/stitch-frames-to-video.ts@@ -35,12 +35,12 @@ import {DEFAULT_PIXEL_FORMAT,validateSelectedPixelFormatAndCodecCombination,} from './pixel-format';+import {resolveHardwareAcceleration} from './probe-encoder';import {validateSelectedCodecAndProResCombination} from './prores-profile';import {getShouldRenderAudio} from './render-has-audio';import {validateDimension, validateFps} from './validate';import {validateEvenDimensionsWithCodec} from './validate-even-dimensions-with-codec';import {validateBitrate} from './validate-videobitrate';-type InternalStitchFramesToVideoOptions = {audioBitrate: string | null;videoBitrate: string | null;@@ -266,6 +266,7 @@ const innerStitchFramesToVideo = async (encodingMaxRate: maxRate,encodingBufferSize: bufferSize,hardwareAcceleration,+ hardwareAccelerated: false,});validateSelectedPixelFormatAndCodecCombination(pixelFormat, codec);@@ -347,6 +348,17 @@ const innerStitchFramesToVideo = async (return Promise.resolve(file);}+ const resolvedHardwareAcceleration = resolveHardwareAcceleration({+ codec,+ hardwareAcceleration,+ binariesDirectory,+ indent: indent ?? false,+ logLevel,+ crf,+ encodingMaxRate: maxRate,+ encodingBufferSize: bufferSize,+ });+const ffmpegArgs = [...(preEncodedFileLocation? [['-i', preEncodedFileLocation]]@@ -376,7 +388,7 @@ const innerStitchFramesToVideo = async (x264Preset,gopSize,colorSpace,- hardwareAcceleration,+ hardwareAcceleration: resolvedHardwareAcceleration,indent,logLevel,}),diff --git a/packages/renderer/src/test/crf.test.ts b/packages/renderer/src/test/crf.test.tsindex f5e55f237d..47e758d2f7 100644--- a/packages/renderer/src/test/crf.test.ts+++ b/packages/renderer/src/test/crf.test.ts@@ -53,6 +53,7 @@ describe('validateSelectedCrfAndCodecCombination valid input', () => {encodingMaxRate: null,encodingBufferSize: null,hardwareAcceleration: 'if-possible',+ hardwareAccelerated: false,}),).not.toThrow()),);@@ -87,6 +88,7 @@ describe('validateSelectedCrfAndCodecCombination invalid input', () => {encodingMaxRate: null,encodingBufferSize: null,hardwareAcceleration: 'if-possible',+ hardwareAccelerated: false,}),).toThrow(new RegExp(@@ -105,6 +107,7 @@ test('ProRes', () => {encodingMaxRate: null,encodingBufferSize: null,hardwareAcceleration: 'if-possible',+ hardwareAccelerated: false,}),).toThrow(/The "prores" codec does not support the --crf option\./);});@@ -118,6 +121,7 @@ test('WAV', () => {encodingMaxRate: null,encodingBufferSize: null,hardwareAcceleration: 'if-possible',+ hardwareAccelerated: false,}),).toThrow(/The "wav" codec does not support the --crf option\./);});@@ -131,6 +135,7 @@ test('WAV', () => {encodingMaxRate: null,encodingBufferSize: null,hardwareAcceleration: 'if-possible',+ hardwareAccelerated: false,}),).toThrow(/"crf" and "videoBitrate" can not both be set. Choose one of either./,@@ -146,6 +151,7 @@ test('encodingMaxRate', () => {encodingMaxRate: '1M',encodingBufferSize: null,hardwareAcceleration: 'if-possible',+ hardwareAccelerated: false,}),).toThrow(/"encodingMaxRate" can not be set without also setting "encodingBufferSize"./,diff --git a/packages/renderer/src/test/ffmpeg-args.test.ts b/packages/renderer/src/test/ffmpeg-args.test.tsnew file mode 100644index 0000000000..1648a7f145--- /dev/null+++ b/packages/renderer/src/test/ffmpeg-args.test.ts@@ -0,0 +1,81 @@+import {afterEach, expect, test} from 'bun:test';+import type {Codec} from '../codec';+import {generateFfmpegArgs} from '../ffmpeg-args';+import type {HardwareAccelerationOption} from '../options/hardware-acceleration';++const originalPlatform = process.platform;++const setPlatform = (platform: string) => {+ Object.defineProperty(process, 'platform', {value: platform});+};++const restorePlatform = () => {+ Object.defineProperty(process, 'platform', {value: originalPlatform});+};++afterEach(restorePlatform);++const makeArgs = ({+ codec,+ crf = null,+ hardwareAcceleration,+}: {+ codec: Codec;+ crf?: number | null;+ hardwareAcceleration: HardwareAccelerationOption;+}) =>+ generateFfmpegArgs({+ hasPreencoded: false,+ proResProfileName: null,+ pixelFormat: 'yuv420p',+ x264Preset: null,+ gopSize: null,+ codec,+ crf,+ videoBitrate: null,+ encodingMaxRate: null,+ encodingBufferSize: null,+ colorSpace: 'default',+ hardwareAcceleration,+ indent: false,+ logLevel: 'info',+ }).flat();++test('does not pass the default CRF option to hardware encoders', () => {+ setPlatform('linux');++ const args = makeArgs({+ codec: 'h264',+ hardwareAcceleration: 'if-possible',+ });++ expect(args).toContain('h264_nvenc');+ expect(args).not.toContain('-crf');+});++test('keeps default CRF for software encoders when hardware acceleration is not used', () => {+ setPlatform('linux');++ const args = makeArgs({+ codec: 'vp8',+ hardwareAcceleration: 'if-possible',+ });++ expect(args).toContain('libvpx');+ expect(args).toContain('-crf');+ expect(args).toContain('9');+});++test('keeps explicit CRF when if-possible falls back to software', () => {+ setPlatform('linux');++ const args = makeArgs({+ codec: 'h264',+ crf: 20,+ hardwareAcceleration: 'if-possible',+ });++ expect(args).toContain('libx264');+ expect(args).toContain('-crf');+ expect(args).toContain('20');+});diff --git a/packages/renderer/src/test/get-codec-name.test.ts b/packages/renderer/src/test/get-codec-name.test.tsnew file mode 100644index 0000000000..27d58642ef--- /dev/null+++ b/packages/renderer/src/test/get-codec-name.test.ts@@ -0,0 +1,265 @@+import {afterAll, afterEach, describe, expect, mock, test} from 'bun:test';+import type {Codec} from '../codec';+import type {HardwareAccelerationOption} from '../options/hardware-acceleration';++// Mock remotion/version before importing the module under test+mock.module('remotion/version', () => ({+ VERSION: '4.0.0-test',+}));++const {getCodecName} = require('../get-codec-name');++const originalPlatform = process.platform;++const setPlatform = (platform: string) => {+ Object.defineProperty(process, 'platform', {value: platform});+};++const restorePlatform = () => {+ Object.defineProperty(process, 'platform', {value: originalPlatform});+};++const callGetCodecName = ({+ codec,+ hardwareAcceleration,+ crf,+ encodingMaxRate = null,+ encodingBufferSize = null,+}: {+ codec: Codec;+ hardwareAcceleration: HardwareAccelerationOption;+ crf?: number;+ encodingMaxRate?: string | null;+ encodingBufferSize?: string | null;+}) =>+ getCodecName({+ codec,+ hardwareAcceleration,+ crf: crf ?? null,+ encodingMaxRate,+ encodingBufferSize,+ logLevel: 'warn',+ indent: false,+ });++describe('getCodecName - macOS VideoToolbox (existing behavior)', () => {+ afterEach(restorePlatform);++ test('h264 + darwin + hwaccel:required + no CRF', () => {+ setPlatform('darwin');+ expect(+ callGetCodecName({codec: 'h264', hardwareAcceleration: 'required'}),+ ).toEqual({encoderName: 'h264_videotoolbox', hardwareAccelerated: true});+ });++ test('h265 + darwin + hwaccel:required + no CRF', () => {+ setPlatform('darwin');+ expect(+ callGetCodecName({codec: 'h265', hardwareAcceleration: 'required'}),+ ).toEqual({encoderName: 'hevc_videotoolbox', hardwareAccelerated: true});+ });++ test('prores + darwin + hwaccel:required + no CRF', () => {+ setPlatform('darwin');+ expect(+ callGetCodecName({codec: 'prores', hardwareAcceleration: 'required'}),+ ).toEqual({+ encoderName: 'prores_videotoolbox',+ hardwareAccelerated: true,+ });+ });++ test('h264 + darwin + hwaccel:required + crf=20 throws error', () => {+ setPlatform('darwin');+ expect(() =>+ callGetCodecName({+ codec: 'h264',+ hardwareAcceleration: 'required',+ crf: 20,+ }),+ ).toThrow(/hardware accelerated encoding/);+ });++ test('h264 + darwin + hwaccel:disable returns software encoder', () => {+ setPlatform('darwin');+ expect(+ callGetCodecName({codec: 'h264', hardwareAcceleration: 'disable'}),+ ).toEqual({encoderName: 'libx264', hardwareAccelerated: false});+ });+});++describe('getCodecName - NVENC on Linux', () => {+ afterEach(restorePlatform);++ test('h264 + linux + hwaccel:if-possible + no CRF', () => {+ setPlatform('linux');+ expect(+ callGetCodecName({codec: 'h264', hardwareAcceleration: 'if-possible'}),+ ).toEqual({encoderName: 'h264_nvenc', hardwareAccelerated: true});+ });++ test('h265 + linux + hwaccel:if-possible + no CRF', () => {+ setPlatform('linux');+ expect(+ callGetCodecName({codec: 'h265', hardwareAcceleration: 'if-possible'}),+ ).toEqual({encoderName: 'hevc_nvenc', hardwareAccelerated: true});+ });++ test('h264 + linux + hwaccel:required + no CRF', () => {+ setPlatform('linux');+ expect(+ callGetCodecName({codec: 'h264', hardwareAcceleration: 'required'}),+ ).toEqual({encoderName: 'h264_nvenc', hardwareAccelerated: true});+ });++ test('h264 + linux + hwaccel:if-possible + crf=20 falls back to software', () => {+ setPlatform('linux');+ expect(+ callGetCodecName({+ codec: 'h264',+ hardwareAcceleration: 'if-possible',+ crf: 20,+ }),+ ).toEqual({encoderName: 'libx264', hardwareAccelerated: false});+ });+});++describe('getCodecName - NVENC on Windows', () => {+ afterEach(restorePlatform);++ test('h264 + win32 + hwaccel:if-possible + no CRF', () => {+ setPlatform('win32');+ expect(+ callGetCodecName({codec: 'h264', hardwareAcceleration: 'if-possible'}),+ ).toEqual({encoderName: 'h264_nvenc', hardwareAccelerated: true});+ });++ test('h265 + win32 + hwaccel:if-possible + no CRF', () => {+ setPlatform('win32');+ expect(+ callGetCodecName({codec: 'h265', hardwareAcceleration: 'if-possible'}),+ ).toEqual({encoderName: 'hevc_nvenc', hardwareAccelerated: true});+ });++ test('h264 + win32 + hwaccel:required + no CRF', () => {+ setPlatform('win32');+ expect(+ callGetCodecName({codec: 'h264', hardwareAcceleration: 'required'}),+ ).toEqual({encoderName: 'h264_nvenc', hardwareAccelerated: true});+ });++ test('h265 + win32 + hwaccel:required + no CRF', () => {+ setPlatform('win32');+ expect(+ callGetCodecName({codec: 'h265', hardwareAcceleration: 'required'}),+ ).toEqual({encoderName: 'hevc_nvenc', hardwareAccelerated: true});+ });++ test('h264 + win32 + hwaccel:if-possible + crf=20 falls back to software', () => {+ setPlatform('win32');+ expect(+ callGetCodecName({+ codec: 'h264',+ hardwareAcceleration: 'if-possible',+ crf: 20,+ }),+ ).toEqual({encoderName: 'libx264', hardwareAccelerated: false});+ });++ test('h265 + win32 + hwaccel:if-possible + crf=20 falls back to software', () => {+ setPlatform('win32');+ expect(+ callGetCodecName({+ codec: 'h265',+ hardwareAcceleration: 'if-possible',+ crf: 20,+ }),+ ).toEqual({encoderName: 'libx265', hardwareAccelerated: false});+ });+});++describe('getCodecName - No hardware acceleration for unsupported codecs', () => {+ afterEach(restorePlatform);++ test('vp8 + linux + hwaccel:required returns software', () => {+ setPlatform('linux');+ expect(+ callGetCodecName({codec: 'vp8', hardwareAcceleration: 'required'}),+ ).toEqual({encoderName: 'libvpx', hardwareAccelerated: false});+ });++ test('vp9 + linux + hwaccel:required returns software', () => {+ setPlatform('linux');+ expect(+ callGetCodecName({codec: 'vp9', hardwareAcceleration: 'required'}),+ ).toEqual({encoderName: 'libvpx-vp9', hardwareAccelerated: false});+ });++ test('av1 + linux + hwaccel:required returns software', () => {+ setPlatform('linux');+ expect(+ callGetCodecName({codec: 'av1', hardwareAcceleration: 'required'}),+ ).toEqual({encoderName: 'libaom-av1', hardwareAccelerated: false});+ });++ test('prores + linux + hwaccel:required throws error (no NVENC ProRes)', () => {+ setPlatform('linux');+ expect(() =>+ callGetCodecName({codec: 'prores', hardwareAcceleration: 'required'}),+ ).toThrow(/does not support hardware acceleration/);+ });++ test('h264-mkv + linux + hwaccel:required throws error', () => {+ setPlatform('linux');+ expect(() =>+ callGetCodecName({codec: 'h264-mkv', hardwareAcceleration: 'required'}),+ ).toThrow(/does not support hardware acceleration/);+ });++ test('h264-ts + linux + hwaccel:required throws error', () => {+ setPlatform('linux');+ expect(() =>+ callGetCodecName({codec: 'h264-ts', hardwareAcceleration: 'required'}),+ ).toThrow(/does not support hardware acceleration/);+ });+});++describe('getCodecName - software fallback', () => {+ afterEach(restorePlatform);++ test('h264 + linux + hwaccel:disable returns software', () => {+ setPlatform('linux');+ expect(+ callGetCodecName({codec: 'h264', hardwareAcceleration: 'disable'}),+ ).toEqual({encoderName: 'libx264', hardwareAccelerated: false});+ });++ test('h265 + win32 + hwaccel:disable returns software', () => {+ setPlatform('win32');+ expect(+ callGetCodecName({codec: 'h265', hardwareAcceleration: 'disable'}),+ ).toEqual({encoderName: 'libx265', hardwareAccelerated: false});+ });+});++describe('getCodecName - audio codecs return null', () => {+ test('mp3 returns null', () => {+ expect(+ callGetCodecName({codec: 'mp3', hardwareAcceleration: 'disable'}),+ ).toBeNull();+ });++ test('aac returns null', () => {+ expect(+ callGetCodecName({codec: 'aac', hardwareAcceleration: 'disable'}),+ ).toBeNull();+ });++ test('wav returns null', () => {+ expect(+ callGetCodecName({codec: 'wav', hardwareAcceleration: 'disable'}),+ ).toBeNull();+ });+});++afterAll(restorePlatform);diff --git a/packages/renderer/src/test/probe-encoder.test.ts b/packages/renderer/src/test/probe-encoder.test.tsnew file mode 100644index 0000000000..275707550b--- /dev/null+++ b/packages/renderer/src/test/probe-encoder.test.ts@@ -0,0 +1,157 @@+import {afterEach, describe, expect, mock, test} from 'bun:test';++// Mock remotion/version before importing+mock.module('remotion/version', () => ({+ VERSION: '4.0.0-test',+}));++const {resolveHardwareAcceleration} = require('../probe-encoder');++/**+ * Tests for resolveHardwareAcceleration that DO NOT trigger actual FFmpeg probing.+ * These test the logic branches that short-circuit before any execFileSync call:+ * - "disable" passthrough+ * - Audio codec passthrough (getCodecName returns null)+ * - Software encoder passthrough (getCodecName returns non-hw-accelerated)+ *+ * Probing-dependent paths (if-possible/required with hardware encoders) are+ * exercised by integration tests that run with the real FFmpeg binary.+ */+describe('resolveHardwareAcceleration', () => {+ const originalPlatform = process.platform;+ const setPlatform = (platform: string) => {+ Object.defineProperty(process, 'platform', {value: platform});+ };++ const restorePlatform = () => {+ Object.defineProperty(process, 'platform', {value: originalPlatform});+ };++ test('returns "disable" when hardwareAcceleration is "disable"', () => {+ expect(+ resolveHardwareAcceleration({+ codec: 'h264',+ hardwareAcceleration: 'disable',+ binariesDirectory: null,+ indent: false,+ logLevel: 'warn',+ crf: null,+ encodingMaxRate: null,+ encodingBufferSize: null,+ }),+ ).toBe('disable');+ });++ test('returns original value for audio codecs (null from getCodecName)', () => {+ expect(+ resolveHardwareAcceleration({+ codec: 'mp3',+ hardwareAcceleration: 'if-possible',+ binariesDirectory: null,+ indent: false,+ logLevel: 'warn',+ crf: null,+ encodingMaxRate: null,+ encodingBufferSize: null,+ }),+ ).toBe('if-possible');+ });++ test('returns original value for aac codec', () => {+ expect(+ resolveHardwareAcceleration({+ codec: 'aac',+ hardwareAcceleration: 'required',+ binariesDirectory: null,+ indent: false,+ logLevel: 'warn',+ crf: null,+ encodingMaxRate: null,+ encodingBufferSize: null,+ }),+ ).toBe('required');+ });++ test('returns original value for wav codec', () => {+ expect(+ resolveHardwareAcceleration({+ codec: 'wav',+ hardwareAcceleration: 'if-possible',+ binariesDirectory: null,+ indent: false,+ logLevel: 'warn',+ crf: null,+ encodingMaxRate: null,+ encodingBufferSize: null,+ }),+ ).toBe('if-possible');+ });++ describe('software encoder passthrough', () => {+ afterEach(restorePlatform);++ test('returns original value when getCodecName returns software (CRF set on linux)', () => {+ setPlatform('linux');+ expect(+ resolveHardwareAcceleration({+ codec: 'h264',+ hardwareAcceleration: 'if-possible',+ binariesDirectory: null,+ indent: false,+ logLevel: 'warn',+ crf: 20,+ encodingMaxRate: null,+ encodingBufferSize: null,+ }),+ ).toBe('if-possible');+ });++ test('returns original value when codec has no hw encoder (vp8)', () => {+ setPlatform('linux');+ expect(+ resolveHardwareAcceleration({+ codec: 'vp8',+ hardwareAcceleration: 'if-possible',+ binariesDirectory: null,+ indent: false,+ logLevel: 'warn',+ crf: null,+ encodingMaxRate: null,+ encodingBufferSize: null,+ }),+ ).toBe('if-possible');+ });++ test('returns original value when codec has no hw encoder (av1)', () => {+ setPlatform('linux');+ expect(+ resolveHardwareAcceleration({+ codec: 'av1',+ hardwareAcceleration: 'if-possible',+ binariesDirectory: null,+ indent: false,+ logLevel: 'warn',+ crf: null,+ encodingMaxRate: null,+ encodingBufferSize: null,+ }),+ ).toBe('if-possible');+ });++ test('returns "disable" when hardwareAcceleration is "disable" even with NVENC-capable codec', () => {+ setPlatform('linux');+ expect(+ resolveHardwareAcceleration({+ codec: 'h264',+ hardwareAcceleration: 'disable',+ binariesDirectory: null,+ indent: false,+ logLevel: 'warn',+ crf: null,+ encodingMaxRate: null,+ encodingBufferSize: null,+ }),+ ).toBe('disable');+ });+ });+});