]> granicus.if.org Git - libvpx/blob - test/vpxenc.sh
Merge "examples.sh: Run all example tests."
[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   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}" - "$@" ${devnull}
53 }
54
55 # Wrapper function for running vpxenc. Requires that LIBVPX_BIN_PATH points to
56 # the directory containing vpxenc. $1 one is used as the input file path and
57 # shifted away. All remaining parameters are passed through to vpxenc.
58 vpxenc() {
59   local readonly encoder="$(vpx_tool_path vpxenc)"
60   local readonly input="${1}"
61   shift
62   eval "${VPX_TEST_PREFIX}" "${encoder}" "$input" "$@" ${devnull}
63 }
64
65 vpxenc_vp8_ivf() {
66   if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then
67     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8.ivf"
68     vpxenc --codec=vp8 \
69       --width="${YUV_RAW_INPUT_WIDTH}" \
70       --height="${YUV_RAW_INPUT_HEIGHT}" \
71       --limit="${TEST_FRAMES}" \
72       --ivf \
73       --output="${output}" \
74       "${YUV_RAW_INPUT}"
75
76     if [ ! -e "${output}" ]; then
77       elog "Output file does not exist."
78       return 1
79     fi
80   fi
81 }
82
83 vpxenc_vp8_ivf_piped_input() {
84   if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then
85     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8_piped_input.ivf"
86     cat "${YUV_RAW_INPUT}" \
87       | vpxenc --codec=vp8 \
88         --width="${YUV_RAW_INPUT_WIDTH}" \
89         --height="${YUV_RAW_INPUT_HEIGHT}" \
90         --limit="${TEST_FRAMES}" \
91         --ivf \
92         --output="${output}" \
93         -
94
95     if [ ! -e "${output}" ]; then
96       elog "Output file does not exist."
97       return 1
98     fi
99   fi
100 }
101
102 vpxenc_vp8_webm() {
103   if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
104      [ "$(webm_io_available)" = "yes" ]; then
105     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8.webm"
106     vpxenc --codec=vp8 \
107       --width="${YUV_RAW_INPUT_WIDTH}" \
108       --height="${YUV_RAW_INPUT_HEIGHT}" \
109       --limit="${TEST_FRAMES}" \
110       --output="${output}" \
111       "${YUV_RAW_INPUT}"
112
113     if [ ! -e "${output}" ]; then
114       elog "Output file does not exist."
115       return 1
116     fi
117   fi
118 }
119
120 vpxenc_vp9_ivf() {
121   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
122     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.ivf"
123     vpxenc --codec=vp9 \
124       --width="${YUV_RAW_INPUT_WIDTH}" \
125       --height="${YUV_RAW_INPUT_HEIGHT}" \
126       --limit="${TEST_FRAMES}" \
127       --ivf \
128       --test-decode=fatal \
129       --output="${output}" \
130       "${YUV_RAW_INPUT}"
131
132     if [ ! -e "${output}" ]; then
133       elog "Output file does not exist."
134       return 1
135     fi
136   fi
137 }
138
139 vpxenc_vp9_webm() {
140   if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
141      [ "$(webm_io_available)" = "yes" ]; then
142     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.webm"
143     vpxenc --codec=vp9 \
144       --width="${YUV_RAW_INPUT_WIDTH}" \
145       --height="${YUV_RAW_INPUT_HEIGHT}" \
146       --limit="${TEST_FRAMES}" \
147       --test-decode=fatal \
148       --output="${output}" \
149       "${YUV_RAW_INPUT}"
150
151     if [ ! -e "${output}" ]; then
152       elog "Output file does not exist."
153       return 1
154     fi
155   fi
156 }
157
158 vpxenc_vp9_ivf_lossless() {
159   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
160     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless.ivf"
161     vpxenc --codec=vp9 \
162       --width="${YUV_RAW_INPUT_WIDTH}" \
163       --height="${YUV_RAW_INPUT_HEIGHT}" \
164       --limit="${TEST_FRAMES}" \
165       --ivf \
166       --output="${output}" \
167       --lossless=1 \
168       --test-decode=fatal \
169       "${YUV_RAW_INPUT}"
170
171     if [ ! -e "${output}" ]; then
172       elog "Output file does not exist."
173       return 1
174     fi
175   fi
176 }
177
178 vpxenc_vp9_ivf_minq0_maxq0() {
179   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
180     local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless_minq0_maxq0.ivf"
181     vpxenc --codec=vp9 \
182       --width="${YUV_RAW_INPUT_WIDTH}" \
183       --height="${YUV_RAW_INPUT_HEIGHT}" \
184       --limit="${TEST_FRAMES}" \
185       --ivf \
186       --output="${output}" \
187       --min-q=0 \
188       --max-q=0 \
189       --test-decode=fatal \
190       "${YUV_RAW_INPUT}"
191
192     if [ ! -e "${output}" ]; then
193       elog "Output file does not exist."
194       return 1
195     fi
196   fi
197 }
198
199 vpxenc_tests="vpxenc_vp8_ivf
200               vpxenc_vp8_webm
201               vpxenc_vp8_ivf_piped_input
202               vpxenc_vp9_ivf
203               vpxenc_vp9_webm
204               vpxenc_vp9_ivf_lossless
205               vpxenc_vp9_ivf_minq0_maxq0"
206
207 run_tests vpxenc_verify_environment "${vpxenc_tests}"