nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at 22.05 245 lines 9.7 kB view raw
1{ lib, stdenv, buildPackages, fetchurl, pkg-config, addOpenGLRunpath, perl, texinfo, yasm 2, alsa-lib, bzip2, fontconfig, freetype, gnutls, libiconv, lame, libass, libogg 3, libssh, libtheora, libva, libdrm, libvorbis, libvpx, xz, soxr 4, x264, x265, xvidcore, zimg, zlib, libopus, speex, nv-codec-headers, dav1d 5, srt ? null 6, openglSupport ? false, libGLU ? null, libGL ? null 7, libmfxSupport ? false, intel-media-sdk ? null 8, libaomSupport ? false, libaom ? null 9# Build options 10, runtimeCpuDetectBuild ? true # Detect CPU capabilities at runtime 11, multithreadBuild ? true # Multithreading via pthreads/win32 threads 12, sdlSupport ? !stdenv.isAarch32, SDL ? null, SDL2 ? null 13, vdpauSupport ? !stdenv.isAarch32, libvdpau ? null 14# Developer options 15, debugDeveloper ? false 16, optimizationsDeveloper ? true 17, extraWarningsDeveloper ? false 18# Darwin frameworks 19, Cocoa, darwinFrameworks ? [ Cocoa ] 20# Inherit generics 21, branch, sha256, version, patches ? [], knownVulnerabilities ? [] 22, doCheck ? true 23, pulseaudioSupport ? stdenv.isLinux 24, libpulseaudio 25, ... 26}: 27 28/* Maintainer notes: 29 * 30 * THIS IS A MINIMAL BUILD OF FFMPEG, do not include dependencies unless 31 * a build that depends on ffmpeg requires them to be compiled into ffmpeg, 32 * see `ffmpeg-full' for an ffmpeg build with all features included. 33 * 34 * Need fixes to support Darwin: 35 * pulseaudio 36 * 37 * Known issues: 38 * 0.6 - fails to compile (unresolved) (so far, only disabling a number of 39 * features works, but that is not a feasible solution) 40 * 0.6.90 - mmx: compile errors (fix: disable for 0.6.90-rc0) 41 * 1.1 - libsoxr: compile error (fix: disable for 1.1) 42 * Support was initially added in 1.1 before soxr api change, fix 43 * would probably be to add soxr-1.0 44 * ALL - Cross-compiling will disable features not present on host OS 45 * (e.g. dxva2 support [DirectX] will not be enabled unless natively 46 * compiled on Cygwin) 47 * 48 */ 49 50let 51 inherit (stdenv) isDarwin isFreeBSD isLinux isAarch32; 52 inherit (lib) optional optionals optionalString enableFeature filter; 53 54 cmpVer = builtins.compareVersions; 55 reqMin = requiredVersion: (cmpVer requiredVersion branch != 1); 56 reqMatch = requiredVersion: (cmpVer requiredVersion branch == 0); 57 58 ifMinVer = minVer: flag: if reqMin minVer then flag else null; 59 60 ifVerOlder = maxVer: flag: if (lib.versionOlder branch maxVer) then flag else null; 61 62 # Version specific fix 63 verFix = withoutFix: fixVer: withFix: if reqMatch fixVer then withFix else withoutFix; 64 65 # Disable dependency that needs fixes before it will work on Darwin or Arm 66 disDarwinOrArmFix = origArg: minVer: fixArg: if ((isDarwin || isAarch32) && reqMin minVer) then fixArg else origArg; 67 68 vaapiSupport = reqMin "0.6" && ((isLinux || isFreeBSD) && !isAarch32); 69 70 vpxSupport = reqMin "0.6" && !isAarch32; 71in 72 73assert openglSupport -> libGL != null && libGLU != null; 74assert libmfxSupport -> intel-media-sdk != null; 75assert libaomSupport -> libaom != null; 76 77stdenv.mkDerivation rec { 78 79 pname = "ffmpeg"; 80 inherit version; 81 82 src = fetchurl { 83 url = "https://www.ffmpeg.org/releases/${pname}-${version}.tar.bz2"; 84 inherit sha256; 85 }; 86 87 postPatch = "patchShebangs ."; 88 inherit patches; 89 90 outputs = [ "bin" "dev" "out" "man" ] 91 ++ optional (reqMin "1.0") "doc" ; # just dev-doc 92 setOutputFlags = false; # doesn't accept all and stores configureFlags in libs! 93 94 configurePlatforms = []; 95 configureFlags = filter (v: v != null) ([ 96 "--arch=${stdenv.hostPlatform.parsed.cpu.name}" 97 "--target_os=${stdenv.hostPlatform.parsed.kernel.name}" 98 # License 99 "--enable-gpl" 100 "--enable-version3" 101 # Build flags 102 "--enable-shared" 103 (ifMinVer "0.6" "--enable-pic") 104 (ifMinVer "4.0" (enableFeature (srt != null) "libsrt")) 105 (enableFeature runtimeCpuDetectBuild "runtime-cpudetect") 106 "--enable-hardcoded-tables" 107 ] ++ 108 (if multithreadBuild then ( 109 if stdenv.isCygwin then 110 ["--disable-pthreads" "--enable-w32threads"] 111 else # Use POSIX threads by default 112 ["--enable-pthreads" "--disable-w32threads"]) 113 else 114 ["--disable-pthreads" "--disable-w32threads"]) 115 ++ [ 116 (ifMinVer "0.9" "--disable-os2threads") # We don't support OS/2 117 "--enable-network" 118 (ifMinVer "2.4" "--enable-pixelutils") 119 # Executables 120 "--enable-ffmpeg" 121 "--disable-ffplay" 122 (ifMinVer "0.6" "--enable-ffprobe") 123 (if reqMin "4" then null else "--disable-ffserver") 124 # Libraries 125 (ifMinVer "0.6" "--enable-avcodec") 126 (ifMinVer "0.6" "--enable-avdevice") 127 "--enable-avfilter" 128 (ifMinVer "0.6" "--enable-avformat") 129 (ifMinVer "1.0" (ifVerOlder "5.0" "--enable-avresample")) 130 (ifMinVer "1.1" "--enable-avutil") 131 "--enable-postproc" 132 (ifMinVer "0.9" "--enable-swresample") 133 "--enable-swscale" 134 # Docs 135 (ifMinVer "0.6" "--disable-doc") 136 # External Libraries 137 "--enable-libass" 138 "--enable-bzlib" 139 "--enable-gnutls" 140 (ifMinVer "1.0" "--enable-fontconfig") 141 (ifMinVer "0.7" "--enable-libfreetype") 142 "--enable-libmp3lame" 143 (ifMinVer "1.2" "--enable-iconv") 144 "--enable-libtheora" 145 (ifMinVer "2.1" "--enable-libssh") 146 (ifMinVer "0.6" (enableFeature vaapiSupport "vaapi")) 147 (ifMinVer "3.4" (enableFeature vaapiSupport "libdrm")) 148 (enableFeature vdpauSupport "vdpau") 149 "--enable-libvorbis" 150 (ifMinVer "0.6" (enableFeature vpxSupport "libvpx")) 151 (ifMinVer "2.4" "--enable-lzma") 152 (ifMinVer "2.2" (enableFeature openglSupport "opengl")) 153 (ifMinVer "4.2" (enableFeature libmfxSupport "libmfx")) 154 (ifMinVer "4.2" (enableFeature libaomSupport "libaom")) 155 (disDarwinOrArmFix (ifMinVer "0.9" (lib.optionalString pulseaudioSupport "--enable-libpulse")) "0.9" "--disable-libpulse") 156 (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 157 (ifMinVer "1.2" "--enable-libsoxr") 158 "--enable-libx264" 159 "--enable-libxvid" 160 "--enable-libzimg" 161 "--enable-zlib" 162 (ifMinVer "2.8" "--enable-libopus") 163 "--enable-libspeex" 164 (ifMinVer "2.8" "--enable-libx265") 165 (ifMinVer "4.2" (enableFeature (dav1d != null) "libdav1d")) 166 # Developer flags 167 (enableFeature debugDeveloper "debug") 168 (enableFeature optimizationsDeveloper "optimizations") 169 (enableFeature extraWarningsDeveloper "extra-warnings") 170 "--disable-stripping" 171 # Disable mmx support for 0.6.90 172 (verFix null "0.6.90" "--disable-mmx") 173 ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ 174 "--cross-prefix=${stdenv.cc.targetPrefix}" 175 "--enable-cross-compile" 176 ] ++ optional stdenv.cc.isClang "--cc=clang"); 177 178 depsBuildBuild = [ buildPackages.stdenv.cc ]; 179 nativeBuildInputs = [ addOpenGLRunpath perl pkg-config texinfo yasm ]; 180 181 buildInputs = [ 182 bzip2 fontconfig freetype gnutls libiconv lame libass libogg libssh libtheora 183 libvorbis xz soxr x264 x265 xvidcore zimg zlib libopus speex srt nv-codec-headers 184 ] ++ optionals openglSupport [ libGL libGLU ] 185 ++ optional libmfxSupport intel-media-sdk 186 ++ optional libaomSupport libaom 187 ++ optional vpxSupport libvpx 188 ++ optionals (!isDarwin && !isAarch32 && pulseaudioSupport) [ libpulseaudio ] # Need to be fixed on Darwin and ARM 189 ++ optional ((isLinux || isFreeBSD) && !isAarch32) libva 190 ++ optional ((isLinux || isFreeBSD) && !isAarch32) libdrm 191 ++ optional isLinux alsa-lib 192 ++ optionals isDarwin darwinFrameworks 193 ++ optional vdpauSupport libvdpau 194 ++ optional sdlSupport (if reqMin "3.2" then SDL2 else SDL) 195 ++ optional (reqMin "4.2") dav1d; 196 197 enableParallelBuilding = true; 198 199 inherit doCheck; 200 checkPhase = let 201 ldLibraryPathEnv = if stdenv.isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH"; 202 in '' 203 ${ldLibraryPathEnv}="libavcodec:libavdevice:libavfilter:libavformat:libavresample:libavutil:libpostproc:libswresample:libswscale:''${${ldLibraryPathEnv}}" \ 204 make check -j$NIX_BUILD_CORES 205 ''; 206 207 # ffmpeg 3+ generates pkg-config (.pc) files that don't have the 208 # form automatically handled by the multiple-outputs hooks. 209 postFixup = '' 210 moveToOutput bin "$bin" 211 moveToOutput share/ffmpeg/examples "$doc" 212 for pc in ''${!outputDev}/lib/pkgconfig/*.pc; do 213 substituteInPlace $pc \ 214 --replace "includedir=$out" "includedir=''${!outputInclude}" 215 done 216 '' + optionalString stdenv.isLinux '' 217 # Set RUNPATH so that libnvcuvid and libcuda in /run/opengl-driver(-32)/lib can be found. 218 # See the explanation in addOpenGLRunpath. 219 addOpenGLRunpath $out/lib/libavcodec.so 220 addOpenGLRunpath $out/lib/libavutil.so 221 ''; 222 223 installFlags = [ "install-man" ]; 224 225 passthru = { 226 inherit vaapiSupport vdpauSupport; 227 }; 228 229 meta = with lib; { 230 description = "A complete, cross-platform solution to record, convert and stream audio and video"; 231 homepage = "https://www.ffmpeg.org/"; 232 changelog = "https://github.com/FFmpeg/FFmpeg/blob/n${version}/Changelog"; 233 longDescription = '' 234 FFmpeg is the leading multimedia framework, able to decode, encode, transcode, 235 mux, demux, stream, filter and play pretty much anything that humans and machines 236 have created. It supports the most obscure ancient formats up to the cutting edge. 237 No matter if they were designed by some standards committee, the community or 238 a corporation. 239 ''; 240 license = licenses.gpl3; 241 platforms = platforms.all; 242 maintainers = with maintainers; [ codyopel ]; 243 inherit branch knownVulnerabilities; 244 }; 245}