1 { lib, config, stdenv, buildPackages, removeReferencesTo, addDriverRunpath, pkg-config, perl, texinfo, texinfo6, yasm
3 # You can fetch any upstream version using this derivation by specifying version and hash
4 # NOTICE: Always use this argument to override the version. Do not use overrideAttrs.
5 , version # ffmpeg ABI version. Also declare this if you're overriding the source.
6 , hash ? "" # hash of the upstream source for the given ABI version
8 url = "https://git.ffmpeg.org/ffmpeg.git";
13 , ffmpegVariant ? "small" # Decides which dependencies are enabled by default
15 # Build with headless deps; excludes dependencies that are only necessary for
16 # GUI applications. To be used for purposes that don't generally need such
17 # components and i.e. only depend on libav
18 , withHeadlessDeps ? ffmpegVariant == "headless" || withSmallDeps
20 # Dependencies a user might customarily expect from a regular ffmpeg build.
21 # /All/ packages that depend on ffmpeg and some of its feaures should depend
22 # on the small variant. Small means the minimal set of features that satisfies
23 # all dependants in Nixpkgs
24 , withSmallDeps ? ffmpegVariant == "small" || withFullDeps
26 # Everything enabled; only guarded behind platform exclusivity or brokeness.
27 # If you need to depend on ffmpeg-full because ffmpeg is missing some feature
28 # your package needs, you should enable that feature in regular ffmpeg
30 , withFullDeps ? ffmpegVariant == "full"
36 , withAlsa ? withHeadlessDeps && stdenv.hostPlatform.isLinux # Alsa in/output supporT
37 , withAmf ? withHeadlessDeps && lib.meta.availableOn stdenv.hostPlatform amf # AMD Media Framework video encoding
38 , withAom ? withHeadlessDeps # AV1 reference encoder
39 , withAribb24 ? withFullDeps # ARIB text and caption decoding
40 , withAribcaption ? withFullDeps && lib.versionAtLeast version "6.1" # ARIB STD-B24 Caption Decoder/Renderer
41 , withAss ? withHeadlessDeps && stdenv.hostPlatform == stdenv.buildPlatform # (Advanced) SubStation Alpha subtitle rendering
42 , withAvisynth ? withFullDeps # AviSynth script files reading
43 , withBluray ? withHeadlessDeps # BluRay reading
44 , withBs2b ? withFullDeps # bs2b DSP library
45 , withBzlib ? withHeadlessDeps
46 , withCaca ? withFullDeps # Textual display (ASCII art)
47 , withCdio ? withFullDeps && withGPL # Audio CD grabbing
48 , withCelt ? withHeadlessDeps # CELT decoder
49 , withChromaprint ? withFullDeps # Audio fingerprinting
50 , withCodec2 ? withFullDeps # codec2 en/decoding
51 , withCuda ? withFullDeps && withNvcodec
52 , withCudaLLVM ? withHeadlessDeps
53 , withCudaNVCC ? withFullDeps && withUnfree && config.cudaSupport
54 , withCuvid ? withHeadlessDeps && withNvcodec
55 , withDav1d ? withHeadlessDeps # AV1 decoder (focused on speed and correctness)
56 , withDc1394 ? withFullDeps && !stdenv.hostPlatform.isDarwin # IIDC-1394 grabbing (ieee 1394)
57 , withDrm ? withHeadlessDeps && (with stdenv; isLinux || isFreeBSD) # libdrm support
58 , withDvdnav ? withFullDeps && withGPL && lib.versionAtLeast version "7" # needed for DVD demuxing
59 , withDvdread ? withFullDeps && withGPL && lib.versionAtLeast version "7" # needed for DVD demuxing
60 , withFdkAac ? withFullDeps && (!withGPL || withUnfree) # Fraunhofer FDK AAC de/encoder
61 , withNvcodec ? withHeadlessDeps && (with stdenv; !isDarwin && !isAarch32 && !hostPlatform.isRiscV && hostPlatform == buildPlatform) # dynamically linked Nvidia code
62 , withFlite ? withFullDeps # Voice Synthesis
63 , withFontconfig ? withHeadlessDeps # Needed for drawtext filter
64 , withFreetype ? withHeadlessDeps # Needed for drawtext filter
65 , withFrei0r ? withFullDeps && withGPL # frei0r video filtering
66 , withFribidi ? withHeadlessDeps # Needed for drawtext filter
67 , withGme ? withFullDeps # Game Music Emulator
68 , withGnutls ? withHeadlessDeps
69 , withGsm ? withFullDeps # GSM de/encoder
70 , withHarfbuzz ? withHeadlessDeps && lib.versionAtLeast version "6.1" # Needed for drawtext filter
71 , withIconv ? withHeadlessDeps
72 , withIlbc ? withFullDeps # iLBC de/encoding
73 , withJack ? withFullDeps && !stdenv.hostPlatform.isDarwin # Jack audio
74 , withJxl ? withFullDeps && lib.versionAtLeast version "5" # JPEG XL de/encoding
75 , withKvazaar ? withFullDeps # HEVC encoding
76 , withLadspa ? withFullDeps # LADSPA audio filtering
77 , withLc3 ? withFullDeps && lib.versionAtLeast version "7.1" # LC3 de/encoding
78 , withLcevcdec ? false && lib.versionAtLeast version "7.1" # LCEVC decoding # FIXME currently makes ffmpeg crash in any operation on non-AVX CPUs
79 , withLcms2 ? withFullDeps # ICC profile support via lcms2
80 , withLzma ? withHeadlessDeps # xz-utils
81 , withMetal ? false # Unfree and requires manual downloading of files
82 , withMfx ? withFullDeps && (with stdenv.hostPlatform; isLinux && !isAarch) # Hardware acceleration via intel-media-sdk/libmfx
83 , withModplug ? withFullDeps && !stdenv.hostPlatform.isDarwin # ModPlug support
84 , withMp3lame ? withHeadlessDeps # LAME MP3 encoder
85 , withMysofa ? withFullDeps # HRTF support via SOFAlizer
86 , withNpp ? withFullDeps && withUnfree && config.cudaSupport # Nvidia Performance Primitives-based code
87 , withNvdec ? withHeadlessDeps && withNvcodec
88 , withNvenc ? withHeadlessDeps && withNvcodec
89 , withOpenal ? withFullDeps # OpenAL 1.1 capture support
90 , withOpencl ? withHeadlessDeps
91 , withOpencoreAmrnb ? withFullDeps && withVersion3 # AMR-NB de/encoder
92 , withOpencoreAmrwb ? withFullDeps && withVersion3 # AMR-WB decoder
93 , withOpengl ? withFullDeps && !stdenv.hostPlatform.isDarwin # OpenGL rendering
94 , withOpenh264 ? withFullDeps # H.264/AVC encoder
95 , withOpenjpeg ? withHeadlessDeps # JPEG 2000 de/encoder
96 , withOpenmpt ? withHeadlessDeps # Tracked music files decoder
97 , withOpus ? withHeadlessDeps # Opus de/encoder
98 , withPlacebo ? withFullDeps && !stdenv.hostPlatform.isDarwin # libplacebo video processing library
99 , withPulse ? withSmallDeps && stdenv.hostPlatform.isLinux # Pulseaudio input support
100 , withQrencode ? withFullDeps && lib.versionAtLeast version "7" # QR encode generation
101 , withQuirc ? withFullDeps && lib.versionAtLeast version "7" # QR decoding
102 , withRav1e ? withFullDeps # AV1 encoder (focused on speed and safety)
103 , withRist ? withHeadlessDeps # Reliable Internet Stream Transport (RIST) protocol
104 , withRtmp ? withFullDeps # RTMP[E] support
105 , withRubberband ? withFullDeps && withGPL # Rubberband filter
106 , withSamba ? withFullDeps && !stdenv.hostPlatform.isDarwin && withGPLv3 # Samba protocol
107 , withSdl2 ? withSmallDeps
108 , withShaderc ? withFullDeps && !stdenv.hostPlatform.isDarwin && lib.versionAtLeast version "5.0"
109 , withShine ? withFullDeps # Fixed-point MP3 encoding
110 , withSnappy ? withFullDeps # Snappy compression, needed for hap encoding
111 , withSoxr ? withHeadlessDeps # Resampling via soxr
112 , withSpeex ? withHeadlessDeps # Speex de/encoder
113 , withSrt ? withHeadlessDeps # Secure Reliable Transport (SRT) protocol
114 , withSsh ? withHeadlessDeps # SFTP protocol
115 , withSvg ? withFullDeps # SVG protocol
116 , withSvtav1 ? withHeadlessDeps && !stdenv.hostPlatform.isAarch64 && !stdenv.hostPlatform.isMinGW # AV1 encoder/decoder (focused on speed and correctness)
117 , withTensorflow ? false # Tensorflow dnn backend support (Increases closure size by ~390 MiB)
118 , withTheora ? withHeadlessDeps # Theora encoder
119 , withTwolame ? withFullDeps # MP2 encoding
120 , withV4l2 ? withHeadlessDeps && stdenv.hostPlatform.isLinux # Video 4 Linux support
121 , withV4l2M2m ? withV4l2
122 , withVaapi ? withHeadlessDeps && (with stdenv; isLinux || isFreeBSD) # Vaapi hardware acceleration
123 , withVdpau ? withSmallDeps && !stdenv.hostPlatform.isMinGW # Vdpau hardware acceleration
124 , withVidStab ? withHeadlessDeps && withGPL # Video stabilization
125 , withVmaf ? withFullDeps && !stdenv.hostPlatform.isAarch64 && lib.versionAtLeast version "5" # Netflix's VMAF (Video Multi-Method Assessment Fusion)
126 , withVoAmrwbenc ? withFullDeps && withVersion3 # AMR-WB encoder
127 , withVorbis ? withHeadlessDeps # Vorbis de/encoding, native encoder exists
128 , withVpl ? false # Hardware acceleration via intel libvpl
129 , withVpx ? withHeadlessDeps && stdenv.buildPlatform == stdenv.hostPlatform # VP8 & VP9 de/encoding
130 , withVulkan ? withHeadlessDeps && !stdenv.hostPlatform.isDarwin
131 , withVvenc ? withFullDeps && lib.versionAtLeast version "7.1" # H.266/VVC encoding
132 , withWebp ? withHeadlessDeps # WebP encoder
133 , withX264 ? withHeadlessDeps && withGPL # H.264/AVC encoder
134 , withX265 ? withHeadlessDeps && withGPL # H.265/HEVC encoder
135 , withXavs ? withFullDeps && withGPL # AVS encoder
136 , withXcb ? withXcbShm || withXcbxfixes || withXcbShape # X11 grabbing using XCB
137 , withXcbShape ? withFullDeps # X11 grabbing shape rendering
138 , withXcbShm ? withFullDeps # X11 grabbing shm communication
139 , withXcbxfixes ? withFullDeps # X11 grabbing mouse rendering
140 , withXevd ? withFullDeps && lib.versionAtLeast version "7.1" && !xevd.meta.broken # MPEG-5 EVC decoding
141 , withXeve ? withFullDeps && lib.versionAtLeast version "7.1" && !xeve.meta.broken # MPEG-5 EVC encoding
142 , withXlib ? withFullDeps # Xlib support
143 , withXml2 ? withHeadlessDeps # libxml2 support, for IMF and DASH demuxers
144 , withXvid ? withHeadlessDeps && withGPL # Xvid encoder, native encoder exists
145 , withZimg ? withHeadlessDeps
146 , withZlib ? withHeadlessDeps
147 , withZmq ? withFullDeps # Message passing
148 , withZvbi ? withHeadlessDeps # Teletext support
151 * Licensing options (yes some are listed twice, filters and such are not listed)
154 , withVersion3 ? true # When withGPL is set this implies GPLv3 otherwise it is LGPLv3
155 , withGPLv3 ? withGPL && withVersion3
161 , withSmallBuild ? false # Optimize for size instead of speed
162 , withRuntimeCPUDetection ? true # Detect CPU capabilities at runtime (disable to compile natively)
163 , withGrayscale ? withFullDeps # Full grayscale support
164 , withSwscaleAlpha ? buildSwscale # Alpha channel support in swscale. You probably want this when buildSwscale.
165 , withHardcodedTables ? withHeadlessDeps # Hardcode decode tables instead of runtime generation
166 , withSafeBitstreamReader ? withHeadlessDeps # Buffer boundary checking in bitreaders
167 , withMultithread ? true # Multithreading via pthreads/win32 threads
168 , withNetwork ? withHeadlessDeps # Network support
169 , withPixelutils ? withHeadlessDeps # Pixel utils in libavutil
170 , withStatic ? stdenv.hostPlatform.isStatic
171 , withShared ? !stdenv.hostPlatform.isStatic
173 , withThumb ? false # On some ARM platforms
178 , buildFfmpeg ? withHeadlessDeps # Build ffmpeg executable
179 , buildFfplay ? withSmallDeps # Build ffplay executable
180 , buildFfprobe ? withHeadlessDeps # Build ffprobe executable
181 , buildQtFaststart ? withFullDeps # Build qt-faststart executable
182 , withBin ? buildFfmpeg || buildFfplay || buildFfprobe || buildQtFaststart
186 , buildAvcodec ? withHeadlessDeps # Build avcodec library
187 , buildAvdevice ? withHeadlessDeps # Build avdevice library
188 , buildAvfilter ? withHeadlessDeps # Build avfilter library
189 , buildAvformat ? withHeadlessDeps # Build avformat library
190 # Deprecated but depended upon by some packages.
191 # https://github.com/NixOS/nixpkgs/pull/211834#issuecomment-1417435991)
192 , buildAvresample ? withHeadlessDeps && lib.versionOlder version "5" # Build avresample library
193 , buildAvutil ? withHeadlessDeps # Build avutil library
194 , buildPostproc ? withHeadlessDeps # Build postproc library
195 , buildSwresample ? withHeadlessDeps # Build swresample library
196 , buildSwscale ? withHeadlessDeps # Build swscale library
197 , withLib ? buildAvcodec
206 * Documentation options
208 , withDocumentation ? withHtmlDoc || withManPages || withPodDoc || withTxtDoc
209 , withHtmlDoc ? withHeadlessDeps # HTML documentation pages
210 , withManPages ? withHeadlessDeps # Man documentation pages
211 , withPodDoc ? withHeadlessDeps # POD documentation pages
212 , withTxtDoc ? withHeadlessDeps # Text documentation pages
213 # Whether a "doc" output will be produced. Note that withManPages does not produce
214 # a "doc" output because its files go to "man".
215 , withDoc ? withDocumentation && (withHtmlDoc || withPodDoc || withTxtDoc)
221 , withOptimisations ? true
222 , withExtraWarnings ? false
223 , withStripping ? false
226 * External libraries options
302 , nv-codec-headers-12
303 , ocl-icd # OpenCL ICD
305 , opencl-headers # OpenCL headers
344 , xcode # unfree contains metalcc and metallib
360 * It should always be safe to bump patch releases (e.g. 2.1.x, x being a patch release)
361 * If adding a new branch, note any configure flags that were added, changed, or deprecated/removed
362 * and make the necessary changes.
365 * Cross-compiling will disable features not present on host OS
366 * (e.g. dxva2 support [DirectX] will not be enabled unless natively compiled on Cygwin)
371 inherit (lib) optional optionals optionalString enableFeature versionOlder versionAtLeast;
375 assert lib.elem ffmpegVariant [ "headless" "small" "full" ];
378 * Licensing dependencies
380 assert withGPLv3 -> withGPL && withVersion3;
385 assert withPixelutils -> buildAvutil;
386 assert !(withMfx && withVpl); # incompatible features
388 * Program dependencies
390 assert buildFfmpeg -> buildAvcodec
393 && (buildSwresample || buildAvresample);
394 assert buildFfplay -> buildAvcodec
397 && (buildSwresample || buildAvresample);
398 assert buildFfprobe -> buildAvcodec && buildAvformat;
400 * Library dependencies
402 assert buildAvcodec -> buildAvutil; # configure flag since 0.6
403 assert buildAvdevice -> buildAvformat
405 && buildAvutil; # configure flag since 0.6
406 assert buildAvformat -> buildAvcodec && buildAvutil; # configure flag since 0.6
407 assert buildPostproc -> buildAvutil;
408 assert buildSwscale -> buildAvutil;
411 * External Library dependencies
413 assert (withCuda || withCuvid || withNvdec || withNvenc) -> withNvcodec;
415 stdenv.mkDerivation (finalAttrs: {
416 pname = "ffmpeg" + (optionalString (ffmpegVariant != "small") "-${ffmpegVariant}");
422 '' + lib.optionalString withFrei0r ''
423 substituteInPlace libavfilter/vf_frei0r.c \
424 --replace /usr/local/lib/frei0r-1 ${frei0r}/lib/frei0r-1
425 substituteInPlace doc/filters.texi \
426 --replace /usr/local/lib/frei0r-1 ${frei0r}/lib/frei0r-1
430 ++ optionals (lib.versionAtLeast version "6.1" && lib.versionOlder version "6.2") [
431 (fetchpatch2 { # this can be removed post 6.1
432 name = "fix_build_failure_due_to_PropertyKey_EncoderID";
433 url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/cb049d377f54f6b747667a93e4b719380c3e9475";
434 hash = "sha256-sxRXKKgUak5vsQTiV7ge8vp+N22CdTIvuczNgVRP72c=";
437 name = "CVE-2024-31582.patch";
438 url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/99debe5f823f45a482e1dc08de35879aa9c74bd2";
439 hash = "sha256-+CQ9FXR6Vr/AmsbXFiCUXZcxKj1s8nInEdke/Oc/kUA=";
442 name = "CVE-2024-31578.patch";
443 url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/3bb00c0a420c3ce83c6fafee30270d69622ccad7";
444 hash = "sha256-oZMZysBA+/gwaGEM1yvI+8wCadXWE7qLRL6Emap3b8Q=";
447 name = "CVE-2023-49501.patch";
448 url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/4adb93dff05dd947878c67784d98c9a4e13b57a7";
449 hash = "sha256-7cwktto3fPMDGvCZCVtB01X8Q9S/4V4bDLUICSNfGgw=";
452 name = "CVE-2023-49502.patch";
453 url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/737ede405b11a37fdd61d19cf25df296a0cb0b75";
454 hash = "sha256-mpSJwR9TX5ENjjCKvzuM/9e1Aj/AOiQW0+72oOMl9v8=";
457 name = "CVE-2023-50007.patch";
458 url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/b1942734c7cbcdc9034034373abcc9ecb9644c47";
459 hash = "sha256-v0hNcqBtm8GCGAU9UbRUCE0slodOjZCHrkS8e4TrVcQ=";
462 name = "CVE-2023-50008.patch";
463 url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/5f87a68cf70dafeab2fb89b42e41a4c29053b89b";
464 hash = "sha256-sqUUSOPTPLwu2h8GbAw4SfEf+0oWioz52BcpW1n4v3Y=";
467 ++ optionals (lib.versionAtLeast version "7.1") [
468 ./fix-fate-ffmpeg-spec-disposition-7.1.patch
470 # Expose a private API for Chromium / Qt WebEngine.
472 url = "https://gitlab.archlinux.org/archlinux/packaging/packages/ffmpeg/-/raw/a02c1a15706ea832c0d52a4d66be8fb29499801a/add-av_stream_get_first_dts-for-chromium.patch";
473 hash = "sha256-DbH6ieJwDwTjKOdQ04xvRcSLeeLP2Z2qEmqeo8HsPr4=";
477 configurePlatforms = [];
478 setOutputFlags = false; # Only accepts some of them
480 #mingw64 is internally treated as mingw32, so 32 and 64 make no difference here
481 "--target_os=${if stdenv.hostPlatform.isMinGW then "mingw64" else stdenv.hostPlatform.parsed.kernel.name}"
482 "--arch=${stdenv.hostPlatform.parsed.cpu.name}"
483 "--pkg-config=${buildPackages.pkg-config.targetPrefix}pkg-config"
487 (enableFeature withGPL "gpl")
488 (enableFeature withVersion3 "version3")
489 (enableFeature withUnfree "nonfree")
493 (enableFeature withStatic "static")
494 (enableFeature withShared "shared")
495 (enableFeature withPic "pic")
496 (enableFeature withThumb "thumb")
498 (enableFeature withSmallBuild "small")
499 (enableFeature withRuntimeCPUDetection "runtime-cpudetect")
500 (enableFeature withGrayscale "gray")
501 (enableFeature withSwscaleAlpha "swscale-alpha")
502 (enableFeature withHardcodedTables "hardcoded-tables")
503 (enableFeature withSafeBitstreamReader "safe-bitstream-reader")
505 (enableFeature (withMultithread && stdenv.hostPlatform.isUnix) "pthreads")
506 (enableFeature (withMultithread && stdenv.hostPlatform.isWindows) "w32threads")
507 "--disable-os2threads" # We don't support OS/2
509 (enableFeature withNetwork "network")
510 (enableFeature withPixelutils "pixelutils")
512 "--datadir=${placeholder "data"}/share/ffmpeg"
517 (enableFeature buildFfmpeg "ffmpeg")
518 (enableFeature buildFfplay "ffplay")
519 (enableFeature buildFfprobe "ffprobe")
520 ] ++ optionals withBin [
521 "--bindir=${placeholder "bin"}/bin"
526 (enableFeature buildAvcodec "avcodec")
527 (enableFeature buildAvdevice "avdevice")
528 (enableFeature buildAvfilter "avfilter")
529 (enableFeature buildAvformat "avformat")
530 ] ++ optionals (lib.versionOlder version "5") [
531 # Ffmpeg > 4 doesn't know about the flag anymore
532 (enableFeature buildAvresample "avresample")
534 (enableFeature buildAvutil "avutil")
535 (enableFeature (buildPostproc && withGPL) "postproc")
536 (enableFeature buildSwresample "swresample")
537 (enableFeature buildSwscale "swscale")
538 ] ++ optionals withLib [
539 "--libdir=${placeholder "lib"}/lib"
540 "--incdir=${placeholder "dev"}/include"
543 * Documentation flags
545 (enableFeature withDocumentation "doc")
546 (enableFeature withHtmlDoc "htmlpages")
547 (enableFeature withManPages "manpages")
548 ] ++ optionals withManPages [
549 "--mandir=${placeholder "man"}/share/man"
551 (enableFeature withPodDoc "podpages")
552 (enableFeature withTxtDoc "txtpages")
553 ] ++ optionals withDoc [
554 "--docdir=${placeholder "doc"}/share/doc/ffmpeg"
559 (enableFeature withAlsa "alsa")
560 (enableFeature withAmf "amf")
561 (enableFeature withAom "libaom")
562 (enableFeature withAribb24 "libaribb24")
563 ] ++ optionals (versionAtLeast version "6.1") [
564 (enableFeature withAribcaption "libaribcaption")
566 (enableFeature withAss "libass")
567 (enableFeature withAvisynth "avisynth")
568 (enableFeature withBluray "libbluray")
569 (enableFeature withBs2b "libbs2b")
570 (enableFeature withBzlib "bzlib")
571 (enableFeature withCaca "libcaca")
572 (enableFeature withCdio "libcdio")
573 (enableFeature withCelt "libcelt")
574 (enableFeature withChromaprint "chromaprint")
575 (enableFeature withCodec2 "libcodec2")
576 (enableFeature withCuda "cuda")
577 (enableFeature withCudaLLVM "cuda-llvm")
578 (enableFeature withCudaNVCC "cuda-nvcc")
579 (enableFeature withCuvid "cuvid")
580 (enableFeature withDav1d "libdav1d")
581 (enableFeature withDc1394 "libdc1394")
582 (enableFeature withDrm "libdrm")
583 ] ++ optionals (versionAtLeast version "7") [
584 (enableFeature withDvdnav "libdvdnav")
585 (enableFeature withDvdread "libdvdread")
587 (enableFeature withFdkAac "libfdk-aac")
588 (enableFeature withNvcodec "ffnvcodec")
589 (enableFeature withFlite "libflite")
590 (enableFeature withFontconfig "fontconfig")
591 (enableFeature withFontconfig "libfontconfig")
592 (enableFeature withFreetype "libfreetype")
593 (enableFeature withFrei0r "frei0r")
594 (enableFeature withFribidi "libfribidi")
595 (enableFeature withGme "libgme")
596 (enableFeature withGnutls "gnutls")
597 (enableFeature withGsm "libgsm")
598 ] ++ optionals (versionAtLeast version "6.1") [
599 (enableFeature withHarfbuzz "libharfbuzz")
601 (enableFeature withIconv "iconv")
602 (enableFeature withIlbc "libilbc")
603 (enableFeature withJack "libjack")
604 ] ++ optionals (versionAtLeast finalAttrs.version "5.0") [
605 (enableFeature withJxl "libjxl")
607 (enableFeature withKvazaar "libkvazaar")
608 (enableFeature withLadspa "ladspa")
609 ] ++ optionals (versionAtLeast version "7.1") [
610 (enableFeature withLc3 "liblc3")
611 (enableFeature withLcevcdec "liblcevc-dec")
612 ] ++ optionals (versionAtLeast version "5.1") [
613 (enableFeature withLcms2 "lcms2")
615 (enableFeature withLzma "lzma")
616 ] ++ optionals (versionAtLeast version "5.0") [
617 (enableFeature withMetal "metal")
619 (enableFeature withMfx "libmfx")
620 (enableFeature withModplug "libmodplug")
621 (enableFeature withMp3lame "libmp3lame")
622 (enableFeature withMysofa "libmysofa")
623 (enableFeature withNpp "libnpp")
624 (enableFeature withNvdec "nvdec")
625 (enableFeature withNvenc "nvenc")
626 (enableFeature withOpenal "openal")
627 (enableFeature withOpencl "opencl")
628 (enableFeature withOpencoreAmrnb "libopencore-amrnb")
629 (enableFeature withOpencoreAmrwb "libopencore-amrwb")
630 (enableFeature withOpengl "opengl")
631 (enableFeature withOpenh264 "libopenh264")
632 (enableFeature withOpenjpeg "libopenjpeg")
633 (enableFeature withOpenmpt "libopenmpt")
634 (enableFeature withOpus "libopus")
635 ] ++ optionals (versionAtLeast version "5.0") [
636 (enableFeature withPlacebo "libplacebo")
638 (enableFeature withPulse "libpulse")
639 ] ++ optionals (versionAtLeast version "7") [
640 (enableFeature withQrencode "libqrencode")
641 (enableFeature withQuirc "libquirc")
643 (enableFeature withRav1e "librav1e")
644 (enableFeature withRist "librist")
645 (enableFeature withRtmp "librtmp")
646 (enableFeature withRubberband "librubberband")
647 (enableFeature withSamba "libsmbclient")
648 (enableFeature withSdl2 "sdl2")
649 ] ++ optionals (versionAtLeast version "5.0") [
650 (enableFeature withShaderc "libshaderc")
652 (enableFeature withShine "libshine")
653 (enableFeature withSnappy "libsnappy")
654 (enableFeature withSoxr "libsoxr")
655 (enableFeature withSpeex "libspeex")
656 (enableFeature withSrt "libsrt")
657 (enableFeature withSsh "libssh")
658 (enableFeature withSvg "librsvg")
659 (enableFeature withSvtav1 "libsvtav1")
660 (enableFeature withTensorflow "libtensorflow")
661 (enableFeature withTheora "libtheora")
662 (enableFeature withTwolame "libtwolame")
663 (enableFeature withV4l2 "libv4l2")
664 (enableFeature withV4l2M2m "v4l2-m2m")
665 (enableFeature withVaapi "vaapi")
666 (enableFeature withVdpau "vdpau")
667 ] ++ optionals (versionAtLeast version "6.0") [
668 (enableFeature withVpl "libvpl")
670 (enableFeature withVidStab "libvidstab") # Actual min. version 2.0
671 (enableFeature withVmaf "libvmaf")
672 (enableFeature withVoAmrwbenc "libvo-amrwbenc")
673 (enableFeature withVorbis "libvorbis")
674 (enableFeature withVpx "libvpx")
675 (enableFeature withVulkan "vulkan")
676 ] ++ optionals (versionAtLeast version "7.1") [
677 (enableFeature withVvenc "libvvenc")
679 (enableFeature withWebp "libwebp")
680 (enableFeature withX264 "libx264")
681 (enableFeature withX265 "libx265")
682 (enableFeature withXavs "libxavs")
683 (enableFeature withXcb "libxcb")
684 (enableFeature withXcbShape "libxcb-shape")
685 (enableFeature withXcbShm "libxcb-shm")
686 (enableFeature withXcbxfixes "libxcb-xfixes")
687 ] ++ optionals (versionAtLeast version "7") [
688 (enableFeature withXevd "libxevd")
689 (enableFeature withXeve "libxeve")
691 (enableFeature withXlib "xlib")
692 (enableFeature withXml2 "libxml2")
693 (enableFeature withXvid "libxvid")
694 (enableFeature withZimg "libzimg")
695 (enableFeature withZlib "zlib")
696 (enableFeature withZmq "libzmq")
697 (enableFeature withZvbi "libzvbi")
701 (enableFeature withDebug "debug")
702 (enableFeature withOptimisations "optimizations")
703 (enableFeature withExtraWarnings "extra-warnings")
704 (enableFeature withStripping "stripping")
705 ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
706 "--cross-prefix=${stdenv.cc.targetPrefix}"
707 "--enable-cross-compile"
708 "--host-cc=${buildPackages.stdenv.cc}/bin/cc"
709 ] ++ optionals stdenv.cc.isClang [
712 ] ++ optionals withMetal [
713 "--metalcc=${xcode}/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/metal"
714 "--metallib=${xcode}/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/metallib"
717 # ffmpeg embeds the configureFlags verbatim in its binaries and because we
718 # configure binary, include, library dir etc., this causes references in
719 # outputs where we don't want them. Patch the generated config.h to remove all
720 # such references except for data.
722 toStrip = map placeholder (lib.remove "data" finalAttrs.outputs) # We want to keep references to the data dir.
723 ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) buildPackages.stdenv.cc
724 ++ lib.optional withMetal xcode;
726 "remove-references-to ${lib.concatStringsSep " " (map (o: "-t ${o}") toStrip)} config.h";
730 nativeBuildInputs = [ removeReferencesTo addDriverRunpath perl pkg-config yasm ]
731 # Texinfo version 7.1 introduced breaking changes, which older versions of ffmpeg do not handle.
732 ++ (if versionOlder version "5" then [ texinfo6 ] else [ texinfo ])
733 ++ optionals withCudaLLVM [ clang ]
734 ++ optionals withCudaNVCC [ cuda_nvcc ];
737 ++ optionals stdenv.hostPlatform.isDarwin [ apple-sdk_15 ]
738 ++ optionals withAlsa [ alsa-lib ]
739 ++ optionals withAmf [ amf-headers ]
740 ++ optionals withAom [ libaom ]
741 ++ optionals withAribb24 [ aribb24 ]
742 ++ optionals withAribcaption [ libaribcaption ]
743 ++ optionals withAss [ libass ]
744 ++ optionals withAvisynth [ avisynthplus ]
745 ++ optionals withBluray [ libbluray ]
746 ++ optionals withBs2b [ libbs2b ]
747 ++ optionals withBzlib [ bzip2 ]
748 ++ optionals withCaca [ libcaca ]
749 ++ optionals withCdio [ libcdio libcdio-paranoia ]
750 ++ optionals withCelt [ celt ]
751 ++ optionals withChromaprint [ chromaprint ]
752 ++ optionals withCodec2 [ codec2 ]
753 ++ optionals withCudaNVCC [ cuda_cudart cuda_nvcc ]
754 ++ optionals withDav1d [ dav1d ]
755 ++ optionals withDc1394 [ libdc1394 libraw1394 ]
756 ++ optionals withDrm [ libdrm ]
757 ++ optionals withDvdnav [ libdvdnav ]
758 ++ optionals withDvdread [ libdvdread ]
759 ++ optionals withFdkAac [ fdk_aac ]
760 ++ optionals withNvcodec [ (if (lib.versionAtLeast version "6") then nv-codec-headers-12 else nv-codec-headers) ]
761 ++ optionals withFlite [ flite ]
762 ++ optionals withFontconfig [ fontconfig ]
763 ++ optionals withFreetype [ freetype ]
764 ++ optionals withFrei0r [ frei0r ]
765 ++ optionals withFribidi [ fribidi ]
766 ++ optionals withGme [ game-music-emu ]
767 ++ optionals withGnutls [ gnutls ]
768 ++ optionals withGsm [ gsm ]
769 ++ optionals withHarfbuzz [ harfbuzz ]
770 ++ optionals withIconv [ libiconv ] # On Linux this should be in libc, do we really need it?
771 ++ optionals withIlbc [ libilbc ]
772 ++ optionals withJack [ libjack2 ]
773 ++ optionals withJxl [ libjxl ]
774 ++ optionals withKvazaar [ kvazaar ]
775 ++ optionals withLadspa [ ladspaH ]
776 ++ optionals withLc3 [ liblc3 ]
777 ++ optionals withLcevcdec [ lcevcdec ]
778 ++ optionals withLcms2 [ lcms2 ]
779 ++ optionals withLzma [ xz ]
780 ++ optionals withMfx [ intel-media-sdk ]
781 ++ optionals withModplug [ libmodplug ]
782 ++ optionals withMp3lame [ lame ]
783 ++ optionals withMysofa [ libmysofa ]
784 ++ optionals withNpp [ libnpp cuda_cudart cuda_nvcc ]
785 ++ optionals withOpenal [ openal ]
786 ++ optionals withOpencl [ ocl-icd opencl-headers ]
787 ++ optionals (withOpencoreAmrnb || withOpencoreAmrwb) [ opencore-amr ]
788 ++ optionals withOpengl [ libGL libGLU ]
789 ++ optionals withOpenh264 [ openh264 ]
790 ++ optionals withOpenjpeg [ openjpeg ]
791 ++ optionals withOpenmpt [ libopenmpt ]
792 ++ optionals withOpus [ libopus ]
793 ++ optionals withPlacebo [ (if (lib.versionAtLeast version "6.1") then libplacebo else libplacebo_5) vulkan-headers ]
794 ++ optionals withPulse [ libpulseaudio ]
795 ++ optionals withQrencode [ qrencode ]
796 ++ optionals withQuirc [ quirc ]
797 ++ optionals withRav1e [ rav1e ]
798 ++ optionals withRist [ librist ]
799 ++ optionals withRtmp [ rtmpdump ]
800 ++ optionals withRubberband [ rubberband ]
801 ++ optionals withSamba [ samba ]
802 ++ optionals withSdl2 [ SDL2 ]
803 ++ optionals withShaderc [ shaderc ]
804 ++ optionals withShine [ shine ]
805 ++ optionals withSnappy [ snappy ]
806 ++ optionals withSoxr [ soxr ]
807 ++ optionals withSpeex [ speex ]
808 ++ optionals withSrt [ srt ]
809 ++ optionals withSsh [ libssh ]
810 ++ optionals withSvg [ librsvg ]
811 ++ optionals withSvtav1 [ svt-av1 ]
812 ++ optionals withTensorflow [ libtensorflow ]
813 ++ optionals withTheora [ libtheora ]
814 ++ optionals withTwolame [ twolame ]
815 ++ optionals withV4l2 [ libv4l ]
816 ++ optionals withVaapi [ (if withSmallDeps then libva else libva-minimal) ]
817 ++ optionals withVdpau [ libvdpau ]
818 ++ optionals withVidStab [ vid-stab ]
819 ++ optionals withVmaf [ libvmaf ]
820 ++ optionals withVoAmrwbenc [ vo-amrwbenc ]
821 ++ optionals withVorbis [ libvorbis ]
822 ++ optionals withVpl [ libvpl ]
823 ++ optionals withVpx [ libvpx ]
824 ++ optionals withVulkan [ vulkan-headers vulkan-loader ]
825 ++ optionals withVvenc [ vvenc ]
826 ++ optionals withWebp [ libwebp ]
827 ++ optionals withX264 [ x264 ]
828 ++ optionals withX265 [ x265 ]
829 ++ optionals withXavs [ xavs ]
830 ++ optionals withXcb [ libxcb ]
831 ++ optionals withXevd [ xevd ]
832 ++ optionals withXeve [ xeve ]
833 ++ optionals withXlib [ libX11 libXv libXext ]
834 ++ optionals withXml2 [ libxml2 ]
835 ++ optionals withXvid [ xvidcore ]
836 ++ optionals withZimg [ zimg ]
837 ++ optionals withZlib [ zlib ]
838 ++ optionals withZmq [ zeromq ]
839 ++ optionals withZvbi [ zvbi ]
842 buildFlags = [ "all" ]
843 ++ optional buildQtFaststart "tools/qt-faststart"; # Build qt-faststart executable
845 env = lib.optionalAttrs stdenv.cc.isGNU {
846 NIX_CFLAGS_COMPILE = toString [
847 "-Wno-error=incompatible-pointer-types"
848 "-Wno-error=int-conversion"
852 doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
854 # Fails with SIGABRT otherwise FIXME: Why?
856 ldLibraryPathEnv = if stdenv.hostPlatform.isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH";
858 ++ optional buildAvcodec "libavcodec"
859 ++ optional buildAvdevice "libavdevice"
860 ++ optional buildAvfilter "libavfilter"
861 ++ optional buildAvformat "libavformat"
862 ++ optional buildAvresample "libavresample"
863 ++ optional buildAvutil "libavutil"
864 ++ optional buildPostproc "libpostproc"
865 ++ optional buildSwresample "libswresample"
866 ++ optional buildSwscale "libswscale"
869 ${ldLibraryPathEnv}="${lib.concatStringsSep ":" libsToLink}" make check -j$NIX_BUILD_CORES
872 outputs = optionals withBin [ "bin" ] # The first output is the one that gets symlinked by default!
873 ++ optionals withLib [ "lib" "dev" ]
874 ++ optionals withDoc [ "doc" ]
875 ++ optionals withManPages [ "man" ]
876 ++ [ "data" "out" ] # We need an "out" output because we get an error otherwise. It's just an empty dir.
879 postInstall = optionalString buildQtFaststart ''
880 install -D tools/qt-faststart -t $bin/bin
883 # Set RUNPATH so that libnvcuvid and libcuda in /run/opengl-driver(-32)/lib can be found.
884 # See the explanation in addDriverRunpath.
885 postFixup = optionalString (stdenv.hostPlatform.isLinux && withLib) ''
886 addDriverRunpath ${placeholder "lib"}/lib/libavcodec.so
887 addDriverRunpath ${placeholder "lib"}/lib/libavutil.so
889 # https://trac.ffmpeg.org/ticket/10809
890 + optionalString (versionAtLeast version "5.0" && withVulkan && !stdenv.hostPlatform.isMinGW) ''
891 patchelf $lib/lib/libavcodec.so --add-needed libvulkan.so --add-rpath ${lib.makeLibraryPath [ vulkan-loader ]}
894 enableParallelBuilding = true;
896 passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
899 description = "Complete, cross-platform solution to record, convert and stream audio and video";
900 homepage = "https://www.ffmpeg.org/";
901 changelog = "https://github.com/FFmpeg/FFmpeg/blob/n${version}/Changelog";
903 FFmpeg is the leading multimedia framework, able to decode, encode, transcode,
904 mux, demux, stream, filter and play pretty much anything that humans and machines
905 have created. It supports the most obscure ancient formats up to the cutting edge.
906 No matter if they were designed by some standards committee, the community or
909 license = with licenses; [ lgpl21Plus ]
910 ++ optional withGPL gpl2Plus
911 ++ optional withVersion3 lgpl3Plus
912 ++ optional withGPLv3 gpl3Plus
913 ++ optional withUnfree unfreeRedistributable
914 ++ optional (withGPL && withUnfree) unfree;
915 pkgConfigModules = [ ]
916 ++ optional buildAvcodec "libavcodec"
917 ++ optional buildAvdevice "libavdevice"
918 ++ optional buildAvfilter "libavfilter"
919 ++ optional buildAvformat "libavformat"
920 ++ optional buildAvresample "libavresample"
921 ++ optional buildAvutil "libavutil"
922 ++ optional buildPostproc "libpostproc"
923 ++ optional buildSwresample "libswresample"
924 ++ optional buildSwscale "libswscale";
925 platforms = platforms.all;
926 # See https://github.com/NixOS/nixpkgs/pull/295344#issuecomment-1992263658
927 broken = stdenv.hostPlatform.isMinGW && stdenv.hostPlatform.is64bit;
928 maintainers = with maintainers; [ atemu jopejoe1 emily ];
929 mainProgram = "ffmpeg";
931 } // lib.optionalAttrs withCudaLLVM {
932 # remove once https://github.com/NixOS/nixpkgs/issues/318674 is addressed properly
933 hardeningDisable = [ "zerocallusedregs" ];