aomenc.sh 6.46 KB
Newer Older
1
#!/bin/sh
Yaowu Xu's avatar
Yaowu Xu committed
2
## Copyright (c) 2016, Alliance for Open Media. All rights reserved
3
##
Yaowu Xu's avatar
Yaowu Xu committed
4
5
6
7
8
9
## This source code is subject to the terms of the BSD 2 Clause License and
## the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
## was not distributed with this source code in the LICENSE file, you can
## obtain it at www.aomedia.org/license/software. If the Alliance for Open
## Media Patent License 1.0 was not distributed with this source code in the
## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10
##
Yaowu Xu's avatar
Yaowu Xu committed
11
12
13
14
## This file tests aomenc using hantro_collage_w352h288.yuv as input. To add
## new tests to this file, do the following:
##   1. Write a shell function (this is your test).
##   2. Add the function to aomenc_tests (on a new line).
15
16
17
##
. $(dirname $0)/tools_common.sh

18
readonly TEST_FRAMES=5
19
20

# Environment check: Make sure input is available.
Yaowu Xu's avatar
Yaowu Xu committed
21
aomenc_verify_environment() {
22
  if [ ! -e "${YUV_RAW_INPUT}" ]; then
23
    elog "The file ${YUV_RAW_INPUT##*/} must exist in LIBAOM_TEST_DATA_PATH."
24
25
    return 1
  fi
Yaowu Xu's avatar
Yaowu Xu committed
26
  if [ "$(aomenc_can_encode_av1)" = "yes" ]; then
27
28
    if [ ! -e "${Y4M_NOSQ_PAR_INPUT}" ]; then
      elog "The file ${Y4M_NOSQ_PAR_INPUT##*/} must exist in"
29
      elog "LIBAOM_TEST_DATA_PATH."
30
31
32
      return 1
    fi
  fi
Yaowu Xu's avatar
Yaowu Xu committed
33
34
  if [ -z "$(aom_tool_path aomenc)" ]; then
    elog "aomenc not found. It must exist in LIBAOM_BIN_PATH or its parent."
35
36
    return 1
  fi
37
38
}

Yaowu Xu's avatar
Yaowu Xu committed
39
40
aomenc_can_encode_av1() {
  if [ "$(av1_encode_available)" = "yes" ]; then
41
42
43
44
    echo yes
  fi
}

Yaowu Xu's avatar
Yaowu Xu committed
45
46
aomenc_can_encode_av1() {
  if [ "$(av1_encode_available)" = "yes" ]; then
47
48
49
50
    echo yes
  fi
}

51
# Utilities that echo aomenc input file parameters.
52
53
54
55
y4m_input_non_square_par() {
  echo ""${Y4M_NOSQ_PAR_INPUT}""
}

56
57
58
59
y4m_input_720p() {
  echo ""${Y4M_720P_INPUT}""
}

Yaowu Xu's avatar
Yaowu Xu committed
60
# Echo default aomenc real time encoding params. $1 is the codec, which defaults
Yaowu Xu's avatar
Yaowu Xu committed
61
# to av1 if unspecified.
Yaowu Xu's avatar
Yaowu Xu committed
62
aomenc_rt_params() {
Yaowu Xu's avatar
Yaowu Xu committed
63
  local readonly codec="${1:-av1}"
64
65
66
67
  echo "--codec=${codec}
    --buf-initial-sz=500
    --buf-optimal-sz=600
    --buf-sz=1000
68
    --cpu-used=-6
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
    --end-usage=cbr
    --error-resilient=1
    --kf-max-dist=90000
    --lag-in-frames=0
    --max-intra-rate=300
    --max-q=56
    --min-q=2
    --noise-sensitivity=0
    --overshoot-pct=50
    --passes=1
    --profile=0
    --resize-allowed=0
    --rt
    --static-thresh=0
    --undershoot-pct=50"
}

Yaowu Xu's avatar
Yaowu Xu committed
86
87
# Wrapper function for running aomenc with pipe input. Requires that
# LIBAOM_BIN_PATH points to the directory containing aomenc. $1 is used as the
88
# input file path and shifted away. All remaining parameters are passed through
Yaowu Xu's avatar
Yaowu Xu committed
89
90
91
# to aomenc.
aomenc_pipe() {
  local readonly encoder="$(aom_tool_path aomenc)"
92
93
  local readonly input="$1"
  shift
Yaowu Xu's avatar
Yaowu Xu committed
94
  cat "${input}" | eval "${AOM_TEST_PREFIX}" "${encoder}" - \
95
96
    --test-decode=fatal \
    "$@" ${devnull}
97
}
98

Yaowu Xu's avatar
Yaowu Xu committed
99
100
101
102
103
# Wrapper function for running aomenc. Requires that LIBAOM_BIN_PATH points to
# the directory containing aomenc. $1 one is used as the input file path and
# shifted away. All remaining parameters are passed through to aomenc.
aomenc() {
  local readonly encoder="$(aom_tool_path aomenc)"
Tom Finegan's avatar
Tom Finegan committed
104
  local readonly input="$1"
105
  shift
Yaowu Xu's avatar
Yaowu Xu committed
106
  eval "${AOM_TEST_PREFIX}" "${encoder}" "${input}" \
107
108
    --test-decode=fatal \
    "$@" ${devnull}
109
110
}

Yaowu Xu's avatar
Yaowu Xu committed
111
112
113
aomenc_av1_ivf() {
  if [ "$(aomenc_can_encode_av1)" = "yes" ]; then
    local readonly output="${AOM_TEST_OUTPUT_DIR}/av1.ivf"
114
    aomenc $(yuv_raw_input) \
Yaowu Xu's avatar
Yaowu Xu committed
115
      --codec=av1 \
116
      --limit="${TEST_FRAMES}" \
117
      --ivf \
118
      --output="${output}"
119
120
121
122
123

    if [ ! -e "${output}" ]; then
      elog "Output file does not exist."
      return 1
    fi
124
125
126
  fi
}

