nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ stdenv, fetchurl, pkgconfig, 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
16}:
17
18assert faacSupport -> enableUnfree;
19
20let inherit (stdenv.lib) optional hasPrefix enableFeature; in
21
22/* ToDo:
23 - more deps, inspiration: https://packages.ubuntu.com/raring/libav-tools
24 - maybe do some more splitting into outputs
25*/
26
27let
28 result = {
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";
33 };
34
35 libavFun = version : sha1 : stdenv.mkDerivation rec {
36 name = "libav-${version}";
37
38 src = fetchurl {
39 url = "${meta.homepage}/releases/${name}.tar.xz";
40 inherit sha1; # upstream directly provides sha1 of releases over https
41 };
42
43 patches = []
44 ++ optional (vpxSupport && hasPrefix "0.8." version) ./vpxenc-0.8.17-libvpx-1.5.patch
45 ;
46
47 postPatch = ''
48 patchShebangs .
49 # another shebang was hidden in a here document text
50 substituteInPlace ./configure --replace "#! /bin/sh" "#!${bash}/bin/sh"
51 '';
52
53 configurePlatforms = [];
54 configureFlags = assert stdenv.lib.all (x: x!=null) buildInputs; [
55 "--arch=${stdenv.hostPlatform.parsed.cpu.name}"
56 "--target_os=${stdenv.hostPlatform.parsed.kernel.name}"
57 #"--enable-postproc" # it's now a separate package in upstream
58 "--disable-avserver" # upstream says it's in a bad state
59 "--enable-avplay"
60 "--enable-shared"
61 "--enable-runtime-cpudetect"
62 "--cc=cc"
63 (enableFeature enableGPL "gpl")
64 (enableFeature enableGPL "swscale")
65 (enableFeature mp3Support "libmp3lame")
66 (enableFeature mp3Support "libmp3lame")
67 (enableFeature speexSupport "libspeex")
68 (enableFeature theoraSupport "libtheora")
69 (enableFeature vorbisSupport "libvorbis")
70 (enableFeature vpxSupport "libvpx")
71 (enableFeature x264Support "libx264")
72 (enableFeature xvidSupport "libxvid")
73 (enableFeature faacSupport "libfaac")
74 (enableFeature faacSupport "nonfree")
75 (enableFeature vaapiSupport "vaapi")
76 (enableFeature vdpauSupport "vdpau")
77 (enableFeature freetypeSupport "libfreetype")
78 ] ++ optional (stdenv.hostPlatform != stdenv.buildPlatform) [
79 "--cross-prefix=${stdenv.cc.targetPrefix}"
80 "--enable-cross-compile"
81 ];
82
83 nativeBuildInputs = [ pkgconfig perl ];
84 buildInputs = [ lame yasm zlib bzip2 SDL bash ]
85 ++ [ perl ] # for install-man target
86 ++ optional mp3Support lame
87 ++ optional speexSupport speex
88 ++ optional theoraSupport libtheora
89 ++ optional vorbisSupport libvorbis
90 ++ optional vpxSupport libvpx
91 ++ optional x264Support x264
92 ++ optional xvidSupport xvidcore
93 ++ optional faacSupport faac
94 ++ optional vaapiSupport libva
95 ++ optional vdpauSupport libvdpau
96 ++ optional freetypeSupport freetype
97 ;
98
99 enableParallelBuilding = true;
100
101 outputs = [ "bin" "dev" "out" ];
102 setOutputFlags = false;
103
104 # alltools to build smaller tools, incl. aviocat, ismindex, qt-faststart, etc.
105 buildFlags = "all alltools install-man";
106
107
108 postInstall = ''
109 moveToOutput bin "$bin"
110 # alltools target compiles an executable in tools/ for every C
111 # source file in tools/, so move those to $out
112 for tool in $(find tools -type f -executable); do
113 mv "$tool" "$bin/bin/"
114 done
115 '';
116
117 doInstallCheck = false; # fails randomly
118 installCheckTarget = "check"; # tests need to be run *after* installation
119
120 passthru = { inherit vdpauSupport; };
121
122 meta = with stdenv.lib; {
123 homepage = https://libav.org/;
124 description = "A complete, cross-platform solution to record, convert and stream audio and video (fork of ffmpeg)";
125 license = with licenses; if enableUnfree then unfree #ToDo: redistributable or not?
126 else if enableGPL then gpl2Plus else lgpl21Plus;
127 platforms = with platforms; linux ++ darwin;
128 };
129 }; # libavFun
130
131in result