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