]> granicus.if.org Git - libvpx/blob - test/vpxenc.sh
vpxenc.sh: Add real time tests.
[libvpx] / test / vpxenc.sh
1 #!/bin/sh
2 ##
3 ##  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
4 ##
5 ##  Use of this source code is governed by a BSD-style license
6 ##  that can be found in the LICENSE file in the root of the source
7 ##  tree. An additional intellectual property rights grant can be found
8 ##  in the file PATENTS.  All contributing project authors may
9 ##  be found in the AUTHORS file in the root of the source tree.
10 ##
11 ##  This file tests vpxenc using hantro_collage_w352h288.yuv as input. To add
12 ##  new tests to this file, do the following:
13 ##    1. Write a shell function (this is your test).
14 ##    2. Add the function to vpxenc_tests (on a new line).
15 ##
16 . $(dirname $0)/tools_common.sh
17
18 readonly TEST_FRAMES=10
19
20 # Environment check: Make sure input is available.
21 vpxenc_verify_environment() {
22   if [ ! -e "${YUV_RAW_INPUT}" ]; then
23     elog "The file ${YUV_RAW_INPUT##*/} must exist in LIBVPX_TEST_DATA_PATH."
24     return 1
25   fi
26   if [ -z "$(vpx_tool_path vpxenc)" ]; then
27     elog "vpxenc not found. It must exist in LIBVPX_BIN_PATH or its parent."
28     return 1
29   fi
30 }
31
32 vpxenc_can_encode_vp8() {
33   if [ "$(vp8_encode_available)" = "yes" ]; then
34     echo yes
35   fi
36 }
37
38 vpxenc_can_encode_vp9() {
39   if [ "$(vp9_encode_available)" = "yes" ]; then
40     echo yes
41   fi
42 }
43
44 # Wrapper function for running vpxenc with pipe input. Requires that
45 # LIBVPX_BIN_PATH points to the directory containing vpxenc. $1 is used as the
46 # input file path and shifted away. All remaining parameters are passed through
47 # to vpxenc.
48 vpxenc_pipe() {
49   local readonly encoder="$(vpx_tool_path vpxenc)"
50   local readonly input="$1"
51   shift
52   cat "${input}" | eval "${VPX_TEST_PREFIX}" "${encoder}" - \
53     --test-decode=fatal \
54     "$@" ${devnull}
55 }
56
57 # Wrapper function for running vpxenc. Requires that LIBVPX_BIN_PATH points to
58 # the directory containing vpxenc. $1 one is used as the input file path and
59 # shifted away. All remaining parameters are passed through to vpxenc.
60 vpxenc() {
61   local readonly encoder="$(vpx_tool_path vpxenc)"
62   local readonly input="$1"
63   shift
64   eval "${VPX_TEST_PREFIX}" "${encoder}" "${input}" \
65     --test-decode=fatal \
66     "$@" ${devnull}
67 }
68
69 vpxenc_vp8_ivf() {
70   if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then
71     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8.ivf"
72     vpxenc --codec=vp8 \
73       --width="${YUV_RAW_INPUT_WIDTH}" \
74       --height="${YUV_RAW_INPUT_HEIGHT}" \
75       --limit="${TEST_FRAMES}" \
76       --ivf \
77       --output="${output}" \
78       "${YUV_RAW_INPUT}"
79
80     if [ ! -e "${output}" ]; then
81       elog "Output file does not exist."
82       return 1
83     fi
84   fi
85 }
86
87 vpxenc_vp8_webm() {
88   if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
89      [ "$(webm_io_available)" = "yes" ]; then
90     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8.webm"
91     vpxenc --codec=vp8 \
92       --width="${YUV_RAW_INPUT_WIDTH}" \
93       --height="${YUV_RAW_INPUT_HEIGHT}" \
94       --limit="${TEST_FRAMES}" \
95       --output="${output}" \
96       "${YUV_RAW_INPUT}"
97
98     if [ ! -e "${output}" ]; then
99       elog "Output file does not exist."
100       return 1
101     fi
102   fi
103 }
104
105 vpxenc_vp8_webm_rt() {
106   if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
107      [ "$(webm_io_available)" = "yes" ]; then
108     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8_rt.webm"
109     vpxenc "${YUV_RAW_INPUT}" \
110       --codec=vp8 \
111       --width="${YUV_RAW_INPUT_WIDTH}" \
112       --height="${YUV_RAW_INPUT_HEIGHT}" \
113       --output="${output}" \
114       --buf-initial-sz=500 \
115       --buf-optimal-sz=600 \
116       --buf-sz=1000 \
117       --cpu-used=-5 \
118       --end-usage=cbr \
119       --error-resilient=1 \
120       --kf-max-dist=90000 \
121       --lag-in-frames=0 \
122       --max-intra-rate=300 \
123       --max-q=56 \
124       --min-q=2 \
125       --noise-sensitivity=0 \
126       --overshoot-pct=50 \
127       --passes=1 \
128       --profile=0 \
129       --resize-allowed=0 \
130       --rt \
131       --static-thresh=0 \
132       --undershoot-pct=50
133
134     if [ ! -e "${output}" ]; then
135       elog "Output file does not exist."
136       return 1
137     fi
138   fi
139 }
140
141 vpxenc_vp8_webm_2pass() {
142   if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
143      [ "$(webm_io_available)" = "yes" ]; then
144     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8.webm"
145     vpxenc --codec=vp8 \
146       --width="${YUV_RAW_INPUT_WIDTH}" \
147       --height="${YUV_RAW_INPUT_HEIGHT}" \
148       --limit="${TEST_FRAMES}" \
149       --output="${output}" \
150       --passes=2 \
151       "${YUV_RAW_INPUT}"
152
153     if [ ! -e "${output}" ]; then
154       elog "Output file does not exist."
155       return 1
156     fi
157   fi
158 }
159
160 vpxenc_vp8_webm_lag10_frames20() {
161   if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
162      [ "$(webm_io_available)" = "yes" ]; then
163     local readonly lag_total_frames=20
164     local readonly lag_frames=10
165     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8_lag10_frames20.webm"
166     vpxenc --codec=vp8 \
167       --width="${YUV_RAW_INPUT_WIDTH}" \
168       --height="${YUV_RAW_INPUT_HEIGHT}" \
169       --limit="${lag_total_frames}" \
170       --lag-in-frames="${lag_frames}" \
171       --output="${output}" \
172       --auto-alt-ref=1 \
173       --passes=2 \
174       "${YUV_RAW_INPUT}"
175
176     if [ ! -e "${output}" ]; then
177       elog "Output file does not exist."
178       return 1
179     fi
180   fi
181 }
182
183 vpxenc_vp8_ivf_piped_input() {
184   if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then
185     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8_piped_input.ivf"
186     cat "${YUV_RAW_INPUT}" \
187       | vpxenc --codec=vp8 \
188         --width="${YUV_RAW_INPUT_WIDTH}" \
189         --height="${YUV_RAW_INPUT_HEIGHT}" \
190         --limit="${TEST_FRAMES}" \
191         --ivf \
192         --output="${output}" \
193         -
194
195     if [ ! -e "${output}" ]; then
196       elog "Output file does not exist."
197       return 1
198     fi
199   fi
200 }
201
202 vpxenc_vp9_ivf() {
203   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
204     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.ivf"
205     vpxenc --codec=vp9 \
206       --width="${YUV_RAW_INPUT_WIDTH}" \
207       --height="${YUV_RAW_INPUT_HEIGHT}" \
208       --limit="${TEST_FRAMES}" \
209       --ivf \
210       --output="${output}" \
211       "${YUV_RAW_INPUT}"
212
213     if [ ! -e "${output}" ]; then
214       elog "Output file does not exist."
215       return 1
216     fi
217   fi
218 }
219
220 vpxenc_vp9_webm() {
221   if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
222      [ "$(webm_io_available)" = "yes" ]; then
223     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.webm"
224     vpxenc --codec=vp9 \
225       --width="${YUV_RAW_INPUT_WIDTH}" \
226       --height="${YUV_RAW_INPUT_HEIGHT}" \
227       --limit="${TEST_FRAMES}" \
228       --output="${output}" \
229       "${YUV_RAW_INPUT}"
230
231     if [ ! -e "${output}" ]; then
232       elog "Output file does not exist."
233       return 1
234     fi
235   fi
236 }
237
238 vpxenc_vp9_webm_rt() {
239   if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
240      [ "$(webm_io_available)" = "yes" ]; then
241     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_rt.webm"
242     vpxenc "${YUV_RAW_INPUT}" \
243       --codec=vp9 \
244       --width="${YUV_RAW_INPUT_WIDTH}" \
245       --height="${YUV_RAW_INPUT_HEIGHT}" \
246       --output="${output}" \
247       --buf-initial-sz=500 \
248       --buf-optimal-sz=600 \
249       --buf-sz=1000 \
250       --cpu-used=-5 \
251       --end-usage=cbr \
252       --error-resilient=1 \
253       --kf-max-dist=90000 \
254       --lag-in-frames=0 \
255       --max-intra-rate=300 \
256       --max-q=56 \
257       --min-q=2 \
258       --noise-sensitivity=0 \
259       --overshoot-pct=50 \
260       --passes=1 \
261       --profile=0 \
262       --resize-allowed=0 \
263       --rt \
264       --static-thresh=0 \
265       --undershoot-pct=50
266
267     if [ ! -e "${output}" ]; then
268       elog "Output file does not exist."
269       return 1
270     fi
271   fi
272 }
273
274 vpxenc_vp9_webm_2pass() {
275   if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
276      [ "$(webm_io_available)" = "yes" ]; then
277     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.webm"
278     vpxenc --codec=vp9 \
279       --width="${YUV_RAW_INPUT_WIDTH}" \
280       --height="${YUV_RAW_INPUT_HEIGHT}" \
281       --limit="${TEST_FRAMES}" \
282       --output="${output}" \
283       --passes=2 \
284       "${YUV_RAW_INPUT}"
285
286     if [ ! -e "${output}" ]; then
287       elog "Output file does not exist."
288       return 1
289     fi
290   fi
291 }
292
293 vpxenc_vp9_ivf_lossless() {
294   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
295     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless.ivf"
296     vpxenc --codec=vp9 \
297       --width="${YUV_RAW_INPUT_WIDTH}" \
298       --height="${YUV_RAW_INPUT_HEIGHT}" \
299       --limit="${TEST_FRAMES}" \
300       --ivf \
301       --output="${output}" \
302       --lossless=1 \
303       "${YUV_RAW_INPUT}"
304
305     if [ ! -e "${output}" ]; then
306       elog "Output file does not exist."
307       return 1
308     fi
309   fi
310 }
311
312 vpxenc_vp9_ivf_minq0_maxq0() {
313   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
314     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless_minq0_maxq0.ivf"
315     vpxenc --codec=vp9 \
316       --width="${YUV_RAW_INPUT_WIDTH}" \
317       --height="${YUV_RAW_INPUT_HEIGHT}" \
318       --limit="${TEST_FRAMES}" \
319       --ivf \
320       --output="${output}" \
321       --min-q=0 \
322       --max-q=0 \
323       "${YUV_RAW_INPUT}"
324
325     if [ ! -e "${output}" ]; then
326       elog "Output file does not exist."
327       return 1
328     fi
329   fi
330 }
331
332 vpxenc_vp9_webm_lag10_frames20() {
333   if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
334      [ "$(webm_io_available)" = "yes" ]; then
335     local readonly lag_total_frames=20
336     local readonly lag_frames=10
337     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lag10_frames20.webm"
338     vpxenc --codec=vp9 \
339       --width="${YUV_RAW_INPUT_WIDTH}" \
340       --height="${YUV_RAW_INPUT_HEIGHT}" \
341       --limit="${lag_total_frames}" \
342       --lag-in-frames="${lag_frames}" \
343       --output="${output}" \
344       --passes=2 \
345       --auto-alt-ref=1 \
346       "${YUV_RAW_INPUT}"
347
348     if [ ! -e "${output}" ]; then
349       elog "Output file does not exist."
350       return 1
351     fi
352   fi
353 }
354
355 vpxenc_tests="vpxenc_vp8_ivf
356               vpxenc_vp8_webm
357               vpxenc_vp8_webm_rt
358               vpxenc_vp8_webm_2pass
359               vpxenc_vp8_webm_lag10_frames20
360               vpxenc_vp8_ivf_piped_input
361               vpxenc_vp9_ivf
362               vpxenc_vp9_webm
363               vpxenc_vp9_webm_rt
364               vpxenc_vp9_webm_2pass
365               vpxenc_vp9_ivf_lossless
366               vpxenc_vp9_ivf_minq0_maxq0
367               vpxenc_vp9_webm_lag10_frames20"
368
369 run_tests vpxenc_verify_environment "${vpxenc_tests}"