1 { lib, stdenv, fetchurl, pkg-config, yasm, bzip2, zlib, perl, bash
2 , mp3Support ? true, lame ? null
3 , speexSupport ? true, speex ? null
4 , theoraSupport ? true, libtheora ? null
5 , vorbisSupport ? true, libvorbis ? null
6 , vpxSupport ? true, libvpx ? null
7 , x264Support ? false, x264 ? null
8 , xvidSupport ? true, xvidcore ? null
9 , faacSupport ? false, faac ? null
10 , vaapiSupport ? true, libva ? null
11 , vdpauSupport ? true, libvdpau ? null
12 , freetypeSupport ? true, freetype ? null # it's small and almost everywhere
13 , SDL # only for avplay in $bin, adds nontrivial closure to it
14 , enableGPL ? true # ToDo: some additional default stuff may need GPL
15 , enableUnfree ? faacSupport
18 assert faacSupport -> enableUnfree;
20 let inherit (lib) optional optionals hasPrefix enableFeature; in
23 - more deps, inspiration: https://packages.ubuntu.com/raring/libav-tools
24 - maybe do some more splitting into outputs
29 # e.g. https://libav.org/releases/libav-11.11.tar.xz.sha1
30 libav_0_8 = libavFun "0.8.21" "d858f65128dad0bac1a8c3a51e5cbb27a7c79b3f";
31 libav_11 = libavFun "11.12" "61d5dcab5fde349834af193a572b12a5fd6a4d42";
32 libav_12 = libavFun "12.3" "386c18c8b857f23dfcf456ce40370716130211d9";
35 libavFun = version : sha1 : stdenv.mkDerivation rec {
40 url = "${meta.homepage}/releases/${pname}-${version}.tar.xz";
41 inherit sha1; # upstream directly provides sha1 of releases over https
45 ++ optional (vpxSupport && hasPrefix "0.8." version) ./vpxenc-0.8.17-libvpx-1.5.patch
46 ++ optional (vpxSupport && hasPrefix "12." version) ./vpx-12.3-libvpx-1.8.patch
51 # another shebang was hidden in a here document text
52 substituteInPlace ./configure --replace "#! /bin/sh" "#!${bash}/bin/sh"
55 configurePlatforms = [];
56 configureFlags = assert lib.all (x: x!=null) buildInputs; [
57 "--arch=${stdenv.hostPlatform.parsed.cpu.name}"
58 "--target_os=${stdenv.hostPlatform.parsed.kernel.name}"
59 #"--enable-postproc" # it's now a separate package in upstream
60 "--disable-avserver" # upstream says it's in a bad state
63 "--enable-runtime-cpudetect"
64 "--cc=${stdenv.cc.targetPrefix}cc"
65 (enableFeature enableGPL "gpl")
66 (enableFeature enableGPL "swscale")
67 (enableFeature mp3Support "libmp3lame")
68 (enableFeature mp3Support "libmp3lame")
69 (enableFeature speexSupport "libspeex")
70 (enableFeature theoraSupport "libtheora")
71 (enableFeature vorbisSupport "libvorbis")
72 (enableFeature vpxSupport "libvpx")
73 (enableFeature x264Support "libx264")
74 (enableFeature xvidSupport "libxvid")
75 (enableFeature faacSupport "libfaac")
76 (enableFeature faacSupport "nonfree")
77 (enableFeature vaapiSupport "vaapi")
78 (enableFeature vdpauSupport "vdpau")
79 (enableFeature freetypeSupport "libfreetype")
80 ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
81 "--cross-prefix=${stdenv.cc.targetPrefix}"
82 "--enable-cross-compile"
85 nativeBuildInputs = [ pkg-config perl ];
86 buildInputs = [ lame yasm zlib bzip2 SDL bash ]
87 ++ [ perl ] # for install-man target
88 ++ optional mp3Support lame
89 ++ optional speexSupport speex
90 ++ optional theoraSupport libtheora
91 ++ optional vorbisSupport libvorbis
92 ++ optional vpxSupport libvpx
93 ++ optional x264Support x264
94 ++ optional xvidSupport xvidcore
95 ++ optional faacSupport faac
96 ++ optional vaapiSupport libva
97 ++ optional vdpauSupport libvdpau
98 ++ optional freetypeSupport freetype
101 enableParallelBuilding = true;
103 outputs = [ "bin" "dev" "out" ];
104 setOutputFlags = false;
106 # alltools to build smaller tools, incl. aviocat, ismindex, qt-faststart, etc.
107 buildFlags = [ "all" "alltools" "install-man" ];
111 moveToOutput bin "$bin"
112 # alltools target compiles an executable in tools/ for every C
113 # source file in tools/, so move those to $out
114 for tool in $(find tools -type f -executable); do
115 mv "$tool" "$bin/bin/"
119 doInstallCheck = false; # fails randomly
120 installCheckTarget = "check"; # tests need to be run *after* installation
122 passthru = { inherit vdpauSupport; };
125 homepage = "https://libav.org/";
126 description = "A complete, cross-platform solution to record, convert and stream audio and video (fork of ffmpeg)";
127 license = with licenses; if enableUnfree then unfree #ToDo: redistributable or not?
128 else if enableGPL then gpl2Plus else lgpl21Plus;
129 platforms = with platforms; linux ++ darwin;
130 knownVulnerabilities =
131 lib.optional (lib.versionOlder version "12.1") "CVE-2017-9051"
132 ++ lib.optionals (lib.versionOlder version "12.3") [ "CVE-2018-5684" "CVE-2018-5766" ]
133 ++ lib.optionals (lib.versionOlder version "12.4") [ "CVE-2019-9717" "CVE-2019-9720" ];