From 4fc9f2e86b3fd1d6604cc2f65c7c18466d7c37cf Mon Sep 17 00:00:00 2001 From: Atemu Date: Fri, 2 Dec 2022 19:53:02 +0100 Subject: [PATCH] ffmpeg: merge with ffmpeg-full A ton of cleanup and refactoring went into this. Too much to list. Co-authored-by: Anderson Torres Co-authored-by: Martin Weinelt --- pkgs/development/libraries/ffmpeg/4.nix | 10 +- pkgs/development/libraries/ffmpeg/5.nix | 9 +- pkgs/development/libraries/ffmpeg/generic.nix | 778 ++++++++++++++---- pkgs/top-level/all-packages.nix | 56 +- 4 files changed, 634 insertions(+), 219 deletions(-) diff --git a/pkgs/development/libraries/ffmpeg/4.nix b/pkgs/development/libraries/ffmpeg/4.nix index ac88df930768..7882c19da8f3 100644 --- a/pkgs/development/libraries/ffmpeg/4.nix +++ b/pkgs/development/libraries/ffmpeg/4.nix @@ -1,8 +1,4 @@ -{ callPackage, ... }@args: - -callPackage ./generic.nix (rec { +import ./generic.nix rec { version = "4.4.3"; - branch = version; - sha256 = "sha256-M7jC281TD+HbVxBBU0Vgm0yiJ70NoeOpMy27DxH9Jzo="; - -} // args) + sha256 = "sha256-zZDzG1hD+0AHqElzeGR6OVm+H5wqtdktloSPmEUzT/c="; +} diff --git a/pkgs/development/libraries/ffmpeg/5.nix b/pkgs/development/libraries/ffmpeg/5.nix index b19c22a55f3a..7ff9b1fc2e4c 100644 --- a/pkgs/development/libraries/ffmpeg/5.nix +++ b/pkgs/development/libraries/ffmpeg/5.nix @@ -1,7 +1,4 @@ -{ callPackage, ... }@args: - -callPackage ./generic.nix (rec { +import ./generic.nix rec { version = "5.1.2"; - branch = version; - sha256 = "sha256-OaC8yNmFSfFsVwYkZ4JGpqxzbAZs69tAn5UC6RWyLys="; -} // args) + sha256 = "sha256-4jcfwIE0/DgP7ibwkrSm/aPiHIMFn34JNcXkCMx4ceI="; +} diff --git a/pkgs/development/libraries/ffmpeg/generic.nix b/pkgs/development/libraries/ffmpeg/generic.nix index 01995e9237b1..0acf45212e9d 100644 --- a/pkgs/development/libraries/ffmpeg/generic.nix +++ b/pkgs/development/libraries/ffmpeg/generic.nix @@ -1,205 +1,645 @@ -{ 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) -, 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 -, sdlSupport ? !stdenv.isAarch32, SDL2 -, vdpauSupport ? !stdenv.isAarch32, libvdpau -# Developer options -, debugDeveloper ? false -, optimizationsDeveloper ? true -, extraWarningsDeveloper ? false -, Cocoa, CoreMedia, VideoToolbox -# Inherit generics -, branch, sha256, version, patches ? [], knownVulnerabilities ? [] -, doCheck ? true -, pulseaudioSupport ? stdenv.isLinux +{ version, sha256, extraPatches ? [], knownVulnerabilities ? [] }: + +{ lib, stdenv, buildPackages, removeReferencesTo, addOpenGLRunpath, pkg-config, perl, texinfo, yasm + +, ffmpegVariant ? "small" # Decides which dependencies are enabled by default + + # Build with headless deps; excludes dependencies that are only necessary for + # GUI applications. To be used for purposes that don't generally need such + # components and i.e. only depend on libav +, withHeadlessDeps ? ffmpegVariant == "headless" || withSmallDeps + + # Dependencies a user might customarily expect from a regular ffmpeg build. + # /All/ packages that depend on ffmpeg and some of its feaures should depend + # on the small variant. Small means the minimal set of features that satisfies + # all dependants in Nixpkgs +, withSmallDeps ? ffmpegVariant == "small" || withFullDeps + + # Everything enabled; only guarded behind platform exclusivity or brokeness. + # If you need to depend on ffmpeg-full because ffmpeg is missing some feature + # your package needs, you should enable that feature in regular ffmpeg + # instead. +, withFullDeps ? ffmpegVariant == "full" + +, fetchgit +, fetchpatch + + # Feature flags +, withAlsa ? withHeadlessDeps && stdenv.isLinux # Alsa in/output supporT +, withAom ? withFullDeps # AV1 reference encoder +, withAss ? withHeadlessDeps && stdenv.hostPlatform == stdenv.buildPlatform # (Advanced) SubStation Alpha subtitle rendering +, withBluray ? withFullDeps # BluRay reading +, withBs2b ? withFullDeps # bs2b DSP library +, withBzlib ? withHeadlessDeps +, withCaca ? withFullDeps # Textual display (ASCII art) +, withCelt ? withFullDeps # CELT decoder +, withCrystalhd ? withFullDeps +, withCuda ? withFullDeps && (with stdenv; (!isDarwin && !isAarch64)) +, withCudaLLVM ? withFullDeps +, withDav1d ? withHeadlessDeps # AV1 decoder (focused on speed and correctness) +, withDc1394 ? withFullDeps && !stdenv.isDarwin # IIDC-1394 grabbing (ieee 1394) +, withDrm ? withHeadlessDeps && (with stdenv; isLinux || isFreeBSD) # libdrm support +, withFdkAac ? withFullDeps && withUnfree # Fraunhofer FDK AAC de/encoder +, withFontconfig ? withHeadlessDeps # Needed for drawtext filter +, withFreetype ? withHeadlessDeps # Needed for drawtext filter +, withFrei0r ? withFullDeps # frei0r video filtering +, withFribidi ? withFullDeps # Needed for drawtext filter +, withGlslang ? withFullDeps && !stdenv.isDarwin +, withGme ? withFullDeps # Game Music Emulator +, withGnutls ? withHeadlessDeps +, withGsm ? withFullDeps # GSM de/encoder +, withIconv ? withHeadlessDeps +, withIlbc ? withFullDeps +, withJack ? withFullDeps && !stdenv.isDarwin # Jack audio +, withLadspa ? withFullDeps # LADSPA audio filtering +, withLzma ? withHeadlessDeps # xz-utils +, withMfx ? withFullDeps && (with stdenv.targetPlatform; isLinux && !isAarch) # Hardware acceleration via intel-media-sdk/libmfx +, withModplug ? withFullDeps && !stdenv.isDarwin # ModPlug support +, withMp3lame ? withHeadlessDeps # LAME MP3 encoder +, withMysofa ? withFullDeps # HRTF support via SOFAlizer +, withNvdec ? withHeadlessDeps && !stdenv.isDarwin && stdenv.hostPlatform == stdenv.buildPlatform +, withNvenc ? withHeadlessDeps && !stdenv.isDarwin && stdenv.hostPlatform == stdenv.buildPlatform +, withOgg ? withHeadlessDeps # Ogg container used by vorbis & theora +, withOpenal ? withFullDeps # OpenAL 1.1 capture support +, withOpencl ? withFullDeps +, withOpencoreAmrnb ? withFullDeps # AMR-NB de/encoder & AMR-WB decoder +, withOpengl ? false # OpenGL rendering +, withOpenh264 ? withFullDeps # H.264/AVC encoder +, withOpenjpeg ? withFullDeps # JPEG 2000 de/encoder +, withOpenmpt ? withFullDeps # Tracked music files decoder +, withOpus ? withHeadlessDeps # Opus de/encoder +, withPulse ? withSmallDeps && !stdenv.isDarwin # Pulseaudio input support +, withRav1e ? withFullDeps # AV1 encoder (focused on speed and safety) +, withRtmp ? false # RTMP[E] support +, withSamba ? withFullDeps && !stdenv.isDarwin # Samba protocol +, withSdl2 ? withSmallDeps +, withSoxr ? withHeadlessDeps # Resampling via soxr +, withSpeex ? withHeadlessDeps # Speex de/encoder +, withSrt ? withHeadlessDeps # Secure Reliable Transport (SRT) protocol +, withSsh ? withHeadlessDeps # SFTP protocol +, withSvg ? withFullDeps # SVG protocol +, withSvtav1 ? withFullDeps && !stdenv.isAarch64 # AV1 encoder/decoder (focused on speed and correctness) +, withTheora ? withHeadlessDeps # Theora encoder +, withV4l2 ? withFullDeps && !stdenv.isDarwin # Video 4 Linux support +, withV4l2M2m ? withV4l2 +, withVaapi ? withHeadlessDeps && (with stdenv; isLinux || isFreeBSD) # Vaapi hardware acceleration +, withVdpau ? withSmallDeps # Vdpau hardware acceleration +, withVidStab ? withFullDeps # Video stabilization +, withVmaf ? withFullDeps && withGPLv3 && !stdenv.isAarch64 # Netflix's VMAF (Video Multi-Method Assessment Fusion) +, withVoAmrwbenc ? withFullDeps # AMR-WB encoder +, withVorbis ? withHeadlessDeps # Vorbis de/encoding, native encoder exists +, withVpx ? withHeadlessDeps && stdenv.buildPlatform == stdenv.hostPlatform # VP8 & VP9 de/encoding +, withVulkan ? withFullDeps && !stdenv.isDarwin +, withWebp ? withFullDeps # WebP encoder +, withX264 ? withHeadlessDeps # H.264/AVC encoder +, withX265 ? withHeadlessDeps # H.265/HEVC encoder +, withXavs ? withFullDeps # AVS encoder +, withXcb ? withXcbShm || withXcbxfixes || withXcbShape # X11 grabbing using XCB +, withXcbShape ? withFullDeps # X11 grabbing shape rendering +, withXcbShm ? withFullDeps # X11 grabbing shm communication +, withXcbxfixes ? withFullDeps # X11 grabbing mouse rendering +, withXlib ? withFullDeps # Xlib support +, withXml2 ? withFullDeps # libxml2 support, for IMF and DASH demuxers +, withXvid ? withHeadlessDeps # Xvid encoder, native encoder exists +, withZimg ? withHeadlessDeps +, withZlib ? withHeadlessDeps +, withZmq ? withFullDeps # Message passing + +/* + * Licensing options (yes some are listed twice, filters and such are not listed) + */ +, withGPL ? true +, withGPLv3 ? true +, withUnfree ? false + +/* + * Build options + */ +, withSmallBuild ? false # Optimize for size instead of speed +, withRuntimeCPUDetection ? true # Detect CPU capabilities at runtime (disable to compile natively) +, withGrayscale ? withFullDeps # Full grayscale support +, withSwscaleAlpha ? buildSwscale # Alpha channel support in swscale. You probably want this when buildSwscale. +, withHardcodedTables ? withHeadlessDeps # Hardcode decode tables instead of runtime generation +, withSafeBitstreamReader ? withHeadlessDeps # Buffer boundary checking in bitreaders +, withMultithread ? true # Multithreading via pthreads/win32 threads +, withNetwork ? withHeadlessDeps # Network support +, withPixelutils ? withHeadlessDeps # Pixel utils in libavutil +, withLTO ? false # build with link-time optimization +/* + * Program options + */ +, buildFfmpeg ? withHeadlessDeps # Build ffmpeg executable +, buildFfplay ? withFullDeps # Build ffplay executable +, buildFfprobe ? withHeadlessDeps # Build ffprobe executable +, buildQtFaststart ? withFullDeps # Build qt-faststart executable +, withBin ? buildFfmpeg || buildFfplay || buildFfprobe || buildQtFaststart +/* + * Library options + */ +, buildAvcodec ? withHeadlessDeps # Build avcodec library +, buildAvdevice ? withHeadlessDeps # Build avdevice library +, buildAvfilter ? withHeadlessDeps # Build avfilter library +, buildAvformat ? withHeadlessDeps # Build avformat library +, buildAvutil ? withHeadlessDeps # Build avutil library +, buildPostproc ? withHeadlessDeps # Build postproc library +, buildSwresample ? withHeadlessDeps # Build swresample library +, buildSwscale ? withHeadlessDeps # Build swscale library +, withLib ? buildAvcodec + || buildAvdevice + || buildAvfilter + || buildAvformat + || buildAvutil + || buildPostproc + || buildSwresample + || buildSwscale +/* + * Documentation options + */ +, withDocumentation ? withHtmlDoc || withManPages || withPodDoc || withTxtDoc +, withHtmlDoc ? withHeadlessDeps # HTML documentation pages +, withManPages ? withHeadlessDeps # Man documentation pages +, withPodDoc ? withHeadlessDeps # POD documentation pages +, withTxtDoc ? withHeadlessDeps # Text documentation pages +# Whether a "doc" output will be produced. Note that withManPages does not produce +# a "doc" output because its files go to "man". +, withDoc ? withDocumentation && (withHtmlDoc || withPodDoc || withTxtDoc) + +/* + * Developer options + */ +, withDebug ? false +, withOptimisations ? true +, withExtraWarnings ? false +, withStripping ? false + +/* + * External libraries options + */ +, alsa-lib +, bzip2 +, clang +, celt +, dav1d +, fdk_aac +, fontconfig +, freetype +, frei0r +, fribidi +, game-music-emu +, gnutls +, gsm +, libjack2 +, ladspaH +, lame +, libass +, libaom +, libbluray +, libbs2b +, libcaca +, libdc1394 +, libraw1394 +, libdrm +, libiconv +, intel-media-sdk +, libmodplug +, libmysofa +, libogg +, libopenmpt +, libopus +, librsvg +, libssh +, libtheora +, libv4l +, libva +, libva-minimal +, libvdpau +, libvmaf +, libvorbis +, libvpx +, libwebp +, libX11 +, libxcb +, libXv +, libXext +, libxml2 +, xz +, nv-codec-headers +, openal +, ocl-icd # OpenCL ICD +, opencl-headers # OpenCL headers +, opencore-amr +, libGL +, libGLU +, openh264 +, openjpeg , libpulseaudio -, ... +, rav1e +, svt-av1 +, rtmpdump +, samba +, SDL2 +, soxr +, speex +, srt +, vid-stab +, vo-amrwbenc +, x264 +, x265 +, xavs +, xvidcore +, zeromq4 +, zimg +, zlib +, vulkan-loader +, glslang +/* + * Darwin frameworks + */ +, AVFoundation +, Cocoa +, CoreAudio +, CoreMedia +, CoreServices +, MediaToolbox +, VideoDecodeAcceleration +, VideoToolbox }: /* 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 + * Version bumps: + * It should always be safe to bump patch releases (e.g. 2.1.x, x being a patch release) + * If adding a new branch, note any configure flags that were added, changed, or deprecated/removed + * and make the necessary changes. * * 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) + * 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; - - reqMin = requiredVersion: (builtins.compareVersions requiredVersion branch != 1); - - ifMinVer = minVer: flag: if reqMin minVer then flag else null; - - ifVerOlder = maxVer: flag: if (lib.versionOlder branch maxVer) then flag else null; + inherit (stdenv) isCygwin isDarwin isFreeBSD isLinux isAarch64; + inherit (lib) optional optionals optionalString enableFeature; in + +assert lib.elem ffmpegVariant [ "headless" "small" "full" ]; + +/* + * Licensing dependencies + */ +assert withGPLv3 -> withGPL; +assert withUnfree -> withGPL && withGPLv3; +/* + * Build dependencies + */ +assert withPixelutils -> buildAvutil; +/* + * Program dependencies + */ +assert buildFfmpeg -> buildAvcodec + && buildAvfilter + && buildAvformat + && buildSwresample; +assert buildFfplay -> buildAvcodec + && buildAvformat + && buildSwscale + && buildSwresample; +assert buildFfprobe -> buildAvcodec && buildAvformat; +/* + * Library dependencies + */ +assert buildAvcodec -> buildAvutil; # configure flag since 0.6 +assert buildAvdevice -> buildAvformat + && buildAvcodec + && buildAvutil; # configure flag since 0.6 +assert buildAvformat -> buildAvcodec && buildAvutil; # configure flag since 0.6 +assert buildPostproc -> buildAvutil; +assert buildSwscale -> buildAvutil; + stdenv.mkDerivation rec { - pname = "ffmpeg"; + pname = "ffmpeg" + (if ffmpegVariant == "small" then "" else "-${ffmpegVariant}"); inherit version; - src = fetchurl { - url = "https://www.ffmpeg.org/releases/${pname}-${version}.tar.bz2"; + src = fetchgit { + url = "https://git.ffmpeg.org/ffmpeg.git"; + rev = "n${version}"; inherit sha256; }; - postPatch = "patchShebangs ."; - inherit patches; + postPatch = '' + patchShebangs . + '' + lib.optionalString withFrei0r '' + substituteInPlace libavfilter/vf_frei0r.c \ + --replace /usr/local/lib/frei0r-1 ${frei0r}/lib/frei0r-1 + substituteInPlace doc/filters.texi \ + --replace /usr/local/lib/frei0r-1 ${frei0r}/lib/frei0r-1 + ''; - outputs = [ "bin" "dev" "out" "man" "doc" ]; - setOutputFlags = false; # doesn't accept all and stores configureFlags in libs! + patches = map (patch: fetchpatch patch) extraPatches; configurePlatforms = []; - 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" - "--enable-pic" - (ifMinVer "4.0" (enableFeature srtSupport "libsrt")) - (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"]) - ++ [ - "--disable-os2threads" # We don't support OS/2 - "--enable-network" - "--enable-pixelutils" - # Executables - "--enable-ffmpeg" - "--disable-ffplay" - "--enable-ffprobe" - (ifVerOlder "4" "--disable-ffserver") - # Libraries - "--enable-avcodec" - "--enable-avdevice" - "--enable-avfilter" - "--enable-avformat" - (ifVerOlder "5.0" "--enable-avresample") - "--enable-avutil" - "--enable-postproc" - "--enable-swresample" - "--enable-swscale" - # Docs - "--disable-doc" - # External Libraries - "--enable-libass" - "--enable-bzlib" - "--enable-gnutls" - "--enable-fontconfig" - "--enable-libfreetype" - "--enable-libmp3lame" - "--enable-iconv" - "--enable-libtheora" - "--enable-libssh" - (enableFeature vaapiSupport "vaapi") - (enableFeature vaapiSupport "libdrm") - (enableFeature vdpauSupport "vdpau") - "--enable-libvorbis" - (enableFeature vpxSupport "libvpx") - "--enable-lzma" - (enableFeature openglSupport "opengl") - (ifMinVer "4.2" (enableFeature libmfxSupport "libmfx")) - (ifMinVer "4.2" (enableFeature libaomSupport "libaom")) - (lib.optionalString pulseaudioSupport "--enable-libpulse") - (enableFeature sdlSupport "sdl2") - "--enable-libsoxr" - "--enable-libx264" - "--enable-libxvid" - "--enable-libzimg" - "--enable-zlib" - "--enable-libopus" - "--enable-libspeex" - "--enable-libx265" - (ifMinVer "4.2" (enableFeature (reqMin "4.2") "libdav1d")) - # Developer flags - (enableFeature debugDeveloper "debug") - (enableFeature optimizationsDeveloper "optimizations") - (enableFeature extraWarningsDeveloper "extra-warnings") - "--disable-stripping" + setOutputFlags = false; # Only accepts some of them + configureFlags = [ + #mingw64 is internally treated as mingw32, so 32 and 64 make no difference here + "--target_os=${if stdenv.hostPlatform.isMinGW then "mingw64" else stdenv.hostPlatform.parsed.kernel.name}" + "--arch=${stdenv.hostPlatform.parsed.cpu.name}" + "--pkg-config=${buildPackages.pkg-config.targetPrefix}pkg-config" + /* + * Licensing flags + */ + (enableFeature withGPL "gpl") + (enableFeature withGPLv3 "version3") + (enableFeature withUnfree "nonfree") + /* + * Build flags + */ + # On some ARM platforms --enable-thumb + "--enable-shared" + "--enable-pic" + + (enableFeature withSmallBuild "small") + (enableFeature withRuntimeCPUDetection "runtime-cpudetect") + (enableFeature withLTO "lto") + (enableFeature withGrayscale "gray") + (enableFeature withSwscaleAlpha "swscale-alpha") + (enableFeature withHardcodedTables "hardcoded-tables") + (enableFeature withSafeBitstreamReader "safe-bitstream-reader") + + (enableFeature (withMultithread && stdenv.targetPlatform.isUnix) "pthreads") + (enableFeature (withMultithread && stdenv.targetPlatform.isWindows) "w32threads") + "--disable-os2threads" # We don't support OS/2 + + (enableFeature withNetwork "network") + (enableFeature withPixelutils "pixelutils") + + "--datadir=${placeholder "data"}/share/ffmpeg" + + /* + * Program flags + */ + (enableFeature buildFfmpeg "ffmpeg") + (enableFeature buildFfplay "ffplay") + (enableFeature buildFfprobe "ffprobe") + ] ++ optionals withBin [ + "--bindir=${placeholder "bin"}/bin" + ] ++ [ + /* + * Library flags + */ + (enableFeature buildAvcodec "avcodec") + (enableFeature buildAvdevice "avdevice") + (enableFeature buildAvfilter "avfilter") + (enableFeature buildAvformat "avformat") + (enableFeature buildAvutil "avutil") + (enableFeature (buildPostproc && withGPL) "postproc") + (enableFeature buildSwresample "swresample") + (enableFeature buildSwscale "swscale") + ] ++ optionals withLib [ + "--libdir=${placeholder "lib"}/lib" + "--incdir=${placeholder "dev"}/include" + ] ++ [ + /* + * Documentation flags + */ + (enableFeature withDocumentation "doc") + (enableFeature withHtmlDoc "htmlpages") + (enableFeature withManPages "manpages") + ] ++ optionals withManPages [ + "--mandir=${placeholder "man"}/share/man" + ] ++ [ + (enableFeature withPodDoc "podpages") + (enableFeature withTxtDoc "txtpages") + ] ++ optionals withDoc [ + "--docdir=${placeholder "doc"}/share/doc/ffmpeg" + ] ++ [ + /* + * External libraries + */ + (enableFeature withAlsa "alsa") + (enableFeature withBzlib "bzlib") + (enableFeature withCelt "libcelt") + (enableFeature withCuda "cuda") + (enableFeature withCudaLLVM "cuda-llvm") + (enableFeature withDav1d "libdav1d") + (enableFeature withFdkAac "libfdk-aac") + "--disable-libflite" # Force disable until a solution is found + (enableFeature withFontconfig "fontconfig") + (enableFeature withFreetype "libfreetype") + (enableFeature withFrei0r "frei0r") + (enableFeature withFribidi "libfribidi") + (enableFeature withGme "libgme") + (enableFeature withGnutls "gnutls") + (enableFeature withGsm "libgsm") + (enableFeature withLadspa "ladspa") + (enableFeature withMp3lame "libmp3lame") + (enableFeature withAom "libaom") + (enableFeature withAss "libass") + (enableFeature withBluray "libbluray") + (enableFeature withBs2b "libbs2b") + (enableFeature withDc1394 "libdc1394") + (enableFeature withDrm "libdrm") + (enableFeature withIconv "iconv") + (enableFeature withJack "libjack") + (enableFeature withMfx "libmfx") + (enableFeature withModplug "libmodplug") + (enableFeature withMysofa "libmysofa") + (enableFeature withOpus "libopus") + (enableFeature withSvg "librsvg") + (enableFeature withSrt "libsrt") + (enableFeature withSsh "libssh") + (enableFeature withTheora "libtheora") + (enableFeature withV4l2 "libv4l2") + (enableFeature withV4l2M2m "v4l2-m2m") + (enableFeature withVaapi "vaapi") + (enableFeature withVdpau "vdpau") + (enableFeature withVorbis "libvorbis") + (enableFeature withVmaf "libvmaf") + (enableFeature withVpx "libvpx") + (enableFeature withWebp "libwebp") + (enableFeature withXlib "xlib") + (enableFeature withXcb "libxcb") + (enableFeature withXcbShm "libxcb-shm") + (enableFeature withXcbxfixes "libxcb-xfixes") + (enableFeature withXcbShape "libxcb-shape") + (enableFeature withXml2 "libxml2") + (enableFeature withLzma "lzma") + (enableFeature withNvdec "cuvid") + (enableFeature withNvdec "nvdec") + (enableFeature withNvenc "nvenc") + (enableFeature withOpenal "openal") + (enableFeature withOpencl "opencl") + (enableFeature withOpencoreAmrnb "libopencore-amrnb") + (enableFeature withOpengl "opengl") + (enableFeature withOpenh264 "libopenh264") + (enableFeature withOpenjpeg "libopenjpeg") + (enableFeature withOpenmpt "libopenmpt") + (enableFeature withPulse "libpulse") + (enableFeature withRav1e "librav1e") + (enableFeature withSvtav1 "libsvtav1") + (enableFeature withRtmp "librtmp") + (enableFeature withSdl2 "sdl2") + (enableFeature withSoxr "libsoxr") + (enableFeature withSpeex "libspeex") + (enableFeature withVidStab "libvidstab") # Actual min. version 2.0 + (enableFeature withVoAmrwbenc "libvo-amrwbenc") + (enableFeature withX264 "libx264") + (enableFeature withX265 "libx265") + (enableFeature withXavs "libxavs") + (enableFeature withXvid "libxvid") + (enableFeature withZmq "libzmq") + (enableFeature withZimg "libzimg") + (enableFeature withZlib "zlib") + (enableFeature withVulkan "vulkan") + (enableFeature withGlslang "libglslang") + (enableFeature withSamba "libsmbclient") + /* + * Developer flags + */ + (enableFeature withDebug "debug") + (enableFeature withOptimisations "optimizations") + (enableFeature withExtraWarnings "extra-warnings") + (enableFeature withStripping "stripping") ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ - "--cross-prefix=${stdenv.cc.targetPrefix}" - "--enable-cross-compile" - ] ++ optional stdenv.cc.isClang "--cc=clang"); + "--cross-prefix=${stdenv.cc.targetPrefix}" + "--enable-cross-compile" + "--host-cc=${buildPackages.stdenv.cc}/bin/cc" + ] ++ optionals stdenv.cc.isClang [ + "--cc=clang" + "--cxx=clang++" + ]; - depsBuildBuild = [ buildPackages.stdenv.cc ]; - nativeBuildInputs = [ addOpenGLRunpath perl pkg-config texinfo yasm ]; + # ffmpeg embeds the configureFlags verbatim in its binaries and because we + # configure binary, include, library dir etc., this causes references in + # outputs where we don't want them. Patch the generated config.h to remove all + # such references except for data. + postConfigure = let + toStrip = lib.remove "data" outputs; # We want to keep references to the data dir. + in + "remove-references-to ${lib.concatStringsSep " " (map (o: "-t ${placeholder o}") toStrip)} config.h"; - buildInputs = [ - bzip2 fontconfig freetype gnutls libiconv lame libass libogg libssh libtheora - libvorbis xz soxr x264 x265 xvidcore zimg zlib libopus speex nv-codec-headers - ] ++ optionals openglSupport [ libGL libGLU ] - ++ optional libmfxSupport intel-media-sdk - ++ optional libaomSupport libaom - ++ 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 ] - ++ optional vdpauSupport libvdpau - ++ optional sdlSupport SDL2 - ++ optional srtSupport srt - ++ optional (reqMin "4.2") dav1d; + nativeBuildInputs = [ removeReferencesTo addOpenGLRunpath perl pkg-config texinfo yasm ]; - enableParallelBuilding = true; + # TODO This was always in buildInputs before, why? + buildInputs = optionals withFullDeps [ libdc1394 ] + ++ optionals (withFullDeps && !stdenv.isDarwin) [ libraw1394 ] # TODO where does this belong to + ++ optionals (withNvdec || withNvenc) [ nv-codec-headers ] + ++ optionals withAlsa [ alsa-lib ] + ++ optionals withAom [ libaom ] + ++ optionals withAss [ libass ] + ++ optionals withBluray [ libbluray ] + ++ optionals withBs2b [ libbs2b ] + ++ optionals withBzlib [ bzip2 ] + ++ optionals withCaca [ libcaca ] + ++ optionals withCelt [ celt ] + ++ optionals withCudaLLVM [ clang ] + ++ optionals withDav1d [ dav1d ] + ++ optionals withDrm [ libdrm ] + ++ optionals withFdkAac [ fdk_aac ] + ++ optionals withFontconfig [ fontconfig ] + ++ optionals withFreetype [ freetype ] + ++ optionals withFrei0r [ frei0r ] + ++ optionals withFribidi [ fribidi ] + ++ optionals withGlslang [ glslang ] + ++ optionals withGme [ game-music-emu ] + ++ optionals withGnutls [ gnutls ] + ++ optionals withGsm [ gsm ] + ++ optionals withIconv [ libiconv ] # On Linux this should be in libc, do we really need it? + ++ optionals withJack [ libjack2 ] + ++ optionals withLadspa [ ladspaH ] + ++ optionals withLzma [ xz ] + ++ optionals withMfx [ intel-media-sdk ] + ++ optionals withModplug [ libmodplug ] + ++ optionals withMp3lame [ lame ] + ++ optionals withMysofa [ libmysofa ] + ++ optionals withOgg [ libogg ] + ++ optionals withOpenal [ openal ] + ++ optionals withOpencl [ ocl-icd opencl-headers ] + ++ optionals withOpencoreAmrnb [ opencore-amr ] + ++ optionals withOpengl [ libGL libGLU ] + ++ optionals withOpenh264 [ openh264 ] + ++ optionals withOpenjpeg [ openjpeg ] + ++ optionals withOpenmpt [ libopenmpt ] + ++ optionals withOpus [ libopus ] + ++ optionals withPulse [ libpulseaudio ] + ++ optionals withRav1e [ rav1e ] + ++ optionals withRtmp [ rtmpdump ] + ++ optionals withSamba [ samba ] + ++ optionals withSdl2 [ SDL2 ] + ++ optionals withSoxr [ soxr ] + ++ optionals withSpeex [ speex ] + ++ optionals withSrt [ srt ] + ++ optionals withSsh [ libssh ] + ++ optionals withSvg [ librsvg ] + ++ optionals withSvtav1 [ svt-av1 ] + ++ optionals withTheora [ libtheora ] + ++ optionals withVaapi [ (if withSmallDeps then libva else libva-minimal) ] + ++ optionals withVdpau [ libvdpau ] + ++ optionals withVidStab [ vid-stab ] + ++ optionals withVmaf [ libvmaf ] + ++ optionals withVoAmrwbenc [ vo-amrwbenc ] + ++ optionals withVorbis [ libvorbis ] + ++ optionals withVpx [ libvpx ] + ++ optionals withV4l2 [ libv4l ] + ++ optionals withVulkan [ vulkan-loader ] + ++ optionals withWebp [ libwebp ] + ++ optionals withX264 [ x264 ] + ++ optionals withX265 [ x265 ] + ++ optionals withXavs [ xavs ] + ++ optionals withXcb [ libxcb ] + ++ optionals withXlib [ libX11 libXv libXext ] + ++ optionals withXml2 [ libxml2 ] + ++ optionals withXvid [ xvidcore ] + ++ optionals withZimg [ zimg ] + ++ optionals withZlib [ zlib ] + ++ optionals withZmq [ zeromq4 ] + ++ optionals stdenv.isDarwin [ + # TODO fine-grained flags + AVFoundation + Cocoa + CoreAudio + CoreMedia + CoreServices + MediaToolbox + VideoDecodeAcceleration + VideoToolbox + ]; - inherit doCheck; + buildFlags = [ "all" ] + ++ optional buildQtFaststart "tools/qt-faststart"; # Build qt-faststart executable + + doCheck = stdenv.hostPlatform == stdenv.buildPlatform; + + # Fails with SIGABRT otherwise 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}}" \ + ${ldLibraryPathEnv}="libavcodec:libavdevice:libavfilter:libavformat:libavutil:libpostproc${ + optionalString (withHeadlessDeps) ":libswresample" # TODO this can probably go away + }: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. + outputs = optionals withBin [ "bin" ] # The first output is the one that gets symlinked by default! + ++ optionals withLib [ "lib" "dev" ] + ++ optionals withDoc [ "doc" ] + ++ optionals withManPages [ "man" ] + ++ [ "data" "out" ] # We need an "out" output because we get an error otherwise. It's just an empty dir. + ; + + postInstall = optionalString buildQtFaststart '' + install -D tools/qt-faststart -t $bin/bin + ''; + + # Set RUNPATH so that libnvcuvid and libcuda in /run/opengl-driver(-32)/lib can be found. + # See the explanation in addOpenGLRunpath. + postFixup = optionalString stdenv.isLinux '' addOpenGLRunpath $out/lib/libavcodec.so addOpenGLRunpath $out/lib/libavutil.so ''; - installFlags = [ "install-man" ]; - - passthru = { - inherit vaapiSupport vdpauSupport; - }; + enableParallelBuilding = true; meta = with lib; { description = "A complete, cross-platform solution to record, convert and stream audio and video"; @@ -212,9 +652,11 @@ stdenv.mkDerivation rec { No matter if they were designed by some standards committee, the community or a corporation. ''; - license = licenses.gpl3; - maintainers = with maintainers; [ ]; + license = with licenses; [ lgpl21Plus ] + ++ optional withGPL gpl2Plus + ++ optional withGPLv3 gpl3Plus + ++ optional withUnfree unfreeRedistributable; platforms = platforms.all; - inherit branch knownVulnerabilities; + maintainers = with maintainers; [ atemu ]; }; } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 75ded916919d..7b3f57d5333f 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -19365,30 +19365,28 @@ with pkgs; linbox = callPackage ../development/libraries/linbox { }; - ffmpeg_4-headless = callPackage ../development/libraries/ffmpeg/4.nix { - inherit (darwin.apple_sdk.frameworks) Cocoa CoreMedia VideoToolbox; - - sdlSupport = false; - vdpauSupport = false; - pulseaudioSupport = false; - libva = libva-minimal; - }; - ffmpeg_4 = callPackage ../development/libraries/ffmpeg/4.nix { - inherit (darwin.apple_sdk.frameworks) Cocoa CoreMedia VideoToolbox; + inherit (darwin.apple_sdk.frameworks) + Cocoa CoreServices CoreAudio CoreMedia AVFoundation MediaToolbox + VideoDecodeAcceleration VideoToolbox; }; - - ffmpeg_5-headless = callPackage ../development/libraries/ffmpeg/5.nix { - inherit (darwin.apple_sdk.frameworks) Cocoa CoreMedia VideoToolbox; - - sdlSupport = false; - vdpauSupport = false; - pulseaudioSupport = false; - libva = libva-minimal; + ffmpeg_4-headless = ffmpeg_4.override { + ffmpegVariant = "headless"; + }; + ffmpeg_4-full = ffmpeg.override { + ffmpegVariant = "full"; }; ffmpeg_5 = callPackage ../development/libraries/ffmpeg/5.nix { - inherit (darwin.apple_sdk.frameworks) Cocoa CoreMedia VideoToolbox; + inherit (darwin.apple_sdk.frameworks) + Cocoa CoreServices CoreAudio CoreMedia AVFoundation MediaToolbox + VideoDecodeAcceleration VideoToolbox; + }; + ffmpeg_5-headless = ffmpeg_5.override { + ffmpegVariant = "headless"; + }; + ffmpeg_5-full = ffmpeg_5.override { + ffmpegVariant = "full"; }; # Aliases @@ -19397,26 +19395,8 @@ with pkgs; # Packages which use ffmpeg as a library, should pin to the relevant major # version number which the upstream support. ffmpeg = ffmpeg_4; - ffmpeg-headless = ffmpeg_4-headless; - - ffmpeg-full = callPackage ../development/libraries/ffmpeg-full { - svt-av1 = if stdenv.isAarch64 then null else svt-av1; - rtmpdump = null; # Prefer the built-in RTMP implementation - # The following need to be fixed on Darwin - libjack2 = if stdenv.isDarwin then null else libjack2; - libmodplug = if stdenv.isDarwin then null else libmodplug; - libmfx = if stdenv.isDarwin then null else intel-media-sdk; - libpulseaudio = if stdenv.isDarwin then null else libpulseaudio; - samba = if stdenv.isDarwin then null else samba; - inherit (darwin.apple_sdk.frameworks) - Cocoa CoreServices CoreAudio AVFoundation MediaToolbox - VideoDecodeAcceleration VideoToolbox; - }; - - ffmpeg_5-full = ffmpeg-full.override { - ffmpeg = ffmpeg_5; - }; + ffmpeg-full = ffmpeg_4-full; ffmpegthumbnailer = callPackage ../development/libraries/ffmpegthumbnailer { };