1{ stdenv, fetchurl, fetchpatch, pkgconfig, perl, texinfo, yasm
2, hostPlatform
3/*
4 * Licensing options (yes some are listed twice, filters and such are not listed)
5 */
6, gplLicensing ? true # GPL: fdkaac,openssl,frei0r,cdio,samba,utvideo,vidstab,x265,x265,xavs,avid,zvbi,x11grab
7, version3Licensing ? true # (L)GPL3: opencore-amrnb,opencore-amrwb,samba,vo-aacenc,vo-amrwbenc
8, nonfreeLicensing ? false # NONFREE: openssl,fdkaac,blackmagic-design-desktop-video
9/*
10 * Build options
11 */
12, smallBuild ? false # Optimize for size instead of speed
13, runtimeCpuDetectBuild ? true # Detect CPU capabilities at runtime (disable to compile natively)
14, grayBuild ? true # Full grayscale support
15, swscaleAlphaBuild ? true # Alpha channel support in swscale
16, hardcodedTablesBuild ? true # Hardcode decode tables instead of runtime generation
17, safeBitstreamReaderBuild ? true # Buffer boundary checking in bitreaders
18, multithreadBuild ? true # Multithreading via pthreads/win32 threads
19, networkBuild ? true # Network support
20, pixelutilsBuild ? true # Pixel utils in libavutil
21, enableLto ? false # build with link-time optimization
22/*
23 * Program options
24 */
25, ffmpegProgram ? true # Build ffmpeg executable
26, ffplayProgram ? true # Build ffplay executable
27, ffprobeProgram ? true # Build ffprobe executable
28, ffserverProgram ? true # Build ffserver executable
29, qtFaststartProgram ? true # Build qt-faststart executable
30/*
31 * Library options
32 */
33, avcodecLibrary ? true # Build avcodec library
34, avdeviceLibrary ? true # Build avdevice library
35, avfilterLibrary ? true # Build avfilter library
36, avformatLibrary ? true # Build avformat library
37, avresampleLibrary ? true # Build avresample library
38, avutilLibrary ? true # Build avutil library
39, postprocLibrary ? true # Build postproc library
40, swresampleLibrary ? true # Build swresample library
41, swscaleLibrary ? true # Build swscale library
42/*
43 * Documentation options
44 */
45, htmlpagesDocumentation ? false # HTML documentation pages
46, manpagesDocumentation ? true # Man documentation pages
47, podpagesDocumentation ? false # POD documentation pages
48, txtpagesDocumentation ? false # Text documentation pages
49/*
50 * External libraries options
51 */
52, alsaLib ? null # Alsa in/output support
53#, avisynth ? null # Support for reading AviSynth scripts
54, bzip2 ? null
55, celt ? null # CELT decoder
56#, crystalhd ? null # Broadcom CrystalHD hardware acceleration
57#, decklinkExtlib ? false, blackmagic-design-desktop-video ? null # Blackmagic Design DeckLink I/O support
58, fdkaacExtlib ? false, fdk_aac ? null # Fraunhofer FDK AAC de/encoder
59#, flite ? null # Flite (voice synthesis) support
60, fontconfig ? null # Needed for drawtext filter
61, freetype ? null # Needed for drawtext filter
62, frei0r ? null # frei0r video filtering
63, fribidi ? null # Needed for drawtext filter
64, game-music-emu ? null # Game Music Emulator
65, gnutls ? null
66, gsm ? null # GSM de/encoder
67#, ilbc ? null # iLBC de/encoder
68, libjack2 ? null # Jack audio (only version 2 is supported in this build)
69, ladspaH ? null # LADSPA audio filtering
70, lame ? null # LAME MP3 encoder
71, libass ? null # (Advanced) SubStation Alpha subtitle rendering
72, libbluray ? null # BluRay reading
73, libbs2b ? null # bs2b DSP library
74, libcaca ? null # Textual display (ASCII art)
75#, libcdio-paranoia ? null # Audio CD grabbing
76, libdc1394 ? null, libraw1394 ? null # IIDC-1394 grabbing (ieee 1394)
77, libiconv ? null
78#, libiec61883 ? null, libavc1394 ? null # iec61883 (also uses libraw1394)
79#, libmfx ? null # Hardware acceleration vis libmfx
80, libmodplug ? null # ModPlug support
81#, libnut ? null # NUT (de)muxer, native (de)muser exists
82, libogg ? null # Ogg container used by vorbis & theora
83, libopus ? null # Opus de/encoder
84, libsndio ? null # sndio playback/record support
85, libssh ? null # SFTP protocol
86, libtheora ? null # Theora encoder
87, libv4l ? null # Video 4 Linux support
88, libva ? null # Vaapi hardware acceleration
89, libvdpau ? null # Vdpau hardware acceleration
90, libvorbis ? null # Vorbis de/encoding, native encoder exists
91, libvpx ? null # VP8 & VP9 de/encoding
92, libwebp ? null # WebP encoder
93, libX11 ? null # Xlib support
94, libxcb ? null # X11 grabbing using XCB
95, libxcbshmExtlib ? true # X11 grabbing shm communication
96, libxcbxfixesExtlib ? true # X11 grabbing mouse rendering
97, libxcbshapeExtlib ? true # X11 grabbing shape rendering
98, libXv ? null # Xlib support
99, lzma ? null # xz-utils
100, nvenc ? false, nvidia-video-sdk ? null # NVIDIA NVENC support
101, openal ? null # OpenAL 1.1 capture support
102#, opencl ? null # OpenCL code
103, opencore-amr ? null # AMR-NB de/encoder & AMR-WB decoder
104#, opencv ? null # Video filtering
105, openglExtlib ? false, libGLU_combined ? null # OpenGL rendering
106#, openh264 ? null # H.264/AVC encoder
107, openjpeg_1 ? null # JPEG 2000 de/encoder
108, opensslExtlib ? false, openssl ? null
109, libpulseaudio ? null # Pulseaudio input support
110, rtmpdump ? null # RTMP[E] support
111#, libquvi ? null # Quvi input support
112, samba ? null # Samba protocol
113#, schroedinger ? null # Dirac de/encoder
114, SDL2 ? null
115#, shine ? null # Fixed-point MP3 encoder
116, soxr ? null # Resampling via soxr
117, speex ? null # Speex de/encoder
118#, twolame ? null # MP2 encoder
119#, utvideo ? null # Ut Video de/encoder
120, vid-stab ? null # Video stabilization
121#, vo-aacenc ? null # AAC encoder
122#, vo-amrwbenc ? null # AMR-WB encoder
123, wavpack ? null # Wavpack encoder
124, x264 ? null # H.264/AVC encoder
125, x265 ? null # H.265/HEVC encoder
126, xavs ? null # AVS encoder
127, xvidcore ? null # Xvid encoder, native encoder exists
128, zeromq4 ? null # Message passing
129, zlib ? null
130#, zvbi ? null # Teletext support
131/*
132 * Developer options
133 */
134, debugDeveloper ? false
135, optimizationsDeveloper ? true
136, extraWarningsDeveloper ? false
137, strippingDeveloper ? false
138/*
139 * Darwin frameworks
140 */
141, Cocoa, CoreAudio, CoreServices, AVFoundation, MediaToolbox
142, VideoDecodeAcceleration, CF
143}:
144
145/* Maintainer notes:
146 *
147 * Version bumps:
148 * It should always be safe to bump patch releases (e.g. 2.1.x, x being a patch release)
149 * If adding a new branch, note any configure flags that were added, changed, or deprecated/removed
150 * and make the necessary changes.
151 *
152 * Packages with errors:
153 * flite ilbc schroedinger
154 * opencv - circular dependency issue
155 *
156 * Not packaged:
157 * aacplus avisynth cdio-paranoia crystalhd libavc1394 libiec61883
158 * libmxf libnut libquvi nvenc opencl openh264 oss shine twolame
159 * utvideo vo-aacenc vo-amrwbenc xvmc zvbi blackmagic-design-desktop-video
160 *
161 * Need fixes to support Darwin:
162 * frei0r, game-music-emu, gsm, libjack2, libssh, libvpx(stable 1.3.0), openal, openjpeg_1,
163 * pulseaudio, rtmpdump, samba, vid-stab, wavpack, x265. xavs
164 *
165 * Not supported:
166 * stagefright-h264(android only)
167 *
168 * Known issues:
169 * flite: configure fails to find library
170 * Tried modifying ffmpeg's configure script and flite to use pkg-config
171 * Cross-compiling will disable features not present on host OS
172 * (e.g. dxva2 support [DirectX] will not be enabled unless natively compiled on Cygwin)
173 *
174 */
175
176let
177 inherit (stdenv) isCygwin isFreeBSD isLinux;
178 inherit (stdenv.lib) optional optionals optionalString enableFeature;
179in
180
181/*
182 * Licensing dependencies
183 */
184assert version3Licensing -> gplLicensing;
185assert nonfreeLicensing -> gplLicensing && version3Licensing;
186/*
187 * Build dependencies
188 */
189assert networkBuild -> gnutls != null || opensslExtlib;
190assert pixelutilsBuild -> avutilLibrary;
191/*
192 * Program dependencies
193 */
194assert ffmpegProgram -> avcodecLibrary
195 && avfilterLibrary
196 && avformatLibrary
197 && swresampleLibrary;
198assert ffplayProgram -> avcodecLibrary
199 && avformatLibrary
200 && swscaleLibrary
201 && swresampleLibrary
202 && SDL2 != null;
203assert ffprobeProgram -> avcodecLibrary && avformatLibrary;
204assert ffserverProgram -> avformatLibrary;
205/*
206 * Library dependencies
207 */
208assert avcodecLibrary -> avutilLibrary; # configure flag since 0.6
209assert avdeviceLibrary -> avformatLibrary
210 && avcodecLibrary
211 && avutilLibrary; # configure flag since 0.6
212assert avformatLibrary -> avcodecLibrary && avutilLibrary; # configure flag since 0.6
213assert avresampleLibrary -> avutilLibrary;
214assert postprocLibrary -> avutilLibrary;
215assert swresampleLibrary -> soxr != null;
216assert swscaleLibrary -> avutilLibrary;
217/*
218 * External libraries
219 */
220#assert decklinkExtlib -> blackmagic-design-desktop-video != null
221# && !isCygwin && multithreadBuild # POSIX threads required
222# && nonfreeLicensing;
223assert fdkaacExtlib -> fdk_aac != null && nonfreeLicensing;
224assert gnutls != null -> !opensslExtlib;
225assert libxcbshmExtlib -> libxcb != null;
226assert libxcbxfixesExtlib -> libxcb != null;
227assert libxcbshapeExtlib -> libxcb != null;
228assert openglExtlib -> libGLU_combined != null;
229assert opensslExtlib -> gnutls == null && openssl != null && nonfreeLicensing;
230assert nvenc -> nvidia-video-sdk != null && nonfreeLicensing;
231
232stdenv.mkDerivation rec {
233 name = "ffmpeg-full-${version}";
234 version = "3.4.2";
235
236 src = fetchurl {
237 url = "https://www.ffmpeg.org/releases/ffmpeg-${version}.tar.xz";
238 sha256 = "0h6prjn1ijkzzhkyj8mazp0wpx7m0n9ycadjxagf9czqirbyk4ib";
239 };
240
241 prePatch = ''
242 patchShebangs .
243 '' + stdenv.lib.optionalString stdenv.isDarwin ''
244 sed -i 's/#ifndef __MAC_10_11/#if 1/' ./libavcodec/audiotoolboxdec.c
245 '' + stdenv.lib.optionalString (frei0r != null) ''
246 substituteInPlace libavfilter/vf_frei0r.c \
247 --replace /usr/local/lib/frei0r-1 ${frei0r}/lib/frei0r-1
248 substituteInPlace doc/filters.texi \
249 --replace /usr/local/lib/frei0r-1 ${frei0r}/lib/frei0r-1
250 '';
251
252 configureFlags = [
253 /*
254 * Licensing flags
255 */
256 (enableFeature gplLicensing "gpl")
257 (enableFeature version3Licensing "version3")
258 (enableFeature nonfreeLicensing "nonfree")
259 /*
260 * Build flags
261 */
262 # On some ARM platforms --enable-thumb
263 "--enable-shared --disable-static"
264 (enableFeature true "pic")
265 (if stdenv.cc.isClang then "--cc=clang" else null)
266 (enableFeature smallBuild "small")
267 (enableFeature runtimeCpuDetectBuild "runtime-cpudetect")
268 (enableFeature enableLto "lto")
269 (enableFeature grayBuild "gray")
270 (enableFeature swscaleAlphaBuild "swscale-alpha")
271 (enableFeature hardcodedTablesBuild "hardcoded-tables")
272 (enableFeature safeBitstreamReaderBuild "safe-bitstream-reader")
273 (if multithreadBuild then (
274 if isCygwin then
275 "--disable-pthreads --enable-w32threads"
276 else # Use POSIX threads by default
277 "--enable-pthreads --disable-w32threads")
278 else
279 "--disable-pthreads --disable-w32threads")
280 "--disable-os2threads" # We don't support OS/2
281 (enableFeature networkBuild "network")
282 (enableFeature pixelutilsBuild "pixelutils")
283 /*
284 * Program flags
285 */
286 (enableFeature ffmpegProgram "ffmpeg")
287 (enableFeature ffplayProgram "ffplay")
288 (enableFeature ffprobeProgram "ffprobe")
289 (enableFeature ffserverProgram "ffserver")
290 /*
291 * Library flags
292 */
293 (enableFeature avcodecLibrary "avcodec")
294 (enableFeature avdeviceLibrary "avdevice")
295 (enableFeature avfilterLibrary "avfilter")
296 (enableFeature avformatLibrary "avformat")
297 (enableFeature avresampleLibrary "avresample")
298 (enableFeature avutilLibrary "avutil")
299 (enableFeature (postprocLibrary && gplLicensing) "postproc")
300 (enableFeature swresampleLibrary "swresample")
301 (enableFeature swscaleLibrary "swscale")
302 /*
303 * Documentation flags
304 */
305 (enableFeature (htmlpagesDocumentation
306 || manpagesDocumentation
307 || podpagesDocumentation
308 || txtpagesDocumentation) "doc")
309 (enableFeature htmlpagesDocumentation "htmlpages")
310 (enableFeature manpagesDocumentation "manpages")
311 (enableFeature podpagesDocumentation "podpages")
312 (enableFeature txtpagesDocumentation "txtpages")
313 /*
314 * External libraries
315 */
316 #(enableFeature avisynth "avisynth")
317 (enableFeature (bzip2 != null) "bzlib")
318 (enableFeature (celt != null) "libcelt")
319 #(enableFeature crystalhd "crystalhd")
320 #(enableFeature decklinkExtlib "decklink")
321 (enableFeature (fdkaacExtlib && gplLicensing) "libfdk-aac")
322 #(enableFeature (flite != null) "libflite")
323 "--disable-libflite" # Force disable until a solution is found
324 (enableFeature (fontconfig != null) "fontconfig")
325 (enableFeature (freetype != null) "libfreetype")
326 (enableFeature (frei0r != null && gplLicensing) "frei0r")
327 (enableFeature (fribidi != null) "libfribidi")
328 (enableFeature (game-music-emu != null) "libgme")
329 (enableFeature (gnutls != null) "gnutls")
330 (enableFeature (gsm != null) "libgsm")
331 #(enableFeature (ilbc != null) "libilbc")
332 (enableFeature (ladspaH !=null) "ladspa")
333 (enableFeature (lame != null) "libmp3lame")
334 (enableFeature (libass != null) "libass")
335 #(enableFeature (libavc1394 != null) null null)
336 (enableFeature (libbluray != null) "libbluray")
337 (enableFeature (libbs2b != null) "libbs2b")
338 #(enableFeature (libcaca != null) "libcaca")
339 #(enableFeature (cdio-paranoia != null && gplLicensing) "libcdio")
340 (enableFeature (if isLinux then libdc1394 != null && libraw1394 != null else false) "libdc1394")
341 (enableFeature (libiconv != null) "iconv")
342 #(enableFeature (if isLinux then libiec61883 != null && libavc1394 != null && libraw1394 != null else false) "libiec61883")
343 #(enableFeature (libmfx != null) "libmfx")
344 (enableFeature (libmodplug != null) "libmodplug")
345 #(enableFeature (libnut != null) "libnut")
346 (enableFeature (libopus != null) "libopus")
347 (enableFeature (libssh != null) "libssh")
348 (enableFeature (libtheora != null) "libtheora")
349 (enableFeature (if isLinux then libv4l != null else false) "libv4l2")
350 (enableFeature ((isLinux || isFreeBSD) && libva != null) "vaapi")
351 (enableFeature (libvdpau != null) "vdpau")
352 (enableFeature (libvorbis != null) "libvorbis")
353 (enableFeature (libvpx != null) "libvpx")
354 (enableFeature (libwebp != null) "libwebp")
355 (enableFeature (libX11 != null && libXv != null) "xlib")
356 (enableFeature (libxcb != null) "libxcb")
357 (enableFeature libxcbshmExtlib "libxcb-shm")
358 (enableFeature libxcbxfixesExtlib "libxcb-xfixes")
359 (enableFeature libxcbshapeExtlib "libxcb-shape")
360 (enableFeature (lzma != null) "lzma")
361 (enableFeature nvenc "nvenc")
362 (enableFeature (openal != null) "openal")
363 #(enableFeature opencl "opencl")
364 (enableFeature (opencore-amr != null && version3Licensing) "libopencore-amrnb")
365 #(enableFeature (opencv != null) "libopencv")
366 (enableFeature openglExtlib "opengl")
367 #(enableFeature (openh264 != null) "openh264")
368 (enableFeature (openjpeg_1 != null) "libopenjpeg")
369 (enableFeature (opensslExtlib && gplLicensing) "openssl")
370 (enableFeature (libpulseaudio != null) "libpulse")
371 #(enableFeature quvi "libquvi")
372 (enableFeature (rtmpdump != null) "librtmp")
373 #(enableFeature (schroedinger != null) "libschroedinger")
374 #(enableFeature (shine != null) "libshine")
375 (enableFeature (samba != null && gplLicensing && version3Licensing) "libsmbclient")
376 (enableFeature (SDL2 != null) "sdl2")
377 (enableFeature (soxr != null) "libsoxr")
378 (enableFeature (speex != null) "libspeex")
379 #(enableFeature (twolame != null) "libtwolame")
380 #(enableFeature (utvideo != null && gplLicensing) "libutvideo")
381 (enableFeature (vid-stab != null && gplLicensing) "libvidstab") # Actual min. version 2.0
382 #(enableFeature (vo-aacenc != null && version3Licensing) "libvo-aacenc")
383 #(enableFeature (vo-amrwbenc != null && version3Licensing) "libvo-amrwbenc")
384 (enableFeature (wavpack != null) "libwavpack")
385 (enableFeature (x264 != null && gplLicensing) "libx264")
386 (enableFeature (x265 != null && gplLicensing) "libx265")
387 (enableFeature (xavs != null && gplLicensing) "libxavs")
388 (enableFeature (xvidcore != null && gplLicensing) "libxvid")
389 (enableFeature (zeromq4 != null) "libzmq")
390 (enableFeature (zlib != null) "zlib")
391 #(enableFeature (zvbi != null && gplLicensing) "libzvbi")
392 /*
393 * Developer flags
394 */
395 (enableFeature debugDeveloper "debug")
396 (enableFeature optimizationsDeveloper "optimizations")
397 (enableFeature extraWarningsDeveloper "extra-warnings")
398 (enableFeature strippingDeveloper "stripping")
399 ];
400
401 nativeBuildInputs = [ perl pkgconfig texinfo yasm ];
402
403 buildInputs = [
404 bzip2 celt fontconfig freetype frei0r fribidi game-music-emu gnutls gsm
405 libjack2 ladspaH lame libass libbluray libbs2b libcaca libdc1394 libmodplug
406 libogg libopus libssh libtheora libvdpau libvorbis libvpx libwebp libX11
407 libxcb libXv lzma openal openjpeg_1 libpulseaudio rtmpdump opencore-amr
408 samba SDL2 soxr speex vid-stab wavpack x264 x265 xavs xvidcore zeromq4 zlib
409 ] ++ optional openglExtlib libGLU_combined
410 ++ optionals nonfreeLicensing [ fdk_aac openssl ]
411 ++ optional ((isLinux || isFreeBSD) && libva != null) libva
412 ++ optionals isLinux [ alsaLib libraw1394 libv4l ]
413 ++ optionals nvenc [ nvidia-video-sdk ]
414 ++ optionals stdenv.isDarwin [ Cocoa CoreServices CoreAudio AVFoundation
415 MediaToolbox VideoDecodeAcceleration
416 libiconv ];
417
418 # Build qt-faststart executable
419 buildPhase = optional qtFaststartProgram ''make tools/qt-faststart'';
420
421 # Hacky framework patching technique borrowed from the phantomjs2 package
422 postInstall = optionalString qtFaststartProgram ''
423 cp -a tools/qt-faststart $out/bin/
424 '' + optionalString stdenv.isDarwin ''
425 FILES=($(ls $out/bin/*))
426 FILES+=($(ls $out/lib/*.dylib))
427 for f in ''${FILES[@]}; do
428 if [ ! -h "$f" ]; then
429 install_name_tool -change ${CF}/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation "$f"
430 fi
431 done
432 '';
433
434
435 enableParallelBuilding = true;
436
437 /* Cross-compilation is untested, consider this an outline, more work
438 needs to be done to portions of the build to get it to work correctly */
439 crossAttrs = {
440 configurePlatforms = [];
441 configureFlags = configureFlags ++ [
442 "--cross-prefix=${stdenv.cc.targetPrefix}"
443 "--enable-cross-compile"
444 "--target_os=${hostPlatform.parsed.kernel.name}"
445 "--arch=${hostPlatform.arch}"
446 ];
447 };
448
449 meta = with stdenv.lib; {
450 description = "A complete, cross-platform solution to record, convert and stream audio and video";
451 homepage = https://www.ffmpeg.org/;
452 longDescription = ''
453 FFmpeg is the leading multimedia framework, able to decode, encode, transcode,
454 mux, demux, stream, filter and play pretty much anything that humans and machines
455 have created. It supports the most obscure ancient formats up to the cutting edge.
456 No matter if they were designed by some standards committee, the community or
457 a corporation.
458 '';
459 license = (
460 if nonfreeLicensing then
461 licenses.unfreeRedistributable
462 else if version3Licensing then
463 licenses.gpl3
464 else if gplLicensing then
465 licenses.gpl2Plus
466 else
467 licenses.lgpl21Plus
468 );
469 platforms = platforms.all;
470 maintainers = with maintainers; [ codyopel fuuzetsu ];
471 };
472}