3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/pkgs/development/libraries/ffmpeg/generic.nix

230 lines
8.8 KiB
Nix
Raw Normal View History

{ lib, stdenv, buildPackages, fetchurl, pkg-config, addOpenGLRunpath, perl, texinfo, yasm
, alsaLib, bzip2, fontconfig, freetype, gnutls, libiconv, lame, libass, libogg
2021-03-14 18:12:53 +00:00
, libssh, libtheora, libva, libdrm, libvorbis, libvpx, xz, libpulseaudio, soxr
, x264, x265, xvidcore, zlib, libopus, speex, nv-codec-headers, dav1d
2019-11-10 16:44:34 +00:00
, openglSupport ? false, libGLU ? null, libGL ? null
, libmfxSupport ? false, intel-media-sdk ? null
, libaomSupport ? false, libaom ? null
# Build options
, runtimeCpuDetectBuild ? true # Detect CPU capabilities at runtime
, multithreadBuild ? true # Multithreading via pthreads/win32 threads
, sdlSupport ? !stdenv.isAarch32, SDL ? null, SDL2 ? null
, vdpauSupport ? !stdenv.isAarch32, libvdpau ? null
# Developer options
, debugDeveloper ? false
, optimizationsDeveloper ? true
, extraWarningsDeveloper ? false
2015-10-29 13:15:42 +00:00
# Darwin frameworks
, Cocoa, darwinFrameworks ? [ Cocoa ]
# Inherit generics
2021-04-30 15:29:59 +01:00
, branch, sha256, version, patches ? [], knownVulnerabilities ? [], ...
}:
/* Maintainer notes:
*
* THIS IS A MINIMAL BUILD OF FFMPEG, do not include dependencies unless
* a build that depends on ffmpeg requires them to be compiled into ffmpeg,
* see `ffmpeg-full' for an ffmpeg build with all features included.
*
* Need fixes to support Darwin:
2018-07-16 05:15:42 +01:00
* pulseaudio
*
* Known issues:
* 0.6 - fails to compile (unresolved) (so far, only disabling a number of
* features works, but that is not a feasible solution)
* 0.6.90 - mmx: compile errors (fix: disable for 0.6.90-rc0)
* 1.1 - libsoxr: compile error (fix: disable for 1.1)
* Support was initially added in 1.1 before soxr api change, fix
* would probably be to add soxr-1.0
* ALL - Cross-compiling will disable features not present on host OS
* (e.g. dxva2 support [DirectX] will not be enabled unless natively
* compiled on Cygwin)
*
*/
let
inherit (stdenv) isDarwin isFreeBSD isLinux isAarch32;
inherit (lib) optional optionals optionalString enableFeature filter;
cmpVer = builtins.compareVersions;
reqMin = requiredVersion: (cmpVer requiredVersion branch != 1);
reqMatch = requiredVersion: (cmpVer requiredVersion branch == 0);
ifMinVer = minVer: flag: if reqMin minVer then flag else null;
# Version specific fix
verFix = withoutFix: fixVer: withFix: if reqMatch fixVer then withFix else withoutFix;
2016-03-22 14:00:36 +00:00
# Disable dependency that needs fixes before it will work on Darwin or Arm
disDarwinOrArmFix = origArg: minVer: fixArg: if ((isDarwin || isAarch32) && reqMin minVer) then fixArg else origArg;
2017-05-18 23:59:44 +01:00
vaapiSupport = reqMin "0.6" && ((isLinux || isFreeBSD) && !isAarch32);
2018-07-16 05:15:42 +01:00
vpxSupport = reqMin "0.6" && !isAarch32;
in
2019-11-10 16:44:34 +00:00
assert openglSupport -> libGL != null && libGLU != null;
assert libmfxSupport -> intel-media-sdk != null;
assert libaomSupport -> libaom != null;
stdenv.mkDerivation rec {
pname = "ffmpeg";
inherit version;
src = fetchurl {
url = "https://www.ffmpeg.org/releases/${pname}-${version}.tar.bz2";
inherit sha256;
};
postPatch = "patchShebangs .";
inherit patches;
2017-07-11 09:53:28 +01:00
outputs = [ "bin" "dev" "out" "man" ]
++ optional (reqMin "1.0") "doc" ; # just dev-doc
setOutputFlags = false; # doesn't accept all and stores configureFlags in libs!
2018-05-10 06:38:51 +01:00
configurePlatforms = [];
2019-11-11 19:53:15 +00:00
configureFlags = filter (v: v != null) ([
"--arch=${stdenv.hostPlatform.parsed.cpu.name}"
"--target_os=${stdenv.hostPlatform.parsed.kernel.name}"
# License
"--enable-gpl"
"--enable-version3"
# Build flags
"--enable-shared"
(ifMinVer "0.6" "--enable-pic")
(enableFeature runtimeCpuDetectBuild "runtime-cpudetect")
"--enable-hardcoded-tables"
2019-11-11 19:53:15 +00:00
] ++
(if multithreadBuild then (
if stdenv.isCygwin then
2019-11-11 19:53:15 +00:00
["--disable-pthreads" "--enable-w32threads"]
else # Use POSIX threads by default
2019-11-11 19:53:15 +00:00
["--enable-pthreads" "--disable-w32threads"])
else
2019-11-11 19:53:15 +00:00
["--disable-pthreads" "--disable-w32threads"])
++ [
(ifMinVer "0.9" "--disable-os2threads") # We don't support OS/2
"--enable-network"
(ifMinVer "2.4" "--enable-pixelutils")
# Executables
"--enable-ffmpeg"
"--disable-ffplay"
(ifMinVer "0.6" "--enable-ffprobe")
2018-05-10 15:44:40 +01:00
(if reqMin "4" then null else "--disable-ffserver")
# Libraries
(ifMinVer "0.6" "--enable-avcodec")
(ifMinVer "0.6" "--enable-avdevice")
"--enable-avfilter"
(ifMinVer "0.6" "--enable-avformat")
(ifMinVer "1.0" "--enable-avresample")
(ifMinVer "1.1" "--enable-avutil")
"--enable-postproc"
(ifMinVer "0.9" "--enable-swresample")
"--enable-swscale"
# Docs
(ifMinVer "0.6" "--disable-doc")
# External Libraries
"--enable-libass"
"--enable-bzlib"
"--enable-gnutls"
(ifMinVer "1.0" "--enable-fontconfig")
(ifMinVer "0.7" "--enable-libfreetype")
"--enable-libmp3lame"
(ifMinVer "1.2" "--enable-iconv")
"--enable-libtheora"
(ifMinVer "2.1" "--enable-libssh")
2017-05-18 23:59:44 +01:00
(ifMinVer "0.6" (enableFeature vaapiSupport "vaapi"))
2018-10-29 12:23:42 +00:00
(ifMinVer "3.4" (enableFeature vaapiSupport "libdrm"))
2020-02-08 07:00:37 +00:00
(enableFeature vdpauSupport "vdpau")
"--enable-libvorbis"
2018-07-16 05:15:42 +01:00
(ifMinVer "0.6" (enableFeature vpxSupport "libvpx"))
(ifMinVer "2.4" "--enable-lzma")
(ifMinVer "2.2" (enableFeature openglSupport "opengl"))
(ifMinVer "4.2" (enableFeature libmfxSupport "libmfx"))
(ifMinVer "4.2" (enableFeature libaomSupport "libaom"))
2016-03-22 14:00:36 +00:00
(disDarwinOrArmFix (ifMinVer "0.9" "--enable-libpulse") "0.9" "--disable-libpulse")
(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
(ifMinVer "1.2" "--enable-libsoxr")
"--enable-libx264"
"--enable-libxvid"
"--enable-zlib"
2016-03-26 14:01:22 +00:00
(ifMinVer "2.8" "--enable-libopus")
"--enable-libspeex"
2016-04-09 12:00:30 +01:00
(ifMinVer "2.8" "--enable-libx265")
(ifMinVer "4.2" (enableFeature (dav1d != null) "libdav1d"))
# Developer flags
(enableFeature debugDeveloper "debug")
(enableFeature optimizationsDeveloper "optimizations")
(enableFeature extraWarningsDeveloper "extra-warnings")
"--disable-stripping"
# Disable mmx support for 0.6.90
(verFix null "0.6.90" "--disable-mmx")
] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
2018-05-10 06:38:51 +01:00
"--cross-prefix=${stdenv.cc.targetPrefix}"
"--enable-cross-compile"
2019-11-11 19:53:15 +00:00
] ++ optional stdenv.cc.isClang "--cc=clang");
depsBuildBuild = [ buildPackages.stdenv.cc ];
nativeBuildInputs = [ addOpenGLRunpath perl pkg-config texinfo yasm ];
buildInputs = [
bzip2 fontconfig freetype gnutls libiconv lame libass libogg libssh libtheora
2021-03-14 18:12:53 +00:00
libvorbis xz soxr x264 x265 xvidcore zlib libopus speex nv-codec-headers
2019-11-10 16:44:34 +00:00
] ++ optionals openglSupport [ libGL libGLU ]
++ optional libmfxSupport intel-media-sdk
++ optional libaomSupport libaom
2018-07-16 05:15:42 +01:00
++ optional vpxSupport libvpx
++ optionals (!isDarwin && !isAarch32) [ libpulseaudio ] # Need to be fixed on Darwin and ARM
++ optional ((isLinux || isFreeBSD) && !isAarch32) libva
2018-10-29 12:23:42 +00:00
++ optional ((isLinux || isFreeBSD) && !isAarch32) libdrm
2015-10-29 13:15:42 +00:00
++ optional isLinux alsaLib
++ optionals isDarwin darwinFrameworks
2016-03-22 14:00:36 +00:00
++ optional vdpauSupport libvdpau
++ optional sdlSupport (if reqMin "3.2" then SDL2 else SDL)
++ optional (reqMin "4.2") dav1d;
2016-03-22 14:00:36 +00:00
enableParallelBuilding = true;
doCheck = false; # fails
# ffmpeg 3+ generates pkg-config (.pc) files that don't have the
# form automatically handled by the multiple-outputs hooks.
postFixup = ''
moveToOutput bin "$bin"
moveToOutput share/ffmpeg/examples "$doc"
for pc in ''${!outputDev}/lib/pkgconfig/*.pc; do
substituteInPlace $pc \
--replace "includedir=$out" "includedir=''${!outputInclude}"
done
'' + optionalString stdenv.isLinux ''
# Set RUNPATH so that libnvcuvid and libcuda in /run/opengl-driver(-32)/lib can be found.
# See the explanation in addOpenGLRunpath.
addOpenGLRunpath $out/lib/libavcodec.so
addOpenGLRunpath $out/lib/libavutil.so
'';
2016-04-09 12:00:39 +01:00
installFlags = [ "install-man" ];
passthru = {
2017-05-18 23:59:44 +01:00
inherit vaapiSupport vdpauSupport;
};
meta = with lib; {
description = "A complete, cross-platform solution to record, convert and stream audio and video";
homepage = "http://www.ffmpeg.org/";
longDescription = ''
2018-08-08 19:24:19 +01:00
FFmpeg is the leading multimedia framework, able to decode, encode, transcode,
mux, demux, stream, filter and play pretty much anything that humans and machines
have created. It supports the most obscure ancient formats up to the cutting edge.
No matter if they were designed by some standards committee, the community or
a corporation.
'';
license = licenses.gpl3;
platforms = platforms.all;
maintainers = with maintainers; [ codyopel ];
2021-04-30 15:29:59 +01:00
inherit branch knownVulnerabilities;
};
}