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