1 { lib, stdenv, fetchFromGitHub, perl, yasm
2 , vp8DecoderSupport ? true # VP8 decoder
3 , vp8EncoderSupport ? true # VP8 encoder
4 , vp9DecoderSupport ? true # VP9 decoder
5 , vp9EncoderSupport ? true # VP9 encoder
6 , extraWarningsSupport ? false # emit non-fatal warnings
7 , werrorSupport ? false # treat warnings as errors (not available with all compilers)
8 , debugSupport ? false # debug mode
9 , gprofSupport ? false # gprof profiling instrumentation
10 , gcovSupport ? false # gcov coverage instrumentation
11 , sizeLimitSupport ? true # limit max size to allow in the decoder
12 , optimizationsSupport ? true # compiler optimization flags
13 , runtimeCpuDetectSupport ? true # detect cpu capabilities at runtime
14 , thumbSupport ? false # build arm assembly in thumb mode
15 , examplesSupport ? true # build examples (vpxdec & vpxenc are part of examples)
16 , debugLibsSupport ? false # include debug version of each library
17 , postprocSupport ? true # postprocessing
18 , multithreadSupport ? true # multithreaded decoding & encoding
19 , internalStatsSupport ? false # output of encoder internal stats for debug, if supported (encoders)
20 , spatialResamplingSupport ? true # spatial sampling (scaling)
21 , realtimeOnlySupport ? false # build for real-time encoding
22 , ontheflyBitpackingSupport ? false # on-the-fly bitpacking in real-time encoding
23 , errorConcealmentSupport ? false # decoder conceals losses
24 , smallSupport ? false # favor smaller binary over speed
25 , postprocVisualizerSupport ? false # macro block/block level visualizers
26 , unitTestsSupport ? false, curl ? null, coreutils ? null # unit tests
27 , webmIOSupport ? true # input from and output to webm container
28 , libyuvSupport ? true # libyuv
29 , decodePerfTestsSupport ? false # build decoder perf tests with unit tests
30 , encodePerfTestsSupport ? false # build encoder perf tests with unit tests
31 , multiResEncodingSupport ? false # multiple-resolution encoding
32 , temporalDenoisingSupport ? true # use temporal denoising instead of spatial denoising
33 , coefficientRangeCheckingSupport ? false # decoder checks if intermediate transform coefficients are in valid range
34 , vp9HighbitdepthSupport ? true # 10/12 bit color support in VP9
35 # Experimental features
36 , experimentalSpatialSvcSupport ? false # Spatial scalable video coding
37 , experimentalFpMbStatsSupport ? false
38 , experimentalEmulateHardwareSupport ? false
42 inherit (stdenv) is64bit isMips isDarwin isCygwin;
43 inherit (lib) enableFeature optional optionals;
46 assert vp8DecoderSupport || vp8EncoderSupport || vp9DecoderSupport || vp9EncoderSupport;
47 assert internalStatsSupport && (vp9DecoderSupport || vp9EncoderSupport) -> postprocSupport;
48 /* If spatialResamplingSupport not enabled, build will fail with undeclared variable errors.
49 Variables called in vpx_scale/generic/vpx_scale.c are declared by vpx_scale/vpx_scale_rtcd.pl,
50 but is only executed if spatialResamplingSupport is enabled */
51 assert spatialResamplingSupport;
52 assert postprocVisualizerSupport -> postprocSupport;
53 assert unitTestsSupport -> curl != null && coreutils != null;
54 assert vp9HighbitdepthSupport -> (vp9DecoderSupport || vp9EncoderSupport);
55 assert isCygwin -> unitTestsSupport && webmIOSupport && libyuvSupport;
57 stdenv.mkDerivation rec {
61 src = fetchFromGitHub {
62 owner = "webmproject";
65 sha256 = "sha256-9SFFE2GfYYMgxp1dpmL3STTU2ea1R5vFKA1L0pZwIvQ=";
69 patchShebangs --build \
76 # When cross-compiling (for aarch64-multiplatform), the compiler errors out on these flags.
77 # Since they're 'just' warnings, it's fine to just remove them.
78 substituteInPlace configure \
79 --replace "check_add_cflags -Wparentheses-equality" "" \
80 --replace "check_add_cflags -Wunreachable-code-loop-increment" "" \
81 --replace "check_cflags -Wshorten-64-to-32 && add_cflags_only -Wshorten-64-to-32" ""
84 outputs = [ "bin" "dev" "out" ];
85 setOutputFlags = false;
87 configurePlatforms = [];
89 (enableFeature (vp8EncoderSupport || vp8DecoderSupport) "vp8")
90 (enableFeature vp8EncoderSupport "vp8-encoder")
91 (enableFeature vp8DecoderSupport "vp8-decoder")
92 (enableFeature (vp9EncoderSupport || vp9DecoderSupport) "vp9")
93 (enableFeature vp9EncoderSupport "vp9-encoder")
94 (enableFeature vp9DecoderSupport "vp9-decoder")
95 (enableFeature extraWarningsSupport "extra-warnings")
96 (enableFeature werrorSupport "werror")
97 "--disable-install-docs"
98 (enableFeature examplesSupport "install-bins")
99 "--enable-install-libs"
100 "--disable-install-srcs"
101 (enableFeature debugSupport "debug")
102 (enableFeature gprofSupport "gprof")
103 (enableFeature gcovSupport "gcov")
104 # Required to build shared libraries
105 (enableFeature (!isCygwin) "pic")
106 (enableFeature optimizationsSupport "optimizations")
107 (enableFeature runtimeCpuDetectSupport "runtime-cpu-detect")
108 (enableFeature thumbSupport "thumb")
110 (enableFeature examplesSupport "examples")
113 # Limit default decoder max to WHXGA
114 (if sizeLimitSupport then "--size-limit=5120x3200" else null)
115 "--disable-codec-srcs"
116 (enableFeature debugLibsSupport "debug-libs")
117 (enableFeature isMips "dequant-tokens")
118 (enableFeature isMips "dc-recon")
119 (enableFeature postprocSupport "postproc")
120 (enableFeature (postprocSupport && (vp9DecoderSupport || vp9EncoderSupport)) "vp9-postproc")
121 (enableFeature multithreadSupport "multithread")
122 (enableFeature internalStatsSupport "internal-stats")
123 (enableFeature spatialResamplingSupport "spatial-resampling")
124 (enableFeature realtimeOnlySupport "realtime-only")
125 (enableFeature ontheflyBitpackingSupport "onthefly-bitpacking")
126 (enableFeature errorConcealmentSupport "error-concealment")
127 # Shared libraries are only supported on ELF platforms
128 (if isDarwin || isCygwin then
129 "--enable-static --disable-shared"
132 (enableFeature smallSupport "small")
133 (enableFeature postprocVisualizerSupport "postproc-visualizer")
134 (enableFeature unitTestsSupport "unit-tests")
135 (enableFeature webmIOSupport "webm-io")
136 (enableFeature libyuvSupport "libyuv")
137 (enableFeature decodePerfTestsSupport "decode-perf-tests")
138 (enableFeature encodePerfTestsSupport "encode-perf-tests")
139 (enableFeature multiResEncodingSupport "multi-res-encoding")
140 (enableFeature temporalDenoisingSupport "temporal-denoising")
141 (enableFeature (temporalDenoisingSupport && (vp9DecoderSupport || vp9EncoderSupport)) "vp9-temporal-denoising")
142 (enableFeature coefficientRangeCheckingSupport "coefficient-range-checking")
143 (enableFeature (vp9HighbitdepthSupport && is64bit) "vp9-highbitdepth")
144 (enableFeature (experimentalSpatialSvcSupport ||
145 experimentalFpMbStatsSupport ||
146 experimentalEmulateHardwareSupport) "experimental")
147 ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
148 # libvpx darwin targets include darwin version (ie. ARCH-darwinXX-gcc, XX being the darwin version)
149 # See all_platforms: https://github.com/webmproject/libvpx/blob/master/configure
150 # Darwin versions: 10.4=8, 10.5=9, 10.6=10, 10.7=11, 10.8=12, 10.9=13, 10.10=14
151 "--force-target=${stdenv.hostPlatform.parsed.cpu.name}-${stdenv.hostPlatform.parsed.kernel.name}${
152 if stdenv.hostPlatform.isDarwin then
153 if stdenv.hostPlatform.osxMinVersion == "10.10" then "14"
154 else if stdenv.hostPlatform.osxMinVersion == "10.9" then "13"
155 else if stdenv.hostPlatform.osxMinVersion == "10.8" then "12"
156 else if stdenv.hostPlatform.osxMinVersion == "10.7" then "11"
157 else if stdenv.hostPlatform.osxMinVersion == "10.6" then "10"
158 else if stdenv.hostPlatform.osxMinVersion == "10.5" then "9"
161 (if stdenv.hostPlatform.isCygwin then "--enable-static-msvcrt" else "")
162 ] # Experimental features
163 ++ optional experimentalSpatialSvcSupport "--enable-spatial-svc"
164 ++ optional experimentalFpMbStatsSupport "--enable-fp-mb-stats"
165 ++ optional experimentalEmulateHardwareSupport "--enable-emulate-hardware";
167 nativeBuildInputs = [ perl yasm ];
170 ++ optionals unitTestsSupport [ coreutils curl ];
173 "-lpthread" # fixes linker errors
176 enableParallelBuilding = true;
178 postInstall = ''moveToOutput bin "$bin" '';
181 description = "WebM VP8/VP9 codec SDK";
182 homepage = "https://www.webmproject.org/";
183 changelog = "https://github.com/webmproject/libvpx/raw/v${version}/CHANGELOG";
184 license = licenses.bsd3;
185 maintainers = with maintainers; [ codyopel ];
186 platforms = platforms.all;