Yaowu Xu's avatar
Yaowu Xu committed
127
128
aomenc_av1_webm() {
  if [ "$(aomenc_can_encode_av1)" = "yes" ] && \
129
     [ "$(webm_io_available)" = "yes" ]; then
Yaowu Xu's avatar
Yaowu Xu committed
130
    local readonly output="${AOM_TEST_OUTPUT_DIR}/av1.webm"
131
    aomenc $(yuv_raw_input) \
Yaowu Xu's avatar
Yaowu Xu committed
132
      --codec=av1 \
133
      --limit="${TEST_FRAMES}" \
134
      --output="${output}"
135
136
137
138
139

    if [ ! -e "${output}" ]; then
      elog "Output file does not exist."
      return 1
    fi
140
141
142
  fi
}

Yaowu Xu's avatar
Yaowu Xu committed
143
144
aomenc_av1_webm_2pass() {
  if [ "$(aomenc_can_encode_av1)" = "yes" ] && \
145
     [ "$(webm_io_available)" = "yes" ]; then
Yaowu Xu's avatar
Yaowu Xu committed
146
    local readonly output="${AOM_TEST_OUTPUT_DIR}/av1.webm"
147
    aomenc $(yuv_raw_input) \
Yaowu Xu's avatar
Yaowu Xu committed
148
      --codec=av1 \
149
150
      --limit="${TEST_FRAMES}" \
      --output="${output}" \
151
      --passes=2
152
153
154
155
156

    if [ ! -e "${output}" ]; then
      elog "Output file does not exist."
      return 1
    fi
157
158
159
  fi
}

Yaowu Xu's avatar
Yaowu Xu committed
160
161
162
aomenc_av1_ivf_lossless() {
  if [ "$(aomenc_can_encode_av1)" = "yes" ]; then
    local readonly output="${AOM_TEST_OUTPUT_DIR}/av1_lossless.ivf"
163
    aomenc $(yuv_raw_input) \
Yaowu Xu's avatar
Yaowu Xu committed
164
      --codec=av1 \
165
166
167
      --limit="${TEST_FRAMES}" \
      --ivf \
      --output="${output}" \
168
      --lossless=1
169
170
171
172
173
174
175
176

    if [ ! -e "${output}" ]; then
      elog "Output file does not exist."
      return 1
    fi
  fi
}

Yaowu Xu's avatar
Yaowu Xu committed
177
178
179
aomenc_av1_ivf_minq0_maxq0() {
  if [ "$(aomenc_can_encode_av1)" = "yes" ]; then
    local readonly output="${AOM_TEST_OUTPUT_DIR}/av1_lossless_minq0_maxq0.ivf"
180
    aomenc $(yuv_raw_input) \
Yaowu Xu's avatar
Yaowu Xu committed
181
      --codec=av1 \
182
183
184
185
      --limit="${TEST_FRAMES}" \
      --ivf \
      --output="${output}" \
      --min-q=0 \
186
      --max-q=0
187
188
189
190
191

    if [ ! -e "${output}" ]; then
      elog "Output file does not exist."
      return 1
    fi
192
193
194
  fi
}

195
aomenc_av1_webm_lag5_frames10() {
Yaowu Xu's avatar
Yaowu Xu committed
196
  if [ "$(aomenc_can_encode_av1)" = "yes" ] && \
197
     [ "$(webm_io_available)" = "yes" ]; then
198
199
200
    local readonly lag_total_frames=10
    local readonly lag_frames=5
    local readonly output="${AOM_TEST_OUTPUT_DIR}/av1_lag5_frames10.webm"
201
    aomenc $(yuv_raw_input) \
Yaowu Xu's avatar
Yaowu Xu committed
202
      --codec=av1 \
203
204
205
206
      --limit="${lag_total_frames}" \
      --lag-in-frames="${lag_frames}" \
      --output="${output}" \
      --passes=2 \
207
      --auto-alt-ref=1
208
209
210
211
212
213
214
215

    if [ ! -e "${output}" ]; then
      elog "Output file does not exist."
      return 1
    fi
  fi
}

216
# TODO(fgalligan): Test that DisplayWidth is different than video width.
Yaowu Xu's avatar
Yaowu Xu committed
217
218
aomenc_av1_webm_non_square_par() {
  if [ "$(aomenc_can_encode_av1)" = "yes" ] && \
219
     [ "$(webm_io_available)" = "yes" ]; then
Yaowu Xu's avatar
Yaowu Xu committed
220
221
222
    local readonly output="${AOM_TEST_OUTPUT_DIR}/av1_non_square_par.webm"
    aomenc $(y4m_input_non_square_par) \
      --codec=av1 \
223
224
225
226
227
228
229
230
231
232
      --limit="${TEST_FRAMES}" \
      --output="${output}"

    if [ ! -e "${output}" ]; then
      elog "Output file does not exist."
      return 1
    fi
  fi
}

233
aomenc_tests="aomenc_av1_ivf
Yaowu Xu's avatar
Yaowu Xu committed
234
235
236
237
              aomenc_av1_webm
              aomenc_av1_webm_2pass
              aomenc_av1_ivf_lossless
              aomenc_av1_ivf_minq0_maxq0
238
              aomenc_av1_webm_lag5_frames10
Yaowu Xu's avatar
Yaowu Xu committed
239
240
241
              aomenc_av1_webm_non_square_par"

run_tests aomenc_verify_environment "${aomenc_tests}"