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