whisper-cpp: add FFmpeg support

as detailed at https://github.com/ggml-org/whisper.cpp#ffmpeg-support-linux-only

note: for whisper-server to work, it must be started with `--convert` (even for natively support formats, such as wav)
This commit is contained in:
Gaël James
2025-11-26 14:49:07 +01:00
parent cc93939497
commit 807b6e921f
+12
View File
@@ -8,6 +8,7 @@
SDL2,
wget,
which,
ffmpeg,
autoAddDriverRunpath,
makeWrapper,
nix-update-script,
@@ -29,10 +30,13 @@
vulkan-loader,
withSDL ? true,
withFFmpegSupport ? false,
}:
assert metalSupport -> stdenv.hostPlatform.isDarwin;
assert coreMLSupport -> stdenv.hostPlatform.isDarwin;
assert withFFmpegSupport -> stdenv.hostPlatform.isLinux;
let
# It's necessary to consistently use backendStdenv when building with CUDA support,
@@ -108,6 +112,7 @@ effectiveStdenv.mkDerivation (finalAttrs: {
buildInputs =
optional withSDL SDL2
++ optional withFFmpegSupport ffmpeg
++ optionals cudaSupport cudaBuildInputs
++ optionals rocmSupport rocmBuildInputs
++ optionals vulkanSupport vulkanBuildInputs;
@@ -122,6 +127,9 @@ effectiveStdenv.mkDerivation (finalAttrs: {
(cmakeBool "GGML_NATIVE" false)
(cmakeBool "BUILD_SHARED_LIBS" (!effectiveStdenv.hostPlatform.isStatic))
]
++ optionals effectiveStdenv.hostPlatform.isLinux [
(cmakeBool "WHISPER_FFMPEG" withFFmpegSupport)
]
++ optionals (effectiveStdenv.hostPlatform.isx86 && !effectiveStdenv.hostPlatform.isStatic) [
(cmakeBool "GGML_BACKEND_DL" true)
(cmakeBool "GGML_CPU_ALL_VARIANTS" true)
@@ -156,6 +164,10 @@ effectiveStdenv.mkDerivation (finalAttrs: {
wrapProgram "$out/bin/whisper-cpp-download-ggml-model" \
--prefix PATH : ${lib.makeBinPath [ wget ]}
''
+ lib.optionalString withFFmpegSupport ''
wrapProgram "$out/bin/whisper-server" \
--prefix PATH : ${lib.makeBinPath [ ffmpeg ]}
'';
requiredSystemFeatures = optionals rocmSupport [ "big-parallel" ]; # rocmSupport multiplies build time by the number of GPU targets, which takes arround 30 minutes on a 16-cores system to build