1{ version, sha256, extraPatches ? [], knownVulnerabilities ? [] }:
2
3{ lib, stdenv, buildPackages, removeReferencesTo, addOpenGLRunpath, pkg-config, perl, texinfo, yasm
4
5, ffmpegVariant ? "small" # Decides which dependencies are enabled by default
6
7 # Build with headless deps; excludes dependencies that are only necessary for
8 # GUI applications. To be used for purposes that don't generally need such
9 # components and i.e. only depend on libav
10, withHeadlessDeps ? ffmpegVariant == "headless" || withSmallDeps
11
12 # Dependencies a user might customarily expect from a regular ffmpeg build.
13 # /All/ packages that depend on ffmpeg and some of its feaures should depend
14 # on the small variant. Small means the minimal set of features that satisfies
15 # all dependants in Nixpkgs
16, withSmallDeps ? ffmpegVariant == "small" || withFullDeps
17
18 # Everything enabled; only guarded behind platform exclusivity or brokeness.
19 # If you need to depend on ffmpeg-full because ffmpeg is missing some feature
20 # your package needs, you should enable that feature in regular ffmpeg
21 # instead.
22, withFullDeps ? ffmpegVariant == "full"
23
24, fetchgit
25, fetchpatch
26
27 # Feature flags
28, withAlsa ? withHeadlessDeps && stdenv.isLinux # Alsa in/output supporT
29, withAom ? withFullDeps # AV1 reference encoder
30, withAss ? withHeadlessDeps && stdenv.hostPlatform == stdenv.buildPlatform # (Advanced) SubStation Alpha subtitle rendering
31, withBluray ? withFullDeps # BluRay reading
32, withBs2b ? withFullDeps # bs2b DSP library
33, withBzlib ? withHeadlessDeps
34, withCaca ? withFullDeps # Textual display (ASCII art)
35, withCelt ? withFullDeps # CELT decoder
36, withCrystalhd ? withFullDeps
37, withCuda ? withFullDeps && (with stdenv; (!isDarwin && !hostPlatform.isAarch))
38, withCudaLLVM ? withFullDeps
39, withDav1d ? withHeadlessDeps # AV1 decoder (focused on speed and correctness)
40, withDc1394 ? withFullDeps && !stdenv.isDarwin # IIDC-1394 grabbing (ieee 1394)
41, withDrm ? withHeadlessDeps && (with stdenv; isLinux || isFreeBSD) # libdrm support
42, withFdkAac ? withFullDeps && withUnfree # Fraunhofer FDK AAC de/encoder
43, withFontconfig ? withHeadlessDeps # Needed for drawtext filter
44, withFreetype ? withHeadlessDeps # Needed for drawtext filter
45, withFrei0r ? withFullDeps # frei0r video filtering
46, withFribidi ? withFullDeps # Needed for drawtext filter
47, withGlslang ? withFullDeps && !stdenv.isDarwin
48, withGme ? withFullDeps # Game Music Emulator
49, withGnutls ? withHeadlessDeps
50, withGsm ? withFullDeps # GSM de/encoder
51, withIconv ? withHeadlessDeps
52, withIlbc ? withFullDeps
53, withJack ? withFullDeps && !stdenv.isDarwin # Jack audio
54, withLadspa ? withFullDeps # LADSPA audio filtering
55, withLibplacebo ? withFullDeps && !stdenv.isDarwin # libplacebo video processing library
56, withLzma ? withHeadlessDeps # xz-utils
57, withMfx ? withFullDeps && (with stdenv.targetPlatform; isLinux && !isAarch) # Hardware acceleration via intel-media-sdk/libmfx
58, withModplug ? withFullDeps && !stdenv.isDarwin # ModPlug support
59, withMp3lame ? withHeadlessDeps # LAME MP3 encoder
60, withMysofa ? withFullDeps # HRTF support via SOFAlizer
61, withNvdec ? withHeadlessDeps && !stdenv.isDarwin && stdenv.hostPlatform == stdenv.buildPlatform && !stdenv.isAarch32
62, withNvenc ? withHeadlessDeps && !stdenv.isDarwin && stdenv.hostPlatform == stdenv.buildPlatform && !stdenv.isAarch32
63, withOgg ? withHeadlessDeps # Ogg container used by vorbis & theora
64, withOpenal ? withFullDeps # OpenAL 1.1 capture support
65, withOpencl ? withFullDeps
66, withOpencoreAmrnb ? withFullDeps # AMR-NB de/encoder & AMR-WB decoder
67, withOpengl ? false # OpenGL rendering
68, withOpenh264 ? withFullDeps # H.264/AVC encoder
69, withOpenjpeg ? withFullDeps # JPEG 2000 de/encoder
70, withOpenmpt ? withFullDeps # Tracked music files decoder
71, withOpus ? withHeadlessDeps # Opus de/encoder
72, withPulse ? withSmallDeps && !stdenv.isDarwin # Pulseaudio input support
73, withRav1e ? withFullDeps # AV1 encoder (focused on speed and safety)
74, withRtmp ? false # RTMP[E] support
75, withSamba ? withFullDeps && !stdenv.isDarwin # Samba protocol
76, withSdl2 ? withSmallDeps
77, withSoxr ? withHeadlessDeps # Resampling via soxr
78, withSpeex ? withHeadlessDeps # Speex de/encoder
79, withSrt ? withHeadlessDeps # Secure Reliable Transport (SRT) protocol
80, withSsh ? withHeadlessDeps # SFTP protocol
81, withSvg ? withFullDeps # SVG protocol
82, withSvtav1 ? withFullDeps && !stdenv.isAarch64 # AV1 encoder/decoder (focused on speed and correctness)
83, withTensorflow ? false # Tensorflow dnn backend support
84, withTheora ? withHeadlessDeps # Theora encoder
85, withV4l2 ? withFullDeps && !stdenv.isDarwin # Video 4 Linux support
86, withV4l2M2m ? withV4l2
87, withVaapi ? withHeadlessDeps && (with stdenv; isLinux || isFreeBSD) # Vaapi hardware acceleration
88, withVdpau ? withSmallDeps # Vdpau hardware acceleration
89, withVidStab ? withFullDeps # Video stabilization
90, withVmaf ? withFullDeps && withGPLv3 && !stdenv.isAarch64 # Netflix's VMAF (Video Multi-Method Assessment Fusion)
91, withVoAmrwbenc ? withFullDeps # AMR-WB encoder
92, withVorbis ? withHeadlessDeps # Vorbis de/encoding, native encoder exists
93, withVpx ? withHeadlessDeps && stdenv.buildPlatform == stdenv.hostPlatform # VP8 & VP9 de/encoding
94, withVulkan ? withFullDeps && !stdenv.isDarwin
95, withWebp ? withFullDeps # WebP encoder
96, withX264 ? withHeadlessDeps # H.264/AVC encoder
97, withX265 ? withHeadlessDeps # H.265/HEVC encoder
98, withXavs ? withFullDeps # AVS encoder
99, withXcb ? withXcbShm || withXcbxfixes || withXcbShape # X11 grabbing using XCB
100, withXcbShape ? withFullDeps # X11 grabbing shape rendering
101, withXcbShm ? withFullDeps # X11 grabbing shm communication
102, withXcbxfixes ? withFullDeps # X11 grabbing mouse rendering
103, withXlib ? withFullDeps # Xlib support
104, withXml2 ? withFullDeps # libxml2 support, for IMF and DASH demuxers
105, withXvid ? withHeadlessDeps # Xvid encoder, native encoder exists
106, withZimg ? withHeadlessDeps
107, withZlib ? withHeadlessDeps
108, withZmq ? withFullDeps # Message passing
109
110/*
111 * Licensing options (yes some are listed twice, filters and such are not listed)
112 */
113, withGPL ? true
114, withGPLv3 ? true
115, withUnfree ? false
116
117/*
118 * Build options
119 */
120, withSmallBuild ? false # Optimize for size instead of speed
121, withRuntimeCPUDetection ? true # Detect CPU capabilities at runtime (disable to compile natively)
122, withGrayscale ? withFullDeps # Full grayscale support
123, withSwscaleAlpha ? buildSwscale # Alpha channel support in swscale. You probably want this when buildSwscale.
124, withHardcodedTables ? withHeadlessDeps # Hardcode decode tables instead of runtime generation
125, withSafeBitstreamReader ? withHeadlessDeps # Buffer boundary checking in bitreaders
126, withMultithread ? true # Multithreading via pthreads/win32 threads
127, withNetwork ? withHeadlessDeps # Network support
128, withPixelutils ? withHeadlessDeps # Pixel utils in libavutil
129, withLTO ? false # build with link-time optimization
130/*
131 * Program options
132 */
133, buildFfmpeg ? withHeadlessDeps # Build ffmpeg executable
134, buildFfplay ? withFullDeps # Build ffplay executable
135, buildFfprobe ? withHeadlessDeps # Build ffprobe executable
136, buildQtFaststart ? withFullDeps # Build qt-faststart executable
137, withBin ? buildFfmpeg || buildFfplay || buildFfprobe || buildQtFaststart
138/*
139 * Library options
140 */
141, buildAvcodec ? withHeadlessDeps # Build avcodec library
142, buildAvdevice ? withHeadlessDeps # Build avdevice library
143, buildAvfilter ? withHeadlessDeps # Build avfilter library
144, buildAvformat ? withHeadlessDeps # Build avformat library
145# Deprecated but depended upon by some packages.
146# https://github.com/NixOS/nixpkgs/pull/211834#issuecomment-1417435991)
147, buildAvresample ? withHeadlessDeps && lib.versionOlder version "5" # Build avresample library
148, buildAvutil ? withHeadlessDeps # Build avutil library
149, buildPostproc ? withHeadlessDeps # Build postproc library
150, buildSwresample ? withHeadlessDeps # Build swresample library
151, buildSwscale ? withHeadlessDeps # Build swscale library
152, withLib ? buildAvcodec
153 || buildAvdevice
154 || buildAvfilter
155 || buildAvformat
156 || buildAvutil
157 || buildPostproc
158 || buildSwresample
159 || buildSwscale
160/*
161 * Documentation options
162 */
163, withDocumentation ? withHtmlDoc || withManPages || withPodDoc || withTxtDoc
164, withHtmlDoc ? withHeadlessDeps # HTML documentation pages
165, withManPages ? withHeadlessDeps # Man documentation pages
166, withPodDoc ? withHeadlessDeps # POD documentation pages
167, withTxtDoc ? withHeadlessDeps # Text documentation pages
168# Whether a "doc" output will be produced. Note that withManPages does not produce
169# a "doc" output because its files go to "man".
170, withDoc ? withDocumentation && (withHtmlDoc || withPodDoc || withTxtDoc)
171
172/*
173 * Developer options
174 */
175, withDebug ? false
176, withOptimisations ? true
177, withExtraWarnings ? false
178, withStripping ? false
179
180/*
181 * External libraries options
182 */
183, alsa-lib
184, bzip2
185, clang
186, celt
187, dav1d
188, fdk_aac
189, fontconfig
190, freetype
191, frei0r
192, fribidi
193, game-music-emu
194, gnutls
195, gsm
196, libjack2
197, ladspaH
198, lame
199, libass
200, libaom
201, libbluray
202, libbs2b
203, libcaca
204, libdc1394
205, libraw1394
206, libdrm
207, libiconv
208, intel-media-sdk
209, libmodplug
210, libmysofa
211, libogg
212, libopenmpt
213, libopus
214, libplacebo
215, librsvg
216, libssh
217, libtensorflow
218, libtheora
219, libv4l
220, libva
221, libva-minimal
222, libvdpau
223, libvmaf
224, libvorbis
225, libvpx
226, libwebp
227, libX11
228, libxcb
229, libXv
230, libXext
231, libxml2
232, xz
233, nv-codec-headers
234, nv-codec-headers-11
235, openal
236, ocl-icd # OpenCL ICD
237, opencl-headers # OpenCL headers
238, opencore-amr
239, libGL
240, libGLU
241, openh264
242, openjpeg
243, libpulseaudio
244, rav1e
245, svt-av1
246, rtmpdump
247, samba
248, SDL2
249, soxr
250, speex
251, srt
252, vid-stab
253, vo-amrwbenc
254, x264
255, x265
256, xavs
257, xvidcore
258, zeromq4
259, zimg
260, zlib
261, vulkan-headers
262, vulkan-loader
263, glslang
264/*
265 * Darwin frameworks
266 */
267, AVFoundation
268, Cocoa
269, CoreAudio
270, CoreMedia
271, CoreServices
272, MediaToolbox
273, VideoDecodeAcceleration
274, VideoToolbox
275/*
276 * Testing
277 */
278, testers
279}:
280
281/* Maintainer notes:
282 *
283 * Version bumps:
284 * It should always be safe to bump patch releases (e.g. 2.1.x, x being a patch release)
285 * If adding a new branch, note any configure flags that were added, changed, or deprecated/removed
286 * and make the necessary changes.
287 *
288 * Known issues:
289 * Cross-compiling will disable features not present on host OS
290 * (e.g. dxva2 support [DirectX] will not be enabled unless natively compiled on Cygwin)
291 *
292 */
293
294let
295 inherit (lib) optional optionals optionalString enableFeature versionAtLeast;
296in
297
298
299assert lib.elem ffmpegVariant [ "headless" "small" "full" ];
300
301/*
302 * Licensing dependencies
303 */
304assert withGPLv3 -> withGPL;
305assert withUnfree -> withGPL && withGPLv3;
306/*
307 * Build dependencies
308 */
309assert withPixelutils -> buildAvutil;
310/*
311 * Program dependencies
312 */
313assert buildFfmpeg -> buildAvcodec
314 && buildAvfilter
315 && buildAvformat
316 && (buildSwresample || buildAvresample);
317assert buildFfplay -> buildAvcodec
318 && buildAvformat
319 && buildSwscale
320 && (buildSwresample || buildAvresample);
321assert buildFfprobe -> buildAvcodec && buildAvformat;
322/*
323 * Library dependencies
324 */
325assert buildAvcodec -> buildAvutil; # configure flag since 0.6
326assert buildAvdevice -> buildAvformat
327 && buildAvcodec
328 && buildAvutil; # configure flag since 0.6
329assert buildAvformat -> buildAvcodec && buildAvutil; # configure flag since 0.6
330assert buildPostproc -> buildAvutil;
331assert buildSwscale -> buildAvutil;
332
333stdenv.mkDerivation (finalAttrs: {
334 pname = "ffmpeg" + (if ffmpegVariant == "small" then "" else "-${ffmpegVariant}");
335 inherit version;
336
337 src = fetchgit {
338 url = "https://git.ffmpeg.org/ffmpeg.git";
339 rev = "n${finalAttrs.version}";
340 inherit sha256;
341 };
342
343 postPatch = ''
344 patchShebangs .
345 '' + lib.optionalString withFrei0r ''
346 substituteInPlace libavfilter/vf_frei0r.c \
347 --replace /usr/local/lib/frei0r-1 ${frei0r}/lib/frei0r-1
348 substituteInPlace doc/filters.texi \
349 --replace /usr/local/lib/frei0r-1 ${frei0r}/lib/frei0r-1
350 '' + lib.optionalString withVulkan ''
351 # FIXME: horrible hack, remove for next release
352 substituteInPlace libavutil/hwcontext_vulkan.c \
353 --replace VK_EXT_VIDEO_DECODE VK_KHR_VIDEO_DECODE
354 '';
355
356 patches = map (patch: fetchpatch patch) (extraPatches
357 ++ (lib.optional (lib.versionAtLeast version "6" && lib.versionOlder version "6.1")
358 { # this can be removed post 6.1
359 name = "fix_aacps_tablegen";
360 url = "https://git.ffmpeg.org/gitweb/ffmpeg.git/patch/814178f92647be2411516bbb82f48532373d2554";
361 hash = "sha256-FQV9/PiarPXCm45ldtCsxGHjlrriL8DKpn1LaKJ8owI=";
362 }
363 ));
364
365 configurePlatforms = [];
366 setOutputFlags = false; # Only accepts some of them
367 configureFlags = [
368 #mingw64 is internally treated as mingw32, so 32 and 64 make no difference here
369 "--target_os=${if stdenv.hostPlatform.isMinGW then "mingw64" else stdenv.hostPlatform.parsed.kernel.name}"
370 "--arch=${stdenv.hostPlatform.parsed.cpu.name}"
371 "--pkg-config=${buildPackages.pkg-config.targetPrefix}pkg-config"
372 /*
373 * Licensing flags
374 */
375 (enableFeature withGPL "gpl")
376 (enableFeature withGPLv3 "version3")
377 (enableFeature withUnfree "nonfree")
378 /*
379 * Build flags
380 */
381 # On some ARM platforms --enable-thumb
382 "--enable-shared"
383 "--enable-pic"
384
385 (enableFeature withSmallBuild "small")
386 (enableFeature withRuntimeCPUDetection "runtime-cpudetect")
387 (enableFeature withLTO "lto")
388 (enableFeature withGrayscale "gray")
389 (enableFeature withSwscaleAlpha "swscale-alpha")
390 (enableFeature withHardcodedTables "hardcoded-tables")
391 (enableFeature withSafeBitstreamReader "safe-bitstream-reader")
392
393 (enableFeature (withMultithread && stdenv.targetPlatform.isUnix) "pthreads")
394 (enableFeature (withMultithread && stdenv.targetPlatform.isWindows) "w32threads")
395 "--disable-os2threads" # We don't support OS/2
396
397 (enableFeature withNetwork "network")
398 (enableFeature withPixelutils "pixelutils")
399
400 "--datadir=${placeholder "data"}/share/ffmpeg"
401
402 /*
403 * Program flags
404 */
405 (enableFeature buildFfmpeg "ffmpeg")
406 (enableFeature buildFfplay "ffplay")
407 (enableFeature buildFfprobe "ffprobe")
408 ] ++ optionals withBin [
409 "--bindir=${placeholder "bin"}/bin"
410 ] ++ [
411 /*
412 * Library flags
413 */
414 (enableFeature buildAvcodec "avcodec")
415 (enableFeature buildAvdevice "avdevice")
416 (enableFeature buildAvfilter "avfilter")
417 (enableFeature buildAvformat "avformat")
418 ] ++ optionals (lib.versionOlder version "5") [
419 # Ffmpeg > 4 doesn't know about the flag anymore
420 (enableFeature buildAvresample "avresample")
421 ] ++ [
422 (enableFeature buildAvutil "avutil")
423 (enableFeature (buildPostproc && withGPL) "postproc")
424 (enableFeature buildSwresample "swresample")
425 (enableFeature buildSwscale "swscale")
426 ] ++ optionals withLib [
427 "--libdir=${placeholder "lib"}/lib"
428 "--incdir=${placeholder "dev"}/include"
429 ] ++ [
430 /*
431 * Documentation flags
432 */
433 (enableFeature withDocumentation "doc")
434 (enableFeature withHtmlDoc "htmlpages")
435 (enableFeature withManPages "manpages")
436 ] ++ optionals withManPages [
437 "--mandir=${placeholder "man"}/share/man"
438 ] ++ [
439 (enableFeature withPodDoc "podpages")
440 (enableFeature withTxtDoc "txtpages")
441 ] ++ optionals withDoc [
442 "--docdir=${placeholder "doc"}/share/doc/ffmpeg"
443 ] ++ [
444 /*
445 * External libraries
446 */
447 (enableFeature withAlsa "alsa")
448 (enableFeature withBzlib "bzlib")
449 (enableFeature withCelt "libcelt")
450 (enableFeature withCuda "cuda")
451 (enableFeature withCudaLLVM "cuda-llvm")
452 (enableFeature withDav1d "libdav1d")
453 (enableFeature withFdkAac "libfdk-aac")
454 "--disable-libflite" # Force disable until a solution is found
455 (enableFeature withFontconfig "fontconfig")
456 (enableFeature withFreetype "libfreetype")
457 (enableFeature withFrei0r "frei0r")
458 (enableFeature withFribidi "libfribidi")
459 (enableFeature withGme "libgme")
460 (enableFeature withGnutls "gnutls")
461 (enableFeature withGsm "libgsm")
462 (enableFeature withLadspa "ladspa")
463 (enableFeature withMp3lame "libmp3lame")
464 (enableFeature withAom "libaom")
465 (enableFeature withAss "libass")
466 (enableFeature withBluray "libbluray")
467 (enableFeature withBs2b "libbs2b")
468 (enableFeature withDc1394 "libdc1394")
469 (enableFeature withDrm "libdrm")
470 (enableFeature withIconv "iconv")
471 (enableFeature withJack "libjack")
472 (enableFeature withMfx "libmfx")
473 (enableFeature withModplug "libmodplug")
474 (enableFeature withMysofa "libmysofa")
475 (enableFeature withOpus "libopus")
476 (optionalString (versionAtLeast version "5.0" && withLibplacebo) "--enable-libplacebo")
477 (enableFeature withSvg "librsvg")
478 (enableFeature withSrt "libsrt")
479 (enableFeature withSsh "libssh")
480 (enableFeature withTensorflow "libtensorflow")
481 (enableFeature withTheora "libtheora")
482 (enableFeature withV4l2 "libv4l2")
483 (enableFeature withV4l2M2m "v4l2-m2m")
484 (enableFeature withVaapi "vaapi")
485 (enableFeature withVdpau "vdpau")
486 (enableFeature withVorbis "libvorbis")
487 (enableFeature withVmaf "libvmaf")
488 (enableFeature withVpx "libvpx")
489 (enableFeature withWebp "libwebp")
490 (enableFeature withXlib "xlib")
491 (enableFeature withXcb "libxcb")
492 (enableFeature withXcbShm "libxcb-shm")
493 (enableFeature withXcbxfixes "libxcb-xfixes")
494 (enableFeature withXcbShape "libxcb-shape")
495 (enableFeature withXml2 "libxml2")
496 (enableFeature withLzma "lzma")
497 (enableFeature withNvdec "cuvid")
498 (enableFeature withNvdec "nvdec")
499 (enableFeature withNvenc "nvenc")
500 (enableFeature withOpenal "openal")
501 (enableFeature withOpencl "opencl")
502 (enableFeature withOpencoreAmrnb "libopencore-amrnb")
503 (enableFeature withOpengl "opengl")
504 (enableFeature withOpenh264 "libopenh264")
505 (enableFeature withOpenjpeg "libopenjpeg")
506 (enableFeature withOpenmpt "libopenmpt")
507 (enableFeature withPulse "libpulse")
508 (enableFeature withRav1e "librav1e")
509 (enableFeature withSvtav1 "libsvtav1")
510 (enableFeature withRtmp "librtmp")
511 (enableFeature withSdl2 "sdl2")
512 (enableFeature withSoxr "libsoxr")
513 (enableFeature withSpeex "libspeex")
514 (enableFeature withVidStab "libvidstab") # Actual min. version 2.0
515 (enableFeature withVoAmrwbenc "libvo-amrwbenc")
516 (enableFeature withX264 "libx264")
517 (enableFeature withX265 "libx265")
518 (enableFeature withXavs "libxavs")
519 (enableFeature withXvid "libxvid")
520 (enableFeature withZmq "libzmq")
521 (enableFeature withZimg "libzimg")
522 (enableFeature withZlib "zlib")
523 (enableFeature withVulkan "vulkan")
524 (enableFeature withGlslang "libglslang")
525 (enableFeature withSamba "libsmbclient")
526 /*
527 * Developer flags
528 */
529 (enableFeature withDebug "debug")
530 (enableFeature withOptimisations "optimizations")
531 (enableFeature withExtraWarnings "extra-warnings")
532 (enableFeature withStripping "stripping")
533 ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
534 "--cross-prefix=${stdenv.cc.targetPrefix}"
535 "--enable-cross-compile"
536 "--host-cc=${buildPackages.stdenv.cc}/bin/cc"
537 ] ++ optionals stdenv.cc.isClang [
538 "--cc=clang"
539 "--cxx=clang++"
540 ];
541
542 # ffmpeg embeds the configureFlags verbatim in its binaries and because we
543 # configure binary, include, library dir etc., this causes references in
544 # outputs where we don't want them. Patch the generated config.h to remove all
545 # such references except for data.
546 postConfigure = let
547 toStrip = lib.remove "data" finalAttrs.outputs; # We want to keep references to the data dir.
548 in
549 "remove-references-to ${lib.concatStringsSep " " (map (o: "-t ${placeholder o}") toStrip)} config.h";
550
551 nativeBuildInputs = [ removeReferencesTo addOpenGLRunpath perl pkg-config texinfo yasm ];
552
553 # TODO This was always in buildInputs before, why?
554 buildInputs = optionals withFullDeps [ libdc1394 ]
555 ++ optionals (withFullDeps && !stdenv.isDarwin) [ libraw1394 ] # TODO where does this belong to
556 ++ optionals (withNvdec || withNvenc) [ (if (lib.versionAtLeast version "6") then nv-codec-headers-11 else nv-codec-headers) ]
557 ++ optionals withAlsa [ alsa-lib ]
558 ++ optionals withAom [ libaom ]
559 ++ optionals withAss [ libass ]
560 ++ optionals withBluray [ libbluray ]
561 ++ optionals withBs2b [ libbs2b ]
562 ++ optionals withBzlib [ bzip2 ]
563 ++ optionals withCaca [ libcaca ]
564 ++ optionals withCelt [ celt ]
565 ++ optionals withCudaLLVM [ clang ]
566 ++ optionals withDav1d [ dav1d ]
567 ++ optionals withDrm [ libdrm ]
568 ++ optionals withFdkAac [ fdk_aac ]
569 ++ optionals withFontconfig [ fontconfig ]
570 ++ optionals withFreetype [ freetype ]
571 ++ optionals withFrei0r [ frei0r ]
572 ++ optionals withFribidi [ fribidi ]
573 ++ optionals withGlslang [ glslang ]
574 ++ optionals withGme [ game-music-emu ]
575 ++ optionals withGnutls [ gnutls ]
576 ++ optionals withGsm [ gsm ]
577 ++ optionals withIconv [ libiconv ] # On Linux this should be in libc, do we really need it?
578 ++ optionals withJack [ libjack2 ]
579 ++ optionals withLadspa [ ladspaH ]
580 ++ optionals withLibplacebo [ libplacebo vulkan-headers ]
581 ++ optionals withLzma [ xz ]
582 ++ optionals withMfx [ intel-media-sdk ]
583 ++ optionals withModplug [ libmodplug ]
584 ++ optionals withMp3lame [ lame ]
585 ++ optionals withMysofa [ libmysofa ]
586 ++ optionals withOgg [ libogg ]
587 ++ optionals withOpenal [ openal ]
588 ++ optionals withOpencl [ ocl-icd opencl-headers ]
589 ++ optionals withOpencoreAmrnb [ opencore-amr ]
590 ++ optionals withOpengl [ libGL libGLU ]
591 ++ optionals withOpenh264 [ openh264 ]
592 ++ optionals withOpenjpeg [ openjpeg ]
593 ++ optionals withOpenmpt [ libopenmpt ]
594 ++ optionals withOpus [ libopus ]
595 ++ optionals withPulse [ libpulseaudio ]
596 ++ optionals withRav1e [ rav1e ]
597 ++ optionals withRtmp [ rtmpdump ]
598 ++ optionals withSamba [ samba ]
599 ++ optionals withSdl2 [ SDL2 ]
600 ++ optionals withSoxr [ soxr ]
601 ++ optionals withSpeex [ speex ]
602 ++ optionals withSrt [ srt ]
603 ++ optionals withSsh [ libssh ]
604 ++ optionals withSvg [ librsvg ]
605 ++ optionals withSvtav1 [ svt-av1 ]
606 ++ optionals withTensorflow [ libtensorflow ]
607 ++ optionals withTheora [ libtheora ]
608 ++ optionals withVaapi [ (if withSmallDeps then libva else libva-minimal) ]
609 ++ optionals withVdpau [ libvdpau ]
610 ++ optionals withVidStab [ vid-stab ]
611 ++ optionals withVmaf [ libvmaf ]
612 ++ optionals withVoAmrwbenc [ vo-amrwbenc ]
613 ++ optionals withVorbis [ libvorbis ]
614 ++ optionals withVpx [ libvpx ]
615 ++ optionals withV4l2 [ libv4l ]
616 ++ optionals withVulkan [ vulkan-headers vulkan-loader ]
617 ++ optionals withWebp [ libwebp ]
618 ++ optionals withX264 [ x264 ]
619 ++ optionals withX265 [ x265 ]
620 ++ optionals withXavs [ xavs ]
621 ++ optionals withXcb [ libxcb ]
622 ++ optionals withXlib [ libX11 libXv libXext ]
623 ++ optionals withXml2 [ libxml2 ]
624 ++ optionals withXvid [ xvidcore ]
625 ++ optionals withZimg [ zimg ]
626 ++ optionals withZlib [ zlib ]
627 ++ optionals withZmq [ zeromq4 ]
628 ++ optionals stdenv.isDarwin [
629 # TODO fine-grained flags
630 AVFoundation
631 Cocoa
632 CoreAudio
633 CoreMedia
634 CoreServices
635 MediaToolbox
636 VideoDecodeAcceleration
637 VideoToolbox
638 ];
639
640 buildFlags = [ "all" ]
641 ++ optional buildQtFaststart "tools/qt-faststart"; # Build qt-faststart executable
642
643 doCheck = stdenv.hostPlatform == stdenv.buildPlatform;
644
645 # Fails with SIGABRT otherwise FIXME: Why?
646 checkPhase = let
647 ldLibraryPathEnv = if stdenv.isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH";
648 libsToLink = [ ]
649 ++ optional buildAvcodec "libavcodec"
650 ++ optional buildAvdevice "libavdevice"
651 ++ optional buildAvfilter "libavfilter"
652 ++ optional buildAvformat "libavformat"
653 ++ optional buildAvresample "libavresample"
654 ++ optional buildAvutil "libavutil"
655 ++ optional buildPostproc "libpostproc"
656 ++ optional buildSwresample "libswresample"
657 ++ optional buildSwscale "libswscale"
658 ;
659 in ''
660 ${ldLibraryPathEnv}="${lib.concatStringsSep ":" libsToLink}" make check -j$NIX_BUILD_CORES
661 '';
662
663 outputs = optionals withBin [ "bin" ] # The first output is the one that gets symlinked by default!
664 ++ optionals withLib [ "lib" "dev" ]
665 ++ optionals withDoc [ "doc" ]
666 ++ optionals withManPages [ "man" ]
667 ++ [ "data" "out" ] # We need an "out" output because we get an error otherwise. It's just an empty dir.
668 ;
669
670 postInstall = optionalString buildQtFaststart ''
671 install -D tools/qt-faststart -t $bin/bin
672 '';
673
674 # Set RUNPATH so that libnvcuvid and libcuda in /run/opengl-driver(-32)/lib can be found.
675 # See the explanation in addOpenGLRunpath.
676 postFixup = optionalString (stdenv.isLinux && withLib) ''
677 addOpenGLRunpath ${placeholder "lib"}/lib/libavcodec.so
678 addOpenGLRunpath ${placeholder "lib"}/lib/libavutil.so
679 '';
680
681 enableParallelBuilding = true;
682
683 passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
684
685 meta = with lib; {
686 description = "A complete, cross-platform solution to record, convert and stream audio and video";
687 homepage = "https://www.ffmpeg.org/";
688 changelog = "https://github.com/FFmpeg/FFmpeg/blob/n${version}/Changelog";
689 longDescription = ''
690 FFmpeg is the leading multimedia framework, able to decode, encode, transcode,
691 mux, demux, stream, filter and play pretty much anything that humans and machines
692 have created. It supports the most obscure ancient formats up to the cutting edge.
693 No matter if they were designed by some standards committee, the community or
694 a corporation.
695 '';
696 license = with licenses; [ lgpl21Plus ]
697 ++ optional withGPL gpl2Plus
698 ++ optional withGPLv3 gpl3Plus
699 ++ optional withUnfree unfreeRedistributable;
700 pkgConfigModules = [ "libavutil" ];
701 platforms = platforms.all;
702 maintainers = with maintainers; [ atemu ];
703 };
704})