diff --git a/compile-ffmpeg.mjs b/compile-ffmpeg.mjs index 3e5b8e6..9745c6d 100644 --- a/compile-ffmpeg.mjs +++ b/compile-ffmpeg.mjs @@ -12,6 +12,7 @@ import { enableAv1 } from "./compile-av1.mjs"; import { enableFdkAac } from "./compile-fdkaac.mjs"; import { enableZimg } from "./compile-zimg.mjs"; import { fixLinuxLinks } from "./fix-linux-links.mjs"; +import { enableNvencHeaders } from "./compile-nvenc.mjs"; if (existsSync("/opt/homebrew/opt/libx11/lib/libX11.6.dylib")) { console.log( @@ -137,6 +138,7 @@ enableX264(isMusl, isWindows); enableX265(isMusl, isWindows, isOldCmake); enableLibMp3Lame(isWindows); enableOpus(isWindows); +enableNvencHeaders(isWindows); const TAG = "n7.1"; @@ -288,6 +290,12 @@ execSync( process.platform === "darwin" ? "--enable-encoder=prores_videotoolbox" : null, + !isWindows && process.platform === "linux" + ? "--enable-encoder=h264_nvenc" + : null, + !isWindows && process.platform === "linux" + ? "--enable-encoder=hevc_nvenc" + : null, "--disable-muxers", "--enable-muxer=webm,opus,mp4,wav,mp3,mov,matroska,hevc,h264,gif,image2,image2pipe,adts,m4a,mpegts,null,avi", "--enable-libx264", diff --git a/compile-nvenc.mjs b/compile-nvenc.mjs new file mode 100644 index 0000000..48d8152 --- /dev/null +++ b/compile-nvenc.mjs @@ -0,0 +1,33 @@ +import { execSync } from "child_process"; +import { existsSync } from "fs"; +import { PREFIX } from "./const.mjs"; + +const NV_CODEC_HEADERS_TAG = "n12.2.16.0"; + +export const enableNvencHeaders = (isWindows) => { + // Only install on native Linux builds (not macOS, not Windows cross-compile) + // nv-codec-headers are header-only - no runtime dependency at build time + if (process.platform !== "linux" || isWindows) return; + + if (!existsSync("nv-codec-headers")) { + execSync( + "git clone https://github.com/FFmpeg/nv-codec-headers.git", + {stdio: "inherit"}, + ); + } + + execSync("git fetch --all --tags", { + cwd: "nv-codec-headers", + stdio: "inherit", + }); + + execSync(`git checkout ${NV_CODEC_HEADERS_TAG}`, { + cwd: "nv-codec-headers", + stdio: "inherit", + }); + + execSync(`make install PREFIX=${PREFIX}`, { + cwd: "nv-codec-headers", + stdio: "inherit", + }); +};