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
18readonly TEST_FRAMES=10
19
20# Environment check: Make sure input is available.
21vpxenc_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
32vpxenc_can_encode_vp8() {
33  if [ "$(vp8_encode_available)" = "yes" ]; then
34    echo yes
35  fi
36}
37
38vpxenc_can_encode_vp9() {
39  if [ "$(vp9_encode_available)" = "yes" ]; then
40    echo yes
41  fi
42}
43
44# Echo vpxenc command line parameters allowing use of
45# hantro_collage_w352h288.yuv as input.
46yuv_input_hantro_collage() {
47  echo ""${YUV_RAW_INPUT}"
48       --width="${YUV_RAW_INPUT_WIDTH}"
49       --height="${YUV_RAW_INPUT_HEIGHT}""
50}
51
52# Echo default vpxenc real time encoding params. $1 is the codec, which defaults
53# to vp8 if unspecified.
54vpxenc_rt_params() {
55  local readonly codec="${1:-vp8}"
56  echo "--codec=${codec}
57    --buf-initial-sz=500
58    --buf-optimal-sz=600
59    --buf-sz=1000
60    --cpu-used=-5
61    --end-usage=cbr
62    --error-resilient=1
63    --kf-max-dist=90000
64    --lag-in-frames=0
65    --max-intra-rate=300
66    --max-q=56
67    --min-q=2
68    --noise-sensitivity=0
69    --overshoot-pct=50
70    --passes=1
71    --profile=0
72    --resize-allowed=0
73    --rt
74    --static-thresh=0
75    --undershoot-pct=50"
76}
77
78# Wrapper function for running vpxenc with pipe input. Requires that
79# LIBVPX_BIN_PATH points to the directory containing vpxenc. $1 is used as the
80# input file path and shifted away. All remaining parameters are passed through
81# to vpxenc.
82vpxenc_pipe() {
83  local readonly encoder="$(vpx_tool_path vpxenc)"
84  local readonly input="$1"
85  shift
86  cat "${input}" | eval "${VPX_TEST_PREFIX}" "${encoder}" - \
87    --test-decode=fatal \
88    "$@" ${devnull}
89}
90
91# Wrapper function for running vpxenc. Requires that LIBVPX_BIN_PATH points to
92# the directory containing vpxenc. $1 one is used as the input file path and
93# shifted away. All remaining parameters are passed through to vpxenc.
94vpxenc() {
95  local readonly encoder="$(vpx_tool_path vpxenc)"
96  local readonly input="$1"
97  shift
98  eval "${VPX_TEST_PREFIX}" "${encoder}" "${input}" \
99    --test-decode=fatal \
100    "$@" ${devnull}
101}
102
103vpxenc_vp8_ivf() {
104  if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then
105    local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8.ivf"
106    vpxenc $(yuv_input_hantro_collage) \
107      --codec=vp8 \
108      --limit="${TEST_FRAMES}" \
109      --ivf \
110      --output="${output}"
111
112    if [ ! -e "${output}" ]; then
113      elog "Output file does not exist."
114      return 1
115    fi
116  fi
117}
118
119vpxenc_vp8_webm() {
120  if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
121     [ "$(webm_io_available)" = "yes" ]; then
122    local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8.webm"
123    vpxenc $(yuv_input_hantro_collage) \
124      --codec=vp8 \
125      --limit="${TEST_FRAMES}" \
126      --output="${output}"
127
128    if [ ! -e "${output}" ]; then
129      elog "Output file does not exist."
130      return 1
131    fi
132  fi
133}
134
135vpxenc_vp8_webm_rt() {
136  if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
137     [ "$(webm_io_available)" = "yes" ]; then
138    local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8_rt.webm"
139    vpxenc $(yuv_input_hantro_collage) \
140      $(vpxenc_rt_params vp8) \
141      --output="${output}"
142    if [ ! -e "${output}" ]; then
143      elog "Output file does not exist."
144      return 1
145    fi
146  fi
147}
148
149vpxenc_vp8_webm_2pass() {
150  if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
151     [ "$(webm_io_available)" = "yes" ]; then
152    local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8.webm"
153    vpxenc $(yuv_input_hantro_collage) \
154      --codec=vp8 \
155      --limit="${TEST_FRAMES}" \
156      --output="${output}" \
157      --passes=2
158
159    if [ ! -e "${output}" ]; then
160      elog "Output file does not exist."
161      return 1
162    fi
163  fi
164}
165
166vpxenc_vp8_webm_lag10_frames20() {
167  if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
168     [ "$(webm_io_available)" = "yes" ]; then
169    local readonly lag_total_frames=20
170    local readonly lag_frames=10
171    local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8_lag10_frames20.webm"
172    vpxenc $(yuv_input_hantro_collage) \
173      --codec=vp8 \
174      --limit="${lag_total_frames}" \
175      --lag-in-frames="${lag_frames}" \
176      --output="${output}" \
177      --auto-alt-ref=1 \
178      --passes=2
179
180    if [ ! -e "${output}" ]; then
181      elog "Output file does not exist."
182      return 1
183    fi
184  fi
185}
186
187vpxenc_vp8_ivf_piped_input() {
188  if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then
189    local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8_piped_input.ivf"
190    vpxenc_pipe $(yuv_input_hantro_collage) \
191      --codec=vp8 \
192      --limit="${TEST_FRAMES}" \
193      --ivf \
194      --output="${output}"
195
196    if [ ! -e "${output}" ]; then
197      elog "Output file does not exist."
198      return 1
199    fi
200  fi
201}
202
203vpxenc_vp9_ivf() {
204  if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
205    local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.ivf"
206    vpxenc $(yuv_input_hantro_collage) \
207      --codec=vp9 \
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
219vpxenc_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_input_hantro_collage) \
224      --codec=vp9 \
225      --limit="${TEST_FRAMES}" \
226      --output="${output}"
227
228    if [ ! -e "${output}" ]; then
229      elog "Output file does not exist."
230      return 1
231    fi
232  fi
233}
234
235vpxenc_vp9_webm_rt() {
236  if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
237     [ "$(webm_io_available)" = "yes" ]; then
238    local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_rt.webm"
239    vpxenc $(yuv_input_hantro_collage) \
240      $(vpxenc_rt_params vp9) \
241      --output="${output}"
242
243    if [ ! -e "${output}" ]; then
244      elog "Output file does not exist."
245      return 1
246    fi
247  fi
248}
249
250vpxenc_vp9_webm_2pass() {
251  if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
252     [ "$(webm_io_available)" = "yes" ]; then
253    local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.webm"
254    vpxenc $(yuv_input_hantro_collage) \
255      --codec=vp9 \
256      --limit="${TEST_FRAMES}" \
257      --output="${output}" \
258      --passes=2
259
260    if [ ! -e "${output}" ]; then
261      elog "Output file does not exist."
262      return 1
263    fi
264  fi
265}
266
267vpxenc_vp9_ivf_lossless() {
268  if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
269    local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless.ivf"
270    vpxenc $(yuv_input_hantro_collage) \
271      --codec=vp9 \
272      --limit="${TEST_FRAMES}" \
273      --ivf \
274      --output="${output}" \
275      --lossless=1
276
277    if [ ! -e "${output}" ]; then
278      elog "Output file does not exist."
279      return 1
280    fi
281  fi
282}
283
284vpxenc_vp9_ivf_minq0_maxq0() {
285  if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
286    local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless_minq0_maxq0.ivf"
287    vpxenc $(yuv_input_hantro_collage) \
288      --codec=vp9 \
289      --limit="${TEST_FRAMES}" \
290      --ivf \
291      --output="${output}" \
292      --min-q=0 \
293      --max-q=0
294
295    if [ ! -e "${output}" ]; then
296      elog "Output file does not exist."
297      return 1
298    fi
299  fi
300}
301
302vpxenc_vp9_webm_lag10_frames20() {
303  if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
304     [ "$(webm_io_available)" = "yes" ]; then
305    local readonly lag_total_frames=20
306    local readonly lag_frames=10
307    local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lag10_frames20.webm"
308    vpxenc $(yuv_input_hantro_collage) \
309      --codec=vp9 \
310      --limit="${lag_total_frames}" \
311      --lag-in-frames="${lag_frames}" \
312      --output="${output}" \
313      --passes=2 \
314      --auto-alt-ref=1
315
316    if [ ! -e "${output}" ]; then
317      elog "Output file does not exist."
318      return 1
319    fi
320  fi
321}
322
323vpxenc_tests="vpxenc_vp8_ivf
324              vpxenc_vp8_webm
325              vpxenc_vp8_webm_rt
326              vpxenc_vp8_webm_2pass
327              vpxenc_vp8_webm_lag10_frames20
328              vpxenc_vp8_ivf_piped_input
329              vpxenc_vp9_ivf
330              vpxenc_vp9_webm
331              vpxenc_vp9_webm_rt
332              vpxenc_vp9_webm_2pass
333              vpxenc_vp9_ivf_lossless
334              vpxenc_vp9_ivf_minq0_maxq0
335              vpxenc_vp9_webm_lag10_frames20"
336
337run_tests vpxenc_verify_environment "${vpxenc_tests}"
338