nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ stdenv, buildPackages, fetchurl, pkgconfig, addOpenGLRunpath, perl, texinfo, yasm
2, alsaLib, bzip2, fontconfig, freetype, gnutls, libiconv, lame, libass, libogg
3, libssh, libtheora, libva, libdrm, libvorbis, libvpx, lzma, libpulseaudio, soxr
4, x264, x265, xvidcore, zlib, libopus, speex, nv-codec-headers, dav1d
5, openglSupport ? false, libGLU ? null, libGL ? null
6, libmfxSupport ? false, intel-media-sdk ? null
7, libaomSupport ? false, libaom ? null
8# Build options
9, runtimeCpuDetectBuild ? true # Detect CPU capabilities at runtime
10, multithreadBuild ? true # Multithreading via pthreads/win32 threads
11, sdlSupport ? !stdenv.isAarch32, SDL ? null, SDL2 ? null
12, vdpauSupport ? !stdenv.isAarch32, libvdpau ? null
13# Developer options
14, debugDeveloper ? false
15, optimizationsDeveloper ? true
16, extraWarningsDeveloper ? false
17# Darwin frameworks
18, Cocoa, darwinFrameworks ? [ Cocoa ]
19# Inherit generics
20, branch, sha256, version, patches ? [], ...
21}:
22
23/* Maintainer notes:
24 *
25 * THIS IS A MINIMAL BUILD OF FFMPEG, do not include dependencies unless
26 * a build that depends on ffmpeg requires them to be compiled into ffmpeg,
27 * see `ffmpeg-full' for an ffmpeg build with all features included.
28 *
29 * Need fixes to support Darwin:
30 * pulseaudio
31 *
32 * Known issues:
33 * 0.6 - fails to compile (unresolved) (so far, only disabling a number of
34 * features works, but that is not a feasible solution)
35 * 0.6.90 - mmx: compile errors (fix: disable for 0.6.90-rc0)
36 * 1.1 - libsoxr: compile error (fix: disable for 1.1)
37 * Support was initially added in 1.1 before soxr api change, fix
38 * would probably be to add soxr-1.0
39 * ALL - Cross-compiling will disable features not present on host OS
40 * (e.g. dxva2 support [DirectX] will not be enabled unless natively
41 * compiled on Cygwin)
42 *
43 */
44
45let
46 inherit (stdenv) isDarwin isFreeBSD isLinux isAarch32;
47 inherit (stdenv.lib) optional optionals optionalString enableFeature filter;
48
49 cmpVer = builtins.compareVersions;
50 reqMin = requiredVersion: (cmpVer requiredVersion branch != 1);
51 reqMatch = requiredVersion: (cmpVer requiredVersion branch == 0);
52
53 ifMinVer = minVer: flag: if reqMin minVer then flag else null;
54
55 # Version specific fix
56 verFix = withoutFix: fixVer: withFix: if reqMatch fixVer then withFix else withoutFix;
57
58 # Disable dependency that needs fixes before it will work on Darwin or Arm
59 disDarwinOrArmFix = origArg: minVer: fixArg: if ((isDarwin || isAarch32) && reqMin minVer) then fixArg else origArg;
60
61 vaapiSupport = reqMin "0.6" && ((isLinux || isFreeBSD) && !isAarch32);
62
63 vpxSupport = reqMin "0.6" && !isAarch32;
64in
65
66assert openglSupport -> libGL != null && libGLU != null;
67assert libmfxSupport -> intel-media-sdk != null;
68assert libaomSupport -> libaom != null;
69
70stdenv.mkDerivation rec {
71
72 pname = "ffmpeg";
73 inherit version;
74
75 src = fetchurl {
76 url = "https://www.ffmpeg.org/releases/${pname}-${version}.tar.bz2";
77 inherit sha256;
78 };
79
80 postPatch = ''patchShebangs .'';
81 inherit patches;
82
83 outputs = [ "bin" "dev" "out" "man" ]
84 ++ optional (reqMin "1.0") "doc" ; # just dev-doc
85 setOutputFlags = false; # doesn't accept all and stores configureFlags in libs!
86
87 configurePlatforms = [];
88 configureFlags = filter (v: v != null) ([
89 "--arch=${stdenv.hostPlatform.parsed.cpu.name}"
90 "--target_os=${stdenv.hostPlatform.parsed.kernel.name}"
91 # License
92 "--enable-gpl"
93 "--enable-version3"
94 # Build flags
95 "--enable-shared"
96 (ifMinVer "0.6" "--enable-pic")
97 (enableFeature runtimeCpuDetectBuild "runtime-cpudetect")
98 "--enable-hardcoded-tables"
99 ] ++
100 (if multithreadBuild then (
101 if stdenv.isCygwin then
102 ["--disable-pthreads" "--enable-w32threads"]
103 else # Use POSIX threads by default
104 ["--enable-pthreads" "--disable-w32threads"])
105 else
106 ["--disable-pthreads" "--disable-w32threads"])
107 ++ [
108 (ifMinVer "0.9" "--disable-os2threads") # We don't support OS/2
109 "--enable-network"
110 (ifMinVer "2.4" "--enable-pixelutils")
111 # Executables
112 "--enable-ffmpeg"
113 "--disable-ffplay"
114 (ifMinVer "0.6" "--enable-ffprobe")
115 (if reqMin "4" then null else "--disable-ffserver")
116 # Libraries
117 (ifMinVer "0.6" "--enable-avcodec")
118 (ifMinVer "0.6" "--enable-avdevice")
119 "--enable-avfilter"
120 (ifMinVer "0.6" "--enable-avformat")
121 (ifMinVer "1.0" "--enable-avresample")
122 (ifMinVer "1.1" "--enable-avutil")
123 "--enable-postproc"
124 (ifMinVer "0.9" "--enable-swresample")
125 "--enable-swscale"
126 # Docs
127 (ifMinVer "0.6" "--disable-doc")
128 # External Libraries
129 "--enable-libass"
130 "--enable-bzlib"
131 "--enable-gnutls"
132 (ifMinVer "1.0" "--enable-fontconfig")
133 (ifMinVer "0.7" "--enable-libfreetype")
134 "--enable-libmp3lame"
135 (ifMinVer "1.2" "--enable-iconv")
136 "--enable-libtheora"
137 (ifMinVer "2.1" "--enable-libssh")
138 (ifMinVer "0.6" (enableFeature vaapiSupport "vaapi"))
139 (ifMinVer "3.4" (enableFeature vaapiSupport "libdrm"))
140 (enableFeature vdpauSupport "vdpau")
141 "--enable-libvorbis"
142 (ifMinVer "0.6" (enableFeature vpxSupport "libvpx"))
143 (ifMinVer "2.4" "--enable-lzma")
144 (ifMinVer "2.2" (enableFeature openglSupport "opengl"))
145 (ifMinVer "4.2" (enableFeature libmfxSupport "libmfx"))
146 (ifMinVer "4.2" (enableFeature libaomSupport "libaom"))
147 (disDarwinOrArmFix (ifMinVer "0.9" "--enable-libpulse") "0.9" "--disable-libpulse")
148 (ifMinVer "2.5" (if sdlSupport && reqMin "3.2" then "--enable-sdl2" else if sdlSupport then "--enable-sdl" else null)) # autodetected before 2.5, SDL1 support removed in 3.2 for SDL2
149 (ifMinVer "1.2" "--enable-libsoxr")
150 "--enable-libx264"
151 "--enable-libxvid"
152 "--enable-zlib"
153 (ifMinVer "2.8" "--enable-libopus")
154 "--enable-libspeex"
155 (ifMinVer "2.8" "--enable-libx265")
156 (ifMinVer "4.2" (enableFeature (dav1d != null) "libdav1d"))
157 # Developer flags
158 (enableFeature debugDeveloper "debug")
159 (enableFeature optimizationsDeveloper "optimizations")
160 (enableFeature extraWarningsDeveloper "extra-warnings")
161 "--disable-stripping"
162 # Disable mmx support for 0.6.90
163 (verFix null "0.6.90" "--disable-mmx")
164 ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
165 "--cross-prefix=${stdenv.cc.targetPrefix}"
166 "--enable-cross-compile"
167 ] ++ optional stdenv.cc.isClang "--cc=clang");
168
169 depsBuildBuild = [ buildPackages.stdenv.cc ];
170 nativeBuildInputs = [ addOpenGLRunpath perl pkgconfig texinfo yasm ];
171
172 buildInputs = [
173 bzip2 fontconfig freetype gnutls libiconv lame libass libogg libssh libtheora
174 libvorbis lzma soxr x264 x265 xvidcore zlib libopus speex nv-codec-headers
175 ] ++ optionals openglSupport [ libGL libGLU ]
176 ++ optional libmfxSupport intel-media-sdk
177 ++ optional libaomSupport libaom
178 ++ optional vpxSupport libvpx
179 ++ optionals (!isDarwin && !isAarch32) [ libpulseaudio ] # Need to be fixed on Darwin and ARM
180 ++ optional ((isLinux || isFreeBSD) && !isAarch32) libva
181 ++ optional ((isLinux || isFreeBSD) && !isAarch32) libdrm
182 ++ optional isLinux alsaLib
183 ++ optionals isDarwin darwinFrameworks
184 ++ optional vdpauSupport libvdpau
185 ++ optional sdlSupport (if reqMin "3.2" then SDL2 else SDL)
186 ++ optional (reqMin "4.2") dav1d;
187
188 enableParallelBuilding = true;
189
190 doCheck = false; # fails
191
192 # ffmpeg 3+ generates pkg-config (.pc) files that don't have the
193 # form automatically handled by the multiple-outputs hooks.
194 postFixup = ''
195 moveToOutput bin "$bin"
196 moveToOutput share/ffmpeg/examples "$doc"
197 for pc in ''${!outputDev}/lib/pkgconfig/*.pc; do
198 substituteInPlace $pc \
199 --replace "includedir=$out" "includedir=''${!outputInclude}"
200 done
201 '' + optionalString stdenv.isLinux ''
202 # Set RUNPATH so that libnvcuvid and libcuda in /run/opengl-driver(-32)/lib can be found.
203 # See the explanation in addOpenGLRunpath.
204 addOpenGLRunpath $out/lib/libavcodec.so
205 addOpenGLRunpath $out/lib/libavutil.so
206 '';
207
208 installFlags = [ "install-man" ];
209
210 passthru = {
211 inherit vaapiSupport vdpauSupport;
212 };
213
214 meta = with stdenv.lib; {
215 description = "A complete, cross-platform solution to record, convert and stream audio and video";
216 homepage = "http://www.ffmpeg.org/";
217 longDescription = ''
218 FFmpeg is the leading multimedia framework, able to decode, encode, transcode,
219 mux, demux, stream, filter and play pretty much anything that humans and machines
220 have created. It supports the most obscure ancient formats up to the cutting edge.
221 No matter if they were designed by some standards committee, the community or
222 a corporation.
223 '';
224 license = licenses.gpl3;
225 platforms = platforms.all;
226 maintainers = with maintainers; [ codyopel ];
227 inherit branch;
228 };
229}