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