]> granicus.if.org Git - libvpx/blob - test/vpxenc.sh
Merge "inline vpx functions in headers to avoid unused function warning"
[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     echo "The file ${YUV_RAW_INPUT##*/} must exist in LIBVPX_TEST_DATA_PATH."
24     return 1
25   fi
26 }
27
28 vpxenc_can_encode_vp8() {
29   if [ "$(vpxenc_available)" = "yes" ] && \
30      [ "$(vp8_encode_available)" = "yes" ]; then
31     echo yes
32   fi
33 }
34
35 vpxenc_can_encode_vp9() {
36   if [ "$(vpxenc_available)" = "yes" ] && \
37      [ "$(vp9_encode_available)" = "yes" ]; then
38     echo yes
39   fi
40 }
41
42 # Echoes yes to stdout when vpxenc exists according to vpx_tool_available().
43 vpxenc_available() {
44   [ -n "$(vpx_tool_available vpxenc)" ] && echo yes
45 }
46
47 # Wrapper function for running vpxenc with pipe input. Requires that
48 # LIBVPX_BIN_PATH points to the directory containing vpxenc. $1 is used as the
49 # input file path and shifted away. All remaining parameters are passed through
50 # to vpxenc.
51 vpxenc_pipe() {
52   local readonly encoder="${LIBVPX_BIN_PATH}/vpxenc${VPX_TEST_EXE_SUFFIX}"
53   local readonly input="$1"
54   shift
55   cat "${input}" | eval "${VPX_TEST_PREFIX}" "${encoder}" - "$@" ${devnull}
56 }
57
58 # Wrapper function for running vpxenc. Requires that LIBVPX_BIN_PATH points to
59 # the directory containing vpxenc. $1 one is used as the input file path and
60 # shifted away. All remaining parameters are passed through to vpxenc.
61 vpxenc() {
62   local readonly encoder="${LIBVPX_BIN_PATH}/vpxenc${VPX_TEST_EXE_SUFFIX}"
63   local readonly input="${1}"
64   shift
65   eval "${VPX_TEST_PREFIX}" "${encoder}" "$input" "$@" ${devnull}
66 }
67
68 vpxenc_vp8_ivf() {
69   if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then
70     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8.ivf"
71     vpxenc --codec=vp8 \
72       --width="${YUV_RAW_INPUT_WIDTH}" \
73       --height="${YUV_RAW_INPUT_HEIGHT}" \
74       --limit="${TEST_FRAMES}" \
75       --ivf \
76       --output="${output}" \
77       "${YUV_RAW_INPUT}"
78
79     if [ ! -e "${output}" ]; then
80       elog "Output file does not exist."
81       return 1
82     fi
83   fi
84 }
85
86 vpxenc_vp8_ivf_piped_input() {
87   if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then
88     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8_piped_input.ivf"
89     cat "${YUV_RAW_INPUT}" \
90       | vpxenc --codec=vp8 \
91         --width="${YUV_RAW_INPUT_WIDTH}" \
92         --height="${YUV_RAW_INPUT_HEIGHT}" \
93         --limit="${TEST_FRAMES}" \
94         --ivf \
95         --output="${output}" \
96         -
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() {
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       "${YUV_RAW_INPUT}"
115
116     if [ ! -e "${output}" ]; then
117       elog "Output file does not exist."
118       return 1
119     fi
120   fi
121 }
122
123 vpxenc_vp9_ivf() {
124   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
125     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.ivf"
126     vpxenc --codec=vp9 \
127       --width="${YUV_RAW_INPUT_WIDTH}" \
128       --height="${YUV_RAW_INPUT_HEIGHT}" \
129       --limit="${TEST_FRAMES}" \
130       --ivf \
131       --output="${output}" \
132       "${YUV_RAW_INPUT}"
133
134     if [ ! -e "${output}" ]; then
135       elog "Output file does not exist."
136       return 1
137     fi
138   fi
139 }
140
141 vpxenc_vp9_webm() {
142   if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
143      [ "$(webm_io_available)" = "yes" ]; then
144     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.webm"
145     vpxenc --codec=vp9 \
146       --width="${YUV_RAW_INPUT_WIDTH}" \
147       --height="${YUV_RAW_INPUT_HEIGHT}" \
148       --limit="${TEST_FRAMES}" \
149       --output="${output}" \
150       "${YUV_RAW_INPUT}"
151
152     if [ ! -e "${output}" ]; then
153       elog "Output file does not exist."
154       return 1
155     fi
156   fi
157 }
158
159 vpxenc_vp9_ivf_lossless() {
160   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
161     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless.ivf"
162     vpxenc --codec=vp9 \
163       --width="${YUV_RAW_INPUT_WIDTH}" \
164       --height="${YUV_RAW_INPUT_HEIGHT}" \
165       --limit="${TEST_FRAMES}" \
166       --ivf \
167       --output="${output}" \
168       --lossless=1 \
169       --test-decode=fatal \
170       "${YUV_RAW_INPUT}"
171
172     if [ ! -e "${output}" ]; then
173       elog "Output file does not exist."
174       return 1
175     fi
176   fi
177 }
178
179 vpxenc_vp9_ivf_minq0_maxq0() {
180   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
181     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless_minq0_maxq0.ivf"
182     vpxenc --codec=vp9 \
183       --width="${YUV_RAW_INPUT_WIDTH}" \
184       --height="${YUV_RAW_INPUT_HEIGHT}" \
185       --limit="${TEST_FRAMES}" \
186       --ivf \
187       --output="${output}" \
188       --min-q=0 \
189       --max-q=0 \
190       --test-decode=fatal \
191       "${YUV_RAW_INPUT}"
192
193     if [ ! -e "${output}" ]; then
194       elog "Output file does not exist."
195       return 1
196     fi
197   fi
198 }
199
200 vpxenc_tests="vpxenc_vp8_ivf
201               vpxenc_vp8_webm
202               vpxenc_vp8_ivf_piped_input
203               vpxenc_vp9_ivf
204               vpxenc_vp9_webm
205               vpxenc_vp9_ivf_lossless
206               vpxenc_vp9_ivf_minq0_maxq0"
207
208 run_tests vpxenc_verify_environment "${vpxenc_tests}"