]> granicus.if.org Git - libvpx/blob - test/vpxenc.sh
vpxenc.sh: Make vpxenc() usage agree with implementation.
[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 "${YUV_RAW_INPUT}" \
73       --codec=vp8 \
74       --width="${YUV_RAW_INPUT_WIDTH}" \
75       --height="${YUV_RAW_INPUT_HEIGHT}" \
76       --limit="${TEST_FRAMES}" \
77       --ivf \
78       --output="${output}"
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 "${YUV_RAW_INPUT}" \
92       --codec=vp8 \
93       --width="${YUV_RAW_INPUT_WIDTH}" \
94       --height="${YUV_RAW_INPUT_HEIGHT}" \
95       --limit="${TEST_FRAMES}" \
96       --output="${output}"
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 "${YUV_RAW_INPUT}" \
146       --codec=vp8 \
147       --width="${YUV_RAW_INPUT_WIDTH}" \
148       --height="${YUV_RAW_INPUT_HEIGHT}" \
149       --limit="${TEST_FRAMES}" \
150       --output="${output}" \
151       --passes=2
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 "${YUV_RAW_INPUT}" \
167       --codec=vp8 \
168       --width="${YUV_RAW_INPUT_WIDTH}" \
169       --height="${YUV_RAW_INPUT_HEIGHT}" \
170       --limit="${lag_total_frames}" \
171       --lag-in-frames="${lag_frames}" \
172       --output="${output}" \
173       --auto-alt-ref=1 \
174       --passes=2
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       vpxenc_pipe "${YUV_RAW_INPUT}" \
187         --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     if [ ! -e "${output}" ]; then
195       elog "Output file does not exist."
196       return 1
197     fi
198   fi
199 }
200
201 vpxenc_vp9_ivf() {
202   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
203     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.ivf"
204     vpxenc "${YUV_RAW_INPUT}" \
205       --codec=vp9 \
206       --width="${YUV_RAW_INPUT_WIDTH}" \
207       --height="${YUV_RAW_INPUT_HEIGHT}" \
208       --limit="${TEST_FRAMES}" \
209       --ivf \
210       --output="${output}"
211
212     if [ ! -e "${output}" ]; then
213       elog "Output file does not exist."
214       return 1
215     fi
216   fi
217 }
218
219 vpxenc_vp9_webm() {
220   if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
221      [ "$(webm_io_available)" = "yes" ]; then
222     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.webm"
223     vpxenc "${YUV_RAW_INPUT}" \
224       --codec=vp9 \
225       --width="${YUV_RAW_INPUT_WIDTH}" \
226       --height="${YUV_RAW_INPUT_HEIGHT}" \
227       --limit="${TEST_FRAMES}" \
228       --output="${output}"
229
230     if [ ! -e "${output}" ]; then
231       elog "Output file does not exist."
232       return 1
233     fi
234   fi
235 }
236
237 vpxenc_vp9_webm_rt() {
238   if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
239      [ "$(webm_io_available)" = "yes" ]; then
240     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_rt.webm"
241     vpxenc "${YUV_RAW_INPUT}" \
242       --codec=vp9 \
243       --width="${YUV_RAW_INPUT_WIDTH}" \
244       --height="${YUV_RAW_INPUT_HEIGHT}" \
245       --output="${output}" \
246       --buf-initial-sz=500 \
247       --buf-optimal-sz=600 \
248       --buf-sz=1000 \
249       --cpu-used=-5 \
250       --end-usage=cbr \
251       --error-resilient=1 \
252       --kf-max-dist=90000 \
253       --lag-in-frames=0 \
254       --max-intra-rate=300 \
255       --max-q=56 \
256       --min-q=2 \
257       --noise-sensitivity=0 \
258       --overshoot-pct=50 \
259       --passes=1 \
260       --profile=0 \
261       --resize-allowed=0 \
262       --rt \
263       --static-thresh=0 \
264       --undershoot-pct=50
265
266     if [ ! -e "${output}" ]; then
267       elog "Output file does not exist."
268       return 1
269     fi
270   fi
271 }
272
273 vpxenc_vp9_webm_2pass() {
274   if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
275      [ "$(webm_io_available)" = "yes" ]; then
276     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.webm"
277     vpxenc "${YUV_RAW_INPUT}" \
278       --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
285     if [ ! -e "${output}" ]; then
286       elog "Output file does not exist."
287       return 1
288     fi
289   fi
290 }
291
292 vpxenc_vp9_ivf_lossless() {
293   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
294     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless.ivf"
295     vpxenc "${YUV_RAW_INPUT}" \
296       --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
304     if [ ! -e "${output}" ]; then
305       elog "Output file does not exist."
306       return 1
307     fi
308   fi
309 }
310
311 vpxenc_vp9_ivf_minq0_maxq0() {
312   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
313     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless_minq0_maxq0.ivf"
314     vpxenc "${YUV_RAW_INPUT}" \
315       --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
324     if [ ! -e "${output}" ]; then
325       elog "Output file does not exist."
326       return 1
327     fi
328   fi
329 }
330
331 vpxenc_vp9_webm_lag10_frames20() {
332   if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
333      [ "$(webm_io_available)" = "yes" ]; then
334     local readonly lag_total_frames=20
335     local readonly lag_frames=10
336     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lag10_frames20.webm"
337     vpxenc "${YUV_RAW_INPUT}" \
338       --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
347     if [ ! -e "${output}" ]; then
348       elog "Output file does not exist."
349       return 1
350     fi
351   fi
352 }
353
354 vpxenc_tests="vpxenc_vp8_ivf
355               vpxenc_vp8_webm
356               vpxenc_vp8_webm_rt
357               vpxenc_vp8_webm_2pass
358               vpxenc_vp8_webm_lag10_frames20
359               vpxenc_vp8_ivf_piped_input
360               vpxenc_vp9_ivf
361               vpxenc_vp9_webm
362               vpxenc_vp9_webm_rt
363               vpxenc_vp9_webm_2pass
364               vpxenc_vp9_ivf_lossless
365               vpxenc_vp9_ivf_minq0_maxq0
366               vpxenc_vp9_webm_lag10_frames20"
367
368 run_tests vpxenc_verify_environment "${vpxenc_tests}"