nixpkgs/pkgs/development/libraries/ffmpeg/generic.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

221 lines
7.7 KiB
Nix
Raw Normal View History

{ lib, stdenv, buildPackages, fetchurl, pkg-config, addOpenGLRunpath, perl, texinfo, yasm
, alsa-lib, bzip2, fontconfig, freetype, gnutls, libiconv, lame, libass, libogg
, libssh, libtheora, libva, libdrm, libvorbis, xz, soxr
, x264, x265, xvidcore, zimg, zlib, libopus, speex, nv-codec-headers, dav1d
, vpxSupport ? !stdenv.isAarch32, libvpx
, srtSupport ? true, srt
, vaapiSupport ? ((stdenv.isLinux || stdenv.isFreeBSD) && !stdenv.isAarch32)
2022-09-03 19:35:27 +00:00
, openglSupport ? false, libGLU, libGL
, libmfxSupport ? false, intel-media-sdk
, libaomSupport ? false, libaom
# Build options
, runtimeCpuDetectBuild ? true # Detect CPU capabilities at runtime
, multithreadBuild ? true # Multithreading via pthreads/win32 threads
2022-09-03 19:51:00 +00:00
, sdlSupport ? !stdenv.isAarch32, SDL2
2022-09-03 19:35:27 +00:00
, vdpauSupport ? !stdenv.isAarch32, libvdpau
# Developer options
, debugDeveloper ? false
, optimizationsDeveloper ? true
, extraWarningsDeveloper ? false
2022-09-03 19:35:40 +00:00
, Cocoa, CoreMedia, VideoToolbox
# Inherit generics
2021-08-17 21:55:39 +00:00
, branch, sha256, version, patches ? [], knownVulnerabilities ? []
, doCheck ? true
, pulseaudioSupport ? stdenv.isLinux
, libpulseaudio
, ...
}:
/* 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 04:15:42 +00:00
* pulseaudio
*
* Known issues:
* 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 (lib) optional optionals optionalString enableFeature filter;
2022-09-03 20:01:14 +00:00
reqMin = requiredVersion: (builtins.compareVersions requiredVersion branch != 1);
ifMinVer = minVer: flag: if reqMin minVer then flag else null;
2022-01-22 02:53:14 +00:00
ifVerOlder = maxVer: flag: if (lib.versionOlder branch maxVer) then flag else null;
in
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;
2022-09-03 20:02:11 +00:00
outputs = [ "bin" "dev" "out" "man" "doc" ];
setOutputFlags = false; # doesn't accept all and stores configureFlags in libs!
2018-05-10 05:38:51 +00: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}"
"--pkg-config=${buildPackages.pkg-config.targetPrefix}pkg-config"
# License
"--enable-gpl"
"--enable-version3"
# Build flags
"--enable-shared"
2022-09-03 20:01:14 +00:00
"--enable-pic"
(ifMinVer "4.0" (enableFeature srtSupport "libsrt"))
(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"])
++ [
2022-09-03 20:01:14 +00:00
"--disable-os2threads" # We don't support OS/2
"--enable-network"
2022-09-29 09:32:17 +00:00
"--enable-pixelutils"
# Executables
"--enable-ffmpeg"
"--disable-ffplay"
2022-09-03 20:01:14 +00:00
"--enable-ffprobe"
(ifVerOlder "4" "--disable-ffserver")
# Libraries
2022-09-03 20:01:14 +00:00
"--enable-avcodec"
"--enable-avdevice"
"--enable-avfilter"
2022-09-03 20:01:14 +00:00
"--enable-avformat"
2022-09-03 20:02:11 +00:00
(ifVerOlder "5.0" "--enable-avresample")
"--enable-avutil"
"--enable-postproc"
2022-09-03 20:01:14 +00:00
"--enable-swresample"
"--enable-swscale"
# Docs
2022-09-03 20:01:14 +00:00
"--disable-doc"
# External Libraries
"--enable-libass"
"--enable-bzlib"
"--enable-gnutls"
2022-09-03 20:02:11 +00:00
"--enable-fontconfig"
2022-09-03 20:01:14 +00:00
"--enable-libfreetype"
"--enable-libmp3lame"
2022-09-03 20:02:11 +00:00
"--enable-iconv"
"--enable-libtheora"
2022-09-29 09:32:17 +00:00
"--enable-libssh"
2022-09-03 20:01:14 +00:00
(enableFeature vaapiSupport "vaapi")
2022-09-29 09:32:17 +00:00
(enableFeature vaapiSupport "libdrm")
2020-02-08 07:00:37 +00:00
(enableFeature vdpauSupport "vdpau")
"--enable-libvorbis"
2022-09-03 20:01:14 +00:00
(enableFeature vpxSupport "libvpx")
2022-09-29 09:32:17 +00:00
"--enable-lzma"
(enableFeature openglSupport "opengl")
(ifMinVer "4.2" (enableFeature libmfxSupport "libmfx"))
(ifMinVer "4.2" (enableFeature libaomSupport "libaom"))
2022-09-03 20:01:14 +00:00
(lib.optionalString pulseaudioSupport "--enable-libpulse")
2022-09-29 09:32:17 +00:00
(enableFeature sdlSupport "sdl2")
2022-09-03 20:02:11 +00:00
"--enable-libsoxr"
"--enable-libx264"
"--enable-libxvid"
"--enable-libzimg"
"--enable-zlib"
2022-09-29 09:32:17 +00:00
"--enable-libopus"
"--enable-libspeex"
2022-09-29 09:32:17 +00:00
"--enable-libx265"
2022-09-03 19:56:46 +00:00
(ifMinVer "4.2" (enableFeature (reqMin "4.2") "libdav1d"))
# Developer flags
(enableFeature debugDeveloper "debug")
(enableFeature optimizationsDeveloper "optimizations")
(enableFeature extraWarningsDeveloper "extra-warnings")
"--disable-stripping"
] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
2018-05-10 05:38:51 +00: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
libvorbis xz soxr x264 x265 xvidcore zimg 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 04:15:42 +00:00
++ optional vpxSupport libvpx
++ optionals (!stdenv.isDarwin && pulseaudioSupport) [ libpulseaudio ] # Need to be fixed on Darwin
++ optionals vaapiSupport [ libva libdrm ]
++ optional stdenv.isLinux alsa-lib
++ optionals stdenv.isDarwin [ Cocoa CoreMedia VideoToolbox ]
2016-03-22 14:00:36 +00:00
++ optional vdpauSupport libvdpau
2022-09-03 19:51:00 +00:00
++ optional sdlSupport SDL2
++ optional srtSupport srt
++ optional (reqMin "4.2") dav1d;
2016-03-22 14:00:36 +00:00
enableParallelBuilding = true;
2021-08-17 21:55:39 +00:00
inherit doCheck;
checkPhase = let
ldLibraryPathEnv = if stdenv.isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH";
in ''
${ldLibraryPathEnv}="libavcodec:libavdevice:libavfilter:libavformat:libavresample:libavutil:libpostproc:libswresample:libswscale:''${${ldLibraryPathEnv}}" \
make check -j$NIX_BUILD_CORES
'';
# 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 11:00:39 +00:00
installFlags = [ "install-man" ];
passthru = {
2017-05-18 22:59:44 +00:00
inherit vaapiSupport vdpauSupport;
};
meta = with lib; {
description = "A complete, cross-platform solution to record, convert and stream audio and video";
homepage = "https://www.ffmpeg.org/";
changelog = "https://github.com/FFmpeg/FFmpeg/blob/n${version}/Changelog";
longDescription = ''
2018-08-08 18:24:19 +00: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;
maintainers = with maintainers; [ ];
2022-07-21 02:09:14 +00:00
platforms = platforms.all;
2021-04-30 14:29:59 +00:00
inherit branch knownVulnerabilities;
};
}