1 { lib, stdenv, buildPackages, fetchurl, pkg-config, addOpenGLRunpath, perl, texinfo, yasm
2 , alsaLib, bzip2, fontconfig, freetype, gnutls, libiconv, lame, libass, libogg
3 , libssh, libtheora, libva, libdrm, libvorbis, libvpx, xz, 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
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
14 , debugDeveloper ? false
15 , optimizationsDeveloper ? true
16 , extraWarningsDeveloper ? false
18 , Cocoa, darwinFrameworks ? [ Cocoa ]
20 , branch, sha256, version, patches ? [], ...
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.
29 * Need fixes to support Darwin:
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
46 inherit (stdenv) isDarwin isFreeBSD isLinux isAarch32;
47 inherit (lib) optional optionals optionalString enableFeature filter;
49 cmpVer = builtins.compareVersions;
50 reqMin = requiredVersion: (cmpVer requiredVersion branch != 1);
51 reqMatch = requiredVersion: (cmpVer requiredVersion branch == 0);
53 ifMinVer = minVer: flag: if reqMin minVer then flag else null;
55 # Version specific fix
56 verFix = withoutFix: fixVer: withFix: if reqMatch fixVer then withFix else withoutFix;
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;
61 vaapiSupport = reqMin "0.6" && ((isLinux || isFreeBSD) && !isAarch32);
63 vpxSupport = reqMin "0.6" && !isAarch32;
66 assert openglSupport -> libGL != null && libGLU != null;
67 assert libmfxSupport -> intel-media-sdk != null;
68 assert libaomSupport -> libaom != null;
70 stdenv.mkDerivation rec {
76 url = "https://www.ffmpeg.org/releases/${pname}-${version}.tar.bz2";
80 postPatch = "patchShebangs .";
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!
87 configurePlatforms = [];
88 configureFlags = filter (v: v != null) ([
89 "--arch=${stdenv.hostPlatform.parsed.cpu.name}"
90 "--target_os=${stdenv.hostPlatform.parsed.kernel.name}"
96 (ifMinVer "0.6" "--enable-pic")
97 (enableFeature runtimeCpuDetectBuild "runtime-cpudetect")
98 "--enable-hardcoded-tables"
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"])
106 ["--disable-pthreads" "--disable-w32threads"])
108 (ifMinVer "0.9" "--disable-os2threads") # We don't support OS/2
110 (ifMinVer "2.4" "--enable-pixelutils")
114 (ifMinVer "0.6" "--enable-ffprobe")
115 (if reqMin "4" then null else "--disable-ffserver")
117 (ifMinVer "0.6" "--enable-avcodec")
118 (ifMinVer "0.6" "--enable-avdevice")
120 (ifMinVer "0.6" "--enable-avformat")
121 (ifMinVer "1.0" "--enable-avresample")
122 (ifMinVer "1.1" "--enable-avutil")
124 (ifMinVer "0.9" "--enable-swresample")
127 (ifMinVer "0.6" "--disable-doc")
132 (ifMinVer "1.0" "--enable-fontconfig")
133 (ifMinVer "0.7" "--enable-libfreetype")
134 "--enable-libmp3lame"
135 (ifMinVer "1.2" "--enable-iconv")
137 (ifMinVer "2.1" "--enable-libssh")
138 (ifMinVer "0.6" (enableFeature vaapiSupport "vaapi"))
139 (ifMinVer "3.4" (enableFeature vaapiSupport "libdrm"))
140 (enableFeature vdpauSupport "vdpau")
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")
153 (ifMinVer "2.8" "--enable-libopus")
155 (ifMinVer "2.8" "--enable-libx265")
156 (ifMinVer "4.2" (enableFeature (dav1d != null) "libdav1d"))
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");
169 depsBuildBuild = [ buildPackages.stdenv.cc ];
170 nativeBuildInputs = [ addOpenGLRunpath perl pkg-config texinfo yasm ];
173 bzip2 fontconfig freetype gnutls libiconv lame libass libogg libssh libtheora
174 libvorbis xz 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;
188 enableParallelBuilding = true;
190 doCheck = false; # fails
192 # ffmpeg 3+ generates pkg-config (.pc) files that don't have the
193 # form automatically handled by the multiple-outputs hooks.
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}"
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
208 installFlags = [ "install-man" ];
211 inherit vaapiSupport vdpauSupport;
215 description = "A complete, cross-platform solution to record, convert and stream audio and video";
216 homepage = "http://www.ffmpeg.org/";
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
224 license = licenses.gpl3;
225 platforms = platforms.all;
226 maintainers = with maintainers; [ codyopel ];