Merge "Use signed variables in the lookahead."
[aom.git] / test / vpxenc.sh
blobe8994992aed696ead7ad67dea99e5f30e616701b
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.
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).
16 . $(dirname $0)/tools_common.sh
18 readonly TEST_FRAMES=10
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
26 if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
27 if [ ! -e "${Y4M_NOSQ_PAR_INPUT}" ]; then
28 elog "The file ${Y4M_NOSQ_PAR_INPUT##*/} must exist in"
29 elog "LIBVPX_TEST_DATA_PATH."
30 return 1
33 if [ -z "$(vpx_tool_path vpxenc)" ]; then
34 elog "vpxenc not found. It must exist in LIBVPX_BIN_PATH or its parent."
35 return 1
39 vpxenc_can_encode_vp8() {
40 if [ "$(vp8_encode_available)" = "yes" ]; then
41 echo yes
45 vpxenc_can_encode_vp9() {
46 if [ "$(vp9_encode_available)" = "yes" ]; then
47 echo yes
51 # Echo vpxenc command line parameters allowing use of
52 # hantro_collage_w352h288.yuv as input.
53 yuv_input_hantro_collage() {
54 echo ""${YUV_RAW_INPUT}"
55 --width="${YUV_RAW_INPUT_WIDTH}"
56 --height="${YUV_RAW_INPUT_HEIGHT}""
59 y4m_input_non_square_par() {
60 echo ""${Y4M_NOSQ_PAR_INPUT}""
63 y4m_input_720p() {
64 echo ""${Y4M_720P_INPUT}""
67 # Echo default vpxenc real time encoding params. $1 is the codec, which defaults
68 # to vp8 if unspecified.
69 vpxenc_rt_params() {
70 local readonly codec="${1:-vp8}"
71 echo "--codec=${codec}
72 --buf-initial-sz=500
73 --buf-optimal-sz=600
74 --buf-sz=1000
75 --cpu-used=-6
76 --end-usage=cbr
77 --error-resilient=1
78 --kf-max-dist=90000
79 --lag-in-frames=0
80 --max-intra-rate=300
81 --max-q=56
82 --min-q=2
83 --noise-sensitivity=0
84 --overshoot-pct=50
85 --passes=1
86 --profile=0
87 --resize-allowed=0
88 --rt
89 --static-thresh=0
90 --undershoot-pct=50"
93 # Wrapper function for running vpxenc with pipe input. Requires that
94 # LIBVPX_BIN_PATH points to the directory containing vpxenc. $1 is used as the
95 # input file path and shifted away. All remaining parameters are passed through
96 # to vpxenc.
97 vpxenc_pipe() {
98 local readonly encoder="$(vpx_tool_path vpxenc)"
99 local readonly input="$1"
100 shift
101 cat "${input}" | eval "${VPX_TEST_PREFIX}" "${encoder}" - \
102 --test-decode=fatal \
103 "$@" ${devnull}
106 # Wrapper function for running vpxenc. Requires that LIBVPX_BIN_PATH points to
107 # the directory containing vpxenc. $1 one is used as the input file path and
108 # shifted away. All remaining parameters are passed through to vpxenc.
109 vpxenc() {
110 local readonly encoder="$(vpx_tool_path vpxenc)"
111 local readonly input="$1"
112 shift
113 eval "${VPX_TEST_PREFIX}" "${encoder}" "${input}" \
114 --test-decode=fatal \
115 "$@" ${devnull}
118 vpxenc_vp8_ivf() {
119 if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then
120 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8.ivf"
121 vpxenc $(yuv_input_hantro_collage) \
122 --codec=vp8 \
123 --limit="${TEST_FRAMES}" \
124 --ivf \
125 --output="${output}"
127 if [ ! -e "${output}" ]; then
128 elog "Output file does not exist."
129 return 1
134 vpxenc_vp8_webm() {
135 if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
136 [ "$(webm_io_available)" = "yes" ]; then
137 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8.webm"
138 vpxenc $(yuv_input_hantro_collage) \
139 --codec=vp8 \
140 --limit="${TEST_FRAMES}" \
141 --output="${output}"
143 if [ ! -e "${output}" ]; then
144 elog "Output file does not exist."
145 return 1
150 vpxenc_vp8_webm_rt() {
151 if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
152 [ "$(webm_io_available)" = "yes" ]; then
153 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8_rt.webm"
154 vpxenc $(yuv_input_hantro_collage) \
155 $(vpxenc_rt_params vp8) \
156 --output="${output}"
157 if [ ! -e "${output}" ]; then
158 elog "Output file does not exist."
159 return 1
164 vpxenc_vp8_webm_2pass() {
165 if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
166 [ "$(webm_io_available)" = "yes" ]; then
167 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8.webm"
168 vpxenc $(yuv_input_hantro_collage) \
169 --codec=vp8 \
170 --limit="${TEST_FRAMES}" \
171 --output="${output}" \
172 --passes=2
174 if [ ! -e "${output}" ]; then
175 elog "Output file does not exist."
176 return 1
181 vpxenc_vp8_webm_lag10_frames20() {
182 if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
183 [ "$(webm_io_available)" = "yes" ]; then
184 local readonly lag_total_frames=20
185 local readonly lag_frames=10
186 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8_lag10_frames20.webm"
187 vpxenc $(yuv_input_hantro_collage) \
188 --codec=vp8 \
189 --limit="${lag_total_frames}" \
190 --lag-in-frames="${lag_frames}" \
191 --output="${output}" \
192 --auto-alt-ref=1 \
193 --passes=2
195 if [ ! -e "${output}" ]; then
196 elog "Output file does not exist."
197 return 1
202 vpxenc_vp8_ivf_piped_input() {
203 if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then
204 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8_piped_input.ivf"
205 vpxenc_pipe $(yuv_input_hantro_collage) \
206 --codec=vp8 \
207 --limit="${TEST_FRAMES}" \
208 --ivf \
209 --output="${output}"
211 if [ ! -e "${output}" ]; then
212 elog "Output file does not exist."
213 return 1
218 vpxenc_vp9_ivf() {
219 if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
220 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.ivf"
221 vpxenc $(yuv_input_hantro_collage) \
222 --codec=vp9 \
223 --limit="${TEST_FRAMES}" \
224 --ivf \
225 --output="${output}"
227 if [ ! -e "${output}" ]; then
228 elog "Output file does not exist."
229 return 1
234 vpxenc_vp9_webm() {
235 if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
236 [ "$(webm_io_available)" = "yes" ]; then
237 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.webm"
238 vpxenc $(yuv_input_hantro_collage) \
239 --codec=vp9 \
240 --limit="${TEST_FRAMES}" \
241 --output="${output}"
243 if [ ! -e "${output}" ]; then
244 elog "Output file does not exist."
245 return 1
250 vpxenc_vp9_webm_rt() {
251 if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
252 [ "$(webm_io_available)" = "yes" ]; then
253 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_rt.webm"
254 vpxenc $(yuv_input_hantro_collage) \
255 $(vpxenc_rt_params vp9) \
256 --output="${output}"
258 if [ ! -e "${output}" ]; then
259 elog "Output file does not exist."
260 return 1
265 vpxenc_vp9_webm_rt_multithread_tiled() {
266 if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
267 [ "$(webm_io_available)" = "yes" ]; then
268 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_rt_multithread_tiled.webm"
269 local readonly tilethread_min=2
270 local readonly tilethread_max=4
271 local readonly num_threads="$(seq ${tilethread_min} ${tilethread_max})"
272 local readonly num_tile_cols="$(seq ${tilethread_min} ${tilethread_max})"
274 for threads in ${num_threads}; do
275 for tile_cols in ${num_tile_cols}; do
276 vpxenc $(y4m_input_720p) \
277 $(vpxenc_rt_params vp9) \
278 --threads=${threads} \
279 --tile-columns=${tile_cols} \
280 --output="${output}"
281 done
282 done
284 if [ ! -e "${output}" ]; then
285 elog "Output file does not exist."
286 return 1
289 rm "${output}"
293 vpxenc_vp9_webm_rt_multithread_tiled_frameparallel() {
294 if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
295 [ "$(webm_io_available)" = "yes" ]; then
296 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_rt_mt_t_fp.webm"
297 local readonly tilethread_min=2
298 local readonly tilethread_max=4
299 local readonly num_threads="$(seq ${tilethread_min} ${tilethread_max})"
300 local readonly num_tile_cols="$(seq ${tilethread_min} ${tilethread_max})"
302 for threads in ${num_threads}; do
303 for tile_cols in ${num_tile_cols}; do
304 vpxenc $(y4m_input_720p) \
305 $(vpxenc_rt_params vp9) \
306 --threads=${threads} \
307 --tile-columns=${tile_cols} \
308 --frame-parallel=1 \
309 --output="${output}"
310 done
311 done
313 if [ ! -e "${output}" ]; then
314 elog "Output file does not exist."
315 return 1
318 rm "${output}"
322 vpxenc_vp9_webm_2pass() {
323 if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
324 [ "$(webm_io_available)" = "yes" ]; then
325 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.webm"
326 vpxenc $(yuv_input_hantro_collage) \
327 --codec=vp9 \
328 --limit="${TEST_FRAMES}" \
329 --output="${output}" \
330 --passes=2
332 if [ ! -e "${output}" ]; then
333 elog "Output file does not exist."
334 return 1
339 vpxenc_vp9_ivf_lossless() {
340 if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
341 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless.ivf"
342 vpxenc $(yuv_input_hantro_collage) \
343 --codec=vp9 \
344 --limit="${TEST_FRAMES}" \
345 --ivf \
346 --output="${output}" \
347 --lossless=1
349 if [ ! -e "${output}" ]; then
350 elog "Output file does not exist."
351 return 1
356 vpxenc_vp9_ivf_minq0_maxq0() {
357 if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
358 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless_minq0_maxq0.ivf"
359 vpxenc $(yuv_input_hantro_collage) \
360 --codec=vp9 \
361 --limit="${TEST_FRAMES}" \
362 --ivf \
363 --output="${output}" \
364 --min-q=0 \
365 --max-q=0
367 if [ ! -e "${output}" ]; then
368 elog "Output file does not exist."
369 return 1
374 vpxenc_vp9_webm_lag10_frames20() {
375 if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
376 [ "$(webm_io_available)" = "yes" ]; then
377 local readonly lag_total_frames=20
378 local readonly lag_frames=10
379 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lag10_frames20.webm"
380 vpxenc $(yuv_input_hantro_collage) \
381 --codec=vp9 \
382 --limit="${lag_total_frames}" \
383 --lag-in-frames="${lag_frames}" \
384 --output="${output}" \
385 --passes=2 \
386 --auto-alt-ref=1
388 if [ ! -e "${output}" ]; then
389 elog "Output file does not exist."
390 return 1
395 # TODO(fgalligan): Test that DisplayWidth is different than video width.
396 vpxenc_vp9_webm_non_square_par() {
397 if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
398 [ "$(webm_io_available)" = "yes" ]; then
399 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_non_square_par.webm"
400 vpxenc $(y4m_input_non_square_par) \
401 --codec=vp9 \
402 --limit="${TEST_FRAMES}" \
403 --output="${output}"
405 if [ ! -e "${output}" ]; then
406 elog "Output file does not exist."
407 return 1
412 vpxenc_tests="vpxenc_vp8_ivf
413 vpxenc_vp8_webm
414 vpxenc_vp8_webm_rt
415 vpxenc_vp8_webm_2pass
416 vpxenc_vp8_webm_lag10_frames20
417 vpxenc_vp8_ivf_piped_input
418 vpxenc_vp9_ivf
419 vpxenc_vp9_webm
420 vpxenc_vp9_webm_rt
421 vpxenc_vp9_webm_rt_multithread_tiled
422 vpxenc_vp9_webm_rt_multithread_tiled_frameparallel
423 vpxenc_vp9_webm_2pass
424 vpxenc_vp9_ivf_lossless
425 vpxenc_vp9_ivf_minq0_maxq0
426 vpxenc_vp9_webm_lag10_frames20
427 vpxenc_vp9_webm_non_square_par"
429 run_tests vpxenc_verify_environment "${vpxenc_tests}"