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
39}:
40
41let
42 inherit (stdenv) is64bit isMips isDarwin isCygwin;
43 inherit (lib) enableFeature optional optionals;
44
45 # libvpx darwin targets include darwin version (ie. ARCH-darwinXX-gcc, XX being the darwin version)
46 # See all_platforms: https://github.com/webmproject/libvpx/blob/master/configure
47 # Darwin versions: 10.4=8, 10.5=9, 10.6=10, 10.7=11, 10.8=12, 10.9=13, 10.10=14
48 darwinVersion =
49 /**/ if stdenv.hostPlatform.osxMinVersion == "10.10" then "14"
50 else if stdenv.hostPlatform.osxMinVersion == "10.9" then "13"
51 else if stdenv.hostPlatform.osxMinVersion == "10.8" then "12"
52 else if stdenv.hostPlatform.osxMinVersion == "10.7" then "11"
53 else if stdenv.hostPlatform.osxMinVersion == "10.6" then "10"
54 else if stdenv.hostPlatform.osxMinVersion == "10.5" then "9"
55 else "8";
56
57 kernel =
58 # Build system doesn't understand BSD, so pretend to be Linux.
59 /**/ if stdenv.isBSD then "linux"
60 else if stdenv.isDarwin then "darwin${darwinVersion}"
61 else stdenv.hostPlatform.parsed.kernel.name;
62
63in
64
65assert vp8DecoderSupport || vp8EncoderSupport || vp9DecoderSupport || vp9EncoderSupport;
66assert internalStatsSupport && (vp9DecoderSupport || vp9EncoderSupport) -> postprocSupport;
67/* If spatialResamplingSupport not enabled, build will fail with undeclared variable errors.
68 Variables called in vpx_scale/generic/vpx_scale.c are declared by vpx_scale/vpx_scale_rtcd.pl,
69 but is only executed if spatialResamplingSupport is enabled */
70assert spatialResamplingSupport;
71assert postprocVisualizerSupport -> postprocSupport;
72assert unitTestsSupport -> curl != null && coreutils != null;
73assert vp9HighbitdepthSupport -> (vp9DecoderSupport || vp9EncoderSupport);
74assert isCygwin -> unitTestsSupport && webmIOSupport && libyuvSupport;
75
76stdenv.mkDerivation rec {
77 pname = "libvpx";
78 version = "1.13.0";
79
80 src = fetchFromGitHub {
81 owner = "webmproject";
82 repo = pname;
83 rev = "v${version}";
84 sha256 = "sha256-IH+ZWbBUlU5fbciYe+dNGnTFFCte2BXxAlLcvmzdAeY=";
85 };
86
87 postPatch = ''
88 patchShebangs --build \
89 build/make/*.sh \
90 build/make/*.pl \
91 build/make/*.pm \
92 test/*.sh \
93 configure
94
95 # When cross-compiling (for aarch64-multiplatform), the compiler errors out on these flags.
96 # Since they're 'just' warnings, it's fine to just remove them.
97 substituteInPlace configure \
98 --replace "check_add_cflags -Wparentheses-equality" "" \
99 --replace "check_add_cflags -Wunreachable-code-loop-increment" "" \
100 --replace "check_cflags -Wshorten-64-to-32 && add_cflags_only -Wshorten-64-to-32" ""
101 '';
102
103 outputs = [ "bin" "dev" "out" ];
104 setOutputFlags = false;
105
106 configurePlatforms = [];
107 configureFlags = [
108 (enableFeature (vp8EncoderSupport || vp8DecoderSupport) "vp8")
109 (enableFeature vp8EncoderSupport "vp8-encoder")
110 (enableFeature vp8DecoderSupport "vp8-decoder")
111 (enableFeature (vp9EncoderSupport || vp9DecoderSupport) "vp9")
112 (enableFeature vp9EncoderSupport "vp9-encoder")
113 (enableFeature vp9DecoderSupport "vp9-decoder")
114 (enableFeature extraWarningsSupport "extra-warnings")
115 (enableFeature werrorSupport "werror")
116 "--disable-install-docs"
117 (enableFeature examplesSupport "install-bins")
118 "--enable-install-libs"
119 "--disable-install-srcs"
120 (enableFeature debugSupport "debug")
121 (enableFeature gprofSupport "gprof")
122 (enableFeature gcovSupport "gcov")
123 # Required to build shared libraries
124 (enableFeature (!isCygwin) "pic")
125 (enableFeature optimizationsSupport "optimizations")
126 (enableFeature runtimeCpuDetectSupport "runtime-cpu-detect")
127 (enableFeature thumbSupport "thumb")
128 "--enable-libs"
129 (enableFeature examplesSupport "examples")
130 "--disable-docs"
131 "--as=yasm"
132 # Limit default decoder max to WHXGA
133 (if sizeLimitSupport then "--size-limit=5120x3200" else null)
134 "--disable-codec-srcs"
135 (enableFeature debugLibsSupport "debug-libs")
136 (enableFeature isMips "dequant-tokens")
137 (enableFeature isMips "dc-recon")
138 (enableFeature postprocSupport "postproc")
139 (enableFeature (postprocSupport && (vp9DecoderSupport || vp9EncoderSupport)) "vp9-postproc")
140 (enableFeature multithreadSupport "multithread")
141 (enableFeature internalStatsSupport "internal-stats")
142 (enableFeature spatialResamplingSupport "spatial-resampling")
143 (enableFeature realtimeOnlySupport "realtime-only")
144 (enableFeature ontheflyBitpackingSupport "onthefly-bitpacking")
145 (enableFeature errorConcealmentSupport "error-concealment")
146 # Shared libraries are only supported on ELF platforms
147 (if isDarwin || isCygwin then
148 "--enable-static --disable-shared"
149 else
150 "--enable-shared")
151 (enableFeature smallSupport "small")
152 (enableFeature postprocVisualizerSupport "postproc-visualizer")
153 (enableFeature unitTestsSupport "unit-tests")
154 (enableFeature webmIOSupport "webm-io")
155 (enableFeature libyuvSupport "libyuv")
156 (enableFeature decodePerfTestsSupport "decode-perf-tests")
157 (enableFeature encodePerfTestsSupport "encode-perf-tests")
158 (enableFeature multiResEncodingSupport "multi-res-encoding")
159 (enableFeature temporalDenoisingSupport "temporal-denoising")
160 (enableFeature (temporalDenoisingSupport && (vp9DecoderSupport || vp9EncoderSupport)) "vp9-temporal-denoising")
161 (enableFeature coefficientRangeCheckingSupport "coefficient-range-checking")
162 (enableFeature (vp9HighbitdepthSupport && is64bit) "vp9-highbitdepth")
163 (enableFeature (experimentalSpatialSvcSupport ||
164 experimentalFpMbStatsSupport ||
165 experimentalEmulateHardwareSupport) "experimental")
166 ] ++ optionals (stdenv.isBSD || stdenv.hostPlatform != stdenv.buildPlatform) [
167 "--force-target=${stdenv.hostPlatform.parsed.cpu.name}-${kernel}-gcc"
168 (lib.optionalString stdenv.hostPlatform.isCygwin "--enable-static-msvcrt")
169 ] # Experimental features
170 ++ optional experimentalSpatialSvcSupport "--enable-spatial-svc"
171 ++ optional experimentalFpMbStatsSupport "--enable-fp-mb-stats"
172 ++ optional experimentalEmulateHardwareSupport "--enable-emulate-hardware";
173
174 nativeBuildInputs = [ perl yasm ];
175
176 buildInputs = [ ]
177 ++ optionals unitTestsSupport [ coreutils curl ];
178
179 NIX_LDFLAGS = [
180 "-lpthread" # fixes linker errors
181 ];
182
183 enableParallelBuilding = true;
184
185 postInstall = ''moveToOutput bin "$bin" '';
186
187 meta = with lib; {
188 description = "WebM VP8/VP9 codec SDK";
189 homepage = "https://www.webmproject.org/";
190 changelog = "https://github.com/webmproject/libvpx/raw/v${version}/CHANGELOG";
191 license = licenses.bsd3;
192 maintainers = with maintainers; [ codyopel ];
193 platforms = platforms.all;
194 };
195}