]> granicus.if.org Git - libvpx/blob - test/vpxenc.sh
b6482c603fec1c023b99b32ae498383c6dabbfe1
[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_2pass() {
106   if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
107      [ "$(webm_io_available)" = "yes" ]; then
108     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8.webm"
109     vpxenc --codec=vp8 \
110       --width="${YUV_RAW_INPUT_WIDTH}" \
111       --height="${YUV_RAW_INPUT_HEIGHT}" \
112       --limit="${TEST_FRAMES}" \
113       --output="${output}" \
114       --passes=2 \
115       "${YUV_RAW_INPUT}"
116
117     if [ ! -e "${output}" ]; then
118       elog "Output file does not exist."
119       return 1
120     fi
121   fi
122 }
123
124 vpxenc_vp8_webm_lag10_frames20() {
125   if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
126      [ "$(webm_io_available)" = "yes" ]; then
127     local readonly lag_total_frames=20
128     local readonly lag_frames=10
129     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8_lag10_frames20.webm"
130     vpxenc --codec=vp8 \
131       --width="${YUV_RAW_INPUT_WIDTH}" \
132       --height="${YUV_RAW_INPUT_HEIGHT}" \
133       --limit="${lag_total_frames}" \
134       --lag-in-frames="${lag_frames}" \
135       --output="${output}" \
136       --auto-alt-ref=1 \
137       --passes=2 \
138       "${YUV_RAW_INPUT}"
139
140     if [ ! -e "${output}" ]; then
141       elog "Output file does not exist."
142       return 1
143     fi
144   fi
145 }
146
147 vpxenc_vp8_ivf_piped_input() {
148   if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then
149     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8_piped_input.ivf"
150     cat "${YUV_RAW_INPUT}" \
151       | vpxenc --codec=vp8 \
152         --width="${YUV_RAW_INPUT_WIDTH}" \
153         --height="${YUV_RAW_INPUT_HEIGHT}" \
154         --limit="${TEST_FRAMES}" \
155         --ivf \
156         --output="${output}" \
157         -
158
159     if [ ! -e "${output}" ]; then
160       elog "Output file does not exist."
161       return 1
162     fi
163   fi
164 }
165
166 vpxenc_vp9_ivf() {
167   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
168     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.ivf"
169     vpxenc --codec=vp9 \
170       --width="${YUV_RAW_INPUT_WIDTH}" \
171       --height="${YUV_RAW_INPUT_HEIGHT}" \
172       --limit="${TEST_FRAMES}" \
173       --ivf \
174       --output="${output}" \
175       "${YUV_RAW_INPUT}"
176
177     if [ ! -e "${output}" ]; then
178       elog "Output file does not exist."
179       return 1
180     fi
181   fi
182 }
183
184 vpxenc_vp9_webm() {
185   if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
186      [ "$(webm_io_available)" = "yes" ]; then
187     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.webm"
188     vpxenc --codec=vp9 \
189       --width="${YUV_RAW_INPUT_WIDTH}" \
190       --height="${YUV_RAW_INPUT_HEIGHT}" \
191       --limit="${TEST_FRAMES}" \
192       --output="${output}" \
193       "${YUV_RAW_INPUT}"
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_webm_2pass() {
203   if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
204      [ "$(webm_io_available)" = "yes" ]; then
205     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.webm"
206     vpxenc --codec=vp9 \
207       --width="${YUV_RAW_INPUT_WIDTH}" \
208       --height="${YUV_RAW_INPUT_HEIGHT}" \
209       --limit="${TEST_FRAMES}" \
210       --test-decode=fatal \
211       --output="${output}" \
212       --passes=2 \
213       "${YUV_RAW_INPUT}"
214
215     if [ ! -e "${output}" ]; then
216       elog "Output file does not exist."
217       return 1
218     fi
219   fi
220 }
221
222 vpxenc_vp9_ivf_lossless() {
223   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
224     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless.ivf"
225     vpxenc --codec=vp9 \
226       --width="${YUV_RAW_INPUT_WIDTH}" \
227       --height="${YUV_RAW_INPUT_HEIGHT}" \
228       --limit="${TEST_FRAMES}" \
229       --ivf \
230       --output="${output}" \
231       --lossless=1 \
232       "${YUV_RAW_INPUT}"
233
234     if [ ! -e "${output}" ]; then
235       elog "Output file does not exist."
236       return 1
237     fi
238   fi
239 }
240
241 vpxenc_vp9_ivf_minq0_maxq0() {
242   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
243     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless_minq0_maxq0.ivf"
244     vpxenc --codec=vp9 \
245       --width="${YUV_RAW_INPUT_WIDTH}" \
246       --height="${YUV_RAW_INPUT_HEIGHT}" \
247       --limit="${TEST_FRAMES}" \
248       --ivf \
249       --output="${output}" \
250       --min-q=0 \
251       --max-q=0 \
252       "${YUV_RAW_INPUT}"
253
254     if [ ! -e "${output}" ]; then
255       elog "Output file does not exist."
256       return 1
257     fi
258   fi
259 }
260
261 vpxenc_vp9_webm_lag10_frames20() {
262   if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
263      [ "$(webm_io_available)" = "yes" ]; then
264     local readonly lag_total_frames=20
265     local readonly lag_frames=10
266     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lag10_frames20.webm"
267     vpxenc --codec=vp9 \
268       --width="${YUV_RAW_INPUT_WIDTH}" \
269       --height="${YUV_RAW_INPUT_HEIGHT}" \
270       --limit="${lag_total_frames}" \
271       --lag-in-frames="${lag_frames}" \
272       --output="${output}" \
273       --test-decode=fatal \
274       --passes=2 \
275       --auto-alt-ref=1 \
276       "${YUV_RAW_INPUT}"
277
278     if [ ! -e "${output}" ]; then
279       elog "Output file does not exist."
280       return 1
281     fi
282   fi
283 }
284
285 vpxenc_tests="vpxenc_vp8_ivf
286               vpxenc_vp8_webm
287               vpxenc_vp8_webm_2pass
288               vpxenc_vp8_webm_lag10_frames20
289               vpxenc_vp8_ivf_piped_input
290               vpxenc_vp9_ivf
291               vpxenc_vp9_webm
292               vpxenc_vp9_webm_2pass
293               vpxenc_vp9_ivf_lossless
294               vpxenc_vp9_ivf_minq0_maxq0
295               vpxenc_vp9_webm_lag10_frames20"
296
297 run_tests vpxenc_verify_environment "${vpxenc_tests}"