2021-02-05 17:12:51 +00:00
|
|
|
{ lib, stdenv, buildPackages, fetchurl, pkg-config, addOpenGLRunpath, perl, texinfo, yasm
|
2021-06-28 23:13:55 +00:00
|
|
|
, alsa-lib, bzip2, fontconfig, freetype, gnutls, libiconv, lame, libass, libogg
|
2022-10-30 15:09:59 +00:00
|
|
|
, libssh, libtheora, libva, libdrm, libvorbis, xz, soxr
|
2022-01-26 04:04:25 +00:00
|
|
|
, x264, x265, xvidcore, zimg, zlib, libopus, speex, nv-codec-headers, dav1d
|
2022-10-30 15:09:59 +00:00
|
|
|
, vpxSupport ? !stdenv.isAarch32, libvpx
|
|
|
|
, srtSupport ? true, srt
|
|
|
|
, vaapiSupport ? ((stdenv.isLinux || stdenv.isFreeBSD) && !stdenv.isAarch32)
|
|
|
|
, openglSupport ? false, libGLU, libGL
|
|
|
|
, libmfxSupport ? false, intel-media-sdk
|
|
|
|
, libaomSupport ? false, libaom
|
2020-04-24 23:36:52 +00:00
|
|
|
# Build options
|
|
|
|
, runtimeCpuDetectBuild ? true # Detect CPU capabilities at runtime
|
|
|
|
, multithreadBuild ? true # Multithreading via pthreads/win32 threads
|
2022-10-30 15:09:59 +00:00
|
|
|
, sdlSupport ? !stdenv.isAarch32, SDL2
|
|
|
|
, vdpauSupport ? !stdenv.isAarch32, libvdpau
|
2020-04-24 23:36:52 +00:00
|
|
|
# Developer options
|
|
|
|
, debugDeveloper ? false
|
|
|
|
, optimizationsDeveloper ? true
|
|
|
|
, extraWarningsDeveloper ? false
|
2022-10-30 15:09:59 +00:00
|
|
|
, Cocoa, CoreMedia, VideoToolbox
|
2020-04-24 23:36:52 +00:00
|
|
|
# Inherit generics
|
2021-09-18 10:52:07 +00:00
|
|
|
, branch, sha256, version, patches ? [], knownVulnerabilities ? []
|
2022-03-30 09:31:56 +00:00
|
|
|
, doCheck ? true
|
|
|
|
, pulseaudioSupport ? stdenv.isLinux
|
|
|
|
, libpulseaudio
|
|
|
|
, ...
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
/* 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:
|
|
|
|
* 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
|
2021-02-05 17:12:51 +00:00
|
|
|
inherit (lib) optional optionals optionalString enableFeature filter;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-10-30 15:09:59 +00:00
|
|
|
reqMin = requiredVersion: (builtins.compareVersions requiredVersion branch != 1);
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
ifMinVer = minVer: flag: if reqMin minVer then flag else null;
|
|
|
|
|
2022-01-25 03:21:06 +00:00
|
|
|
ifVerOlder = maxVer: flag: if (lib.versionOlder branch maxVer) then flag else null;
|
2020-04-24 23:36:52 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "ffmpeg";
|
|
|
|
inherit version;
|
|
|
|
|
|
|
|
src = fetchurl {
|
|
|
|
url = "https://www.ffmpeg.org/releases/${pname}-${version}.tar.bz2";
|
|
|
|
inherit sha256;
|
|
|
|
};
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
postPatch = "patchShebangs .";
|
2020-04-24 23:36:52 +00:00
|
|
|
inherit patches;
|
|
|
|
|
2022-10-30 15:09:59 +00:00
|
|
|
outputs = [ "bin" "dev" "out" "man" "doc" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
setOutputFlags = false; # doesn't accept all and stores configureFlags in libs!
|
|
|
|
|
|
|
|
configurePlatforms = [];
|
|
|
|
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"
|
2022-10-30 15:09:59 +00:00
|
|
|
"--enable-pic"
|
|
|
|
(ifMinVer "4.0" (enableFeature srtSupport "libsrt"))
|
2020-04-24 23:36:52 +00:00
|
|
|
(enableFeature runtimeCpuDetectBuild "runtime-cpudetect")
|
|
|
|
"--enable-hardcoded-tables"
|
|
|
|
] ++
|
|
|
|
(if multithreadBuild then (
|
|
|
|
if stdenv.isCygwin then
|
|
|
|
["--disable-pthreads" "--enable-w32threads"]
|
|
|
|
else # Use POSIX threads by default
|
|
|
|
["--enable-pthreads" "--disable-w32threads"])
|
|
|
|
else
|
|
|
|
["--disable-pthreads" "--disable-w32threads"])
|
|
|
|
++ [
|
2022-10-30 15:09:59 +00:00
|
|
|
"--disable-os2threads" # We don't support OS/2
|
2020-04-24 23:36:52 +00:00
|
|
|
"--enable-network"
|
2022-10-30 15:09:59 +00:00
|
|
|
"--enable-pixelutils"
|
2020-04-24 23:36:52 +00:00
|
|
|
# Executables
|
|
|
|
"--enable-ffmpeg"
|
|
|
|
"--disable-ffplay"
|
2022-10-30 15:09:59 +00:00
|
|
|
"--enable-ffprobe"
|
|
|
|
(ifVerOlder "4" "--disable-ffserver")
|
2020-04-24 23:36:52 +00:00
|
|
|
# Libraries
|
2022-10-30 15:09:59 +00:00
|
|
|
"--enable-avcodec"
|
|
|
|
"--enable-avdevice"
|
2020-04-24 23:36:52 +00:00
|
|
|
"--enable-avfilter"
|
2022-10-30 15:09:59 +00:00
|
|
|
"--enable-avformat"
|
|
|
|
(ifVerOlder "5.0" "--enable-avresample")
|
|
|
|
"--enable-avutil"
|
2020-04-24 23:36:52 +00:00
|
|
|
"--enable-postproc"
|
2022-10-30 15:09:59 +00:00
|
|
|
"--enable-swresample"
|
2020-04-24 23:36:52 +00:00
|
|
|
"--enable-swscale"
|
|
|
|
# Docs
|
2022-10-30 15:09:59 +00:00
|
|
|
"--disable-doc"
|
2020-04-24 23:36:52 +00:00
|
|
|
# External Libraries
|
2020-09-25 04:45:31 +00:00
|
|
|
"--enable-libass"
|
2020-04-24 23:36:52 +00:00
|
|
|
"--enable-bzlib"
|
|
|
|
"--enable-gnutls"
|
2022-10-30 15:09:59 +00:00
|
|
|
"--enable-fontconfig"
|
|
|
|
"--enable-libfreetype"
|
2020-04-24 23:36:52 +00:00
|
|
|
"--enable-libmp3lame"
|
2022-10-30 15:09:59 +00:00
|
|
|
"--enable-iconv"
|
2020-04-24 23:36:52 +00:00
|
|
|
"--enable-libtheora"
|
2022-10-30 15:09:59 +00:00
|
|
|
"--enable-libssh"
|
|
|
|
(enableFeature vaapiSupport "vaapi")
|
|
|
|
(enableFeature vaapiSupport "libdrm")
|
2020-04-24 23:36:52 +00:00
|
|
|
(enableFeature vdpauSupport "vdpau")
|
|
|
|
"--enable-libvorbis"
|
2022-10-30 15:09:59 +00:00
|
|
|
(enableFeature vpxSupport "libvpx")
|
|
|
|
"--enable-lzma"
|
|
|
|
(enableFeature openglSupport "opengl")
|
2020-04-24 23:36:52 +00:00
|
|
|
(ifMinVer "4.2" (enableFeature libmfxSupport "libmfx"))
|
|
|
|
(ifMinVer "4.2" (enableFeature libaomSupport "libaom"))
|
2022-10-30 15:09:59 +00:00
|
|
|
(lib.optionalString pulseaudioSupport "--enable-libpulse")
|
|
|
|
(enableFeature sdlSupport "sdl2")
|
|
|
|
"--enable-libsoxr"
|
2020-04-24 23:36:52 +00:00
|
|
|
"--enable-libx264"
|
|
|
|
"--enable-libxvid"
|
2022-01-26 04:04:25 +00:00
|
|
|
"--enable-libzimg"
|
2020-04-24 23:36:52 +00:00
|
|
|
"--enable-zlib"
|
2022-10-30 15:09:59 +00:00
|
|
|
"--enable-libopus"
|
2020-04-24 23:36:52 +00:00
|
|
|
"--enable-libspeex"
|
2022-10-30 15:09:59 +00:00
|
|
|
"--enable-libx265"
|
|
|
|
(ifMinVer "4.2" (enableFeature (reqMin "4.2") "libdav1d"))
|
2020-04-24 23:36:52 +00:00
|
|
|
# Developer flags
|
|
|
|
(enableFeature debugDeveloper "debug")
|
|
|
|
(enableFeature optimizationsDeveloper "optimizations")
|
|
|
|
(enableFeature extraWarningsDeveloper "extra-warnings")
|
|
|
|
"--disable-stripping"
|
|
|
|
] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
|
|
|
|
"--cross-prefix=${stdenv.cc.targetPrefix}"
|
|
|
|
"--enable-cross-compile"
|
|
|
|
] ++ optional stdenv.cc.isClang "--cc=clang");
|
|
|
|
|
|
|
|
depsBuildBuild = [ buildPackages.stdenv.cc ];
|
2021-02-05 17:12:51 +00:00
|
|
|
nativeBuildInputs = [ addOpenGLRunpath perl pkg-config texinfo yasm ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
bzip2 fontconfig freetype gnutls libiconv lame libass libogg libssh libtheora
|
2022-10-30 15:09:59 +00:00
|
|
|
libvorbis xz soxr x264 x265 xvidcore zimg zlib libopus speex nv-codec-headers
|
2020-04-24 23:36:52 +00:00
|
|
|
] ++ optionals openglSupport [ libGL libGLU ]
|
|
|
|
++ optional libmfxSupport intel-media-sdk
|
2020-06-18 07:06:33 +00:00
|
|
|
++ optional libaomSupport libaom
|
2020-04-24 23:36:52 +00:00
|
|
|
++ optional vpxSupport libvpx
|
2022-10-30 15:09:59 +00:00
|
|
|
++ 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 ]
|
2020-04-24 23:36:52 +00:00
|
|
|
++ optional vdpauSupport libvdpau
|
2022-10-30 15:09:59 +00:00
|
|
|
++ optional sdlSupport SDL2
|
|
|
|
++ optional srtSupport srt
|
2020-04-24 23:36:52 +00:00
|
|
|
++ optional (reqMin "4.2") dav1d;
|
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
2021-09-18 10:52:07 +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
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# 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 ''
|
2020-06-18 07:06:33 +00:00
|
|
|
# Set RUNPATH so that libnvcuvid and libcuda in /run/opengl-driver(-32)/lib can be found.
|
2020-04-24 23:36:52 +00:00
|
|
|
# See the explanation in addOpenGLRunpath.
|
2020-06-18 07:06:33 +00:00
|
|
|
addOpenGLRunpath $out/lib/libavcodec.so
|
|
|
|
addOpenGLRunpath $out/lib/libavutil.so
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
installFlags = [ "install-man" ];
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
inherit vaapiSupport vdpauSupport;
|
|
|
|
};
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "A complete, cross-platform solution to record, convert and stream audio and video";
|
2021-05-20 23:08:51 +00:00
|
|
|
homepage = "https://www.ffmpeg.org/";
|
|
|
|
changelog = "https://github.com/FFmpeg/FFmpeg/blob/n${version}/Changelog";
|
2020-04-24 23:36:52 +00:00
|
|
|
longDescription = ''
|
|
|
|
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;
|
2022-08-12 12:06:08 +00:00
|
|
|
maintainers = with maintainers; [ ];
|
2020-04-24 23:36:52 +00:00
|
|
|
platforms = platforms.all;
|
2021-05-20 23:08:51 +00:00
|
|
|
inherit branch knownVulnerabilities;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|