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