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