]> granicus.if.org Git - libvpx/blob - test/vpxenc.sh
Merge "vpxenc tests: Relocate vpxenc wrapper."
[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 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. Positional parameters are interpreted as
48 # follows:
49 #   1 - codec name
50 #   2 - input width
51 #   3 - input height
52 #   4 - number of frames to encode
53 #   5 - path to input file
54 #   6 - path to output file
55 #       Note: The output file path must end in .ivf to output an IVF file.
56 #   7 - extra flags
57 #       Note: Extra flags currently supports a special case: when set to "-"
58 #             input is piped to vpxenc via cat.
59 vpxenc() {
60   local encoder="${LIBVPX_BIN_PATH}/vpxenc${VPX_TEST_EXE_SUFFIX}"
61   local codec="${1}"
62   local width=${2}
63   local height=${3}
64   local frames=${4}
65   local input=${5}
66   local output="${VPX_TEST_OUTPUT_DIR}/${6}"
67   local extra_flags=${7}
68
69   # Because --ivf must be within the command line to get IVF from vpxenc.
70   if echo "${output}" | egrep -q 'ivf$'; then
71     use_ivf=--ivf
72   else
73     unset use_ivf
74   fi
75
76   if [ "${extra_flags}" = "-" ]; then
77     pipe_input=yes
78     extra_flags=${8}
79   else
80     unset pipe_input
81   fi
82
83   if [ -z "${pipe_input}" ]; then
84     eval "${VPX_TEST_PREFIX}" "${encoder}" --codec=${codec} --width=${width} \
85         --height=${height} --limit=${frames} ${use_ivf} ${extra_flags} \
86         --output="${output}" "${input}" ${devnull}
87   else
88     cat "${input}" \
89         | eval "${VPX_TEST_PREFIX}" "${encoder}" --codec=${codec} \
90             --width=${width} --height=${height} --limit=${frames} ${use_ivf} \
91             ${extra_flags} --output="${output}" - ${devnull}
92   fi
93
94   if [ ! -e "${output}" ]; then
95     # Return non-zero exit status: output file doesn't exist, so something
96     # definitely went wrong.
97     return 1
98   fi
99 }
100
101 vpxenc_vp8_ivf() {
102   if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then
103     vpxenc vp8 ${YUV_RAW_INPUT_WIDTH} ${YUV_RAW_INPUT_HEIGHT} ${TEST_FRAMES} \
104         "${YUV_RAW_INPUT}" vp8.ivf
105   fi
106 }
107
108 vpxenc_vp8_ivf_pipe_input() {
109   if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then
110     vpxenc vp8 ${YUV_RAW_INPUT_WIDTH} ${YUV_RAW_INPUT_HEIGHT} ${TEST_FRAMES} \
111         "${YUV_RAW_INPUT}" vp8.ivf -
112   fi
113 }
114
115 vpxenc_vp8_webm() {
116   if [ "$(vpxenc_can_encode_vp8)" = "yes" ] &&
117      [ "$(webm_io_available)" = "yes" ] ; then
118     vpxenc vp8 ${YUV_RAW_INPUT_WIDTH} ${YUV_RAW_INPUT_HEIGHT} ${TEST_FRAMES} \
119         "${YUV_RAW_INPUT}" vp8.webm
120   fi
121 }
122
123 vpxenc_vp9_ivf() {
124   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
125     vpxenc vp9 ${YUV_RAW_INPUT_WIDTH} ${YUV_RAW_INPUT_HEIGHT} ${TEST_FRAMES} \
126         "${YUV_RAW_INPUT}" vp9.ivf
127   fi
128 }
129
130 vpxenc_vp9_webm() {
131   if [ "$(vpxenc_can_encode_vp9)" = "yes" ] &&
132      [ "$(webm_io_available)" = "yes" ] ; then
133     vpxenc vp9 ${YUV_RAW_INPUT_WIDTH} ${YUV_RAW_INPUT_HEIGHT} ${TEST_FRAMES} \
134         "${YUV_RAW_INPUT}" vp9.webm
135   fi
136 }
137
138 DISABLED_vpxenc_vp9_ivf_lossless() {
139   if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
140     vpxenc vp9 ${YUV_RAW_INPUT_WIDTH} ${YUV_RAW_INPUT_HEIGHT} ${TEST_FRAMES} \
141         "${YUV_RAW_INPUT}" vp9_lossless.ivf --lossless
142   fi
143 }
144
145 vpxenc_tests="vpxenc_vp8_ivf
146               vpxenc_vp8_webm
147               vpxenc_vp8_ivf_pipe_input
148               vpxenc_vp9_ivf
149               vpxenc_vp9_webm
150               DISABLED_vpxenc_vp9_ivf_lossless"
151
152 run_tests vpxenc_verify_environment "${vpxenc_tests}"