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 y4m_input_720p() { 64 echo ""${Y4M_720P_INPUT}"" 65 } 66 67 # Echo default vpxenc real time encoding params. $1 is the codec, which defaults 68 # to vp8 if unspecified. 69 vpxenc_rt_params() { 70 local readonly codec="${1:-vp8}" 71 echo "--codec=${codec} 72 --buf-initial-sz=500 73 --buf-optimal-sz=600 74 --buf-sz=1000 75 --cpu-used=-6 76 --end-usage=cbr 77 --error-resilient=1 78 --kf-max-dist=90000 79 --lag-in-frames=0 80 --max-intra-rate=300 81 --max-q=56 82 --min-q=2 83 --noise-sensitivity=0 84 --overshoot-pct=50 85 --passes=1 86 --profile=0 87 --resize-allowed=0 88 --rt 89 --static-thresh=0 90 --undershoot-pct=50" 91 } 92 93 # Forces --passes to 1 with CONFIG_REALTIME_ONLY. 94 vpxenc_passes_param() { 95 if [ "$(vpx_config_option_enabled CONFIG_REALTIME_ONLY)" = "yes" ]; then 96 echo "--passes=1" 97 else 98 echo "--passes=2" 99 fi 100 } 101 102 # Wrapper function for running vpxenc with pipe input. Requires that 103 # LIBVPX_BIN_PATH points to the directory containing vpxenc. $1 is used as the 104 # input file path and shifted away. All remaining parameters are passed through 105 # to vpxenc. 106 vpxenc_pipe() { 107 local readonly encoder="$(vpx_tool_path vpxenc)" 108 local readonly input="$1" 109 shift 110 cat "${input}" | eval "${VPX_TEST_PREFIX}" "${encoder}" - \ 111 --test-decode=fatal \ 112 "$@" ${devnull} 113 } 114 115 # Wrapper function for running vpxenc. Requires that LIBVPX_BIN_PATH points to 116 # the directory containing vpxenc. $1 one is used as the input file path and 117 # shifted away. All remaining parameters are passed through to vpxenc. 118 vpxenc() { 119 local readonly encoder="$(vpx_tool_path vpxenc)" 120 local readonly input="$1" 121 shift 122 eval "${VPX_TEST_PREFIX}" "${encoder}" "${input}" \ 123 --test-decode=fatal \ 124 "$@" ${devnull} 125 } 126 127 vpxenc_vp8_ivf() { 128 if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then 129 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8.ivf" 130 vpxenc $(yuv_input_hantro_collage) \ 131 --codec=vp8 \ 132 --limit="${TEST_FRAMES}" \ 133 --ivf \ 134 --output="${output}" 135 136 if [ ! -e "${output}" ]; then 137 elog "Output file does not exist." 138 return 1 139 fi 140 fi 141 } 142 143 vpxenc_vp8_webm() { 144 if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \ 145 [ "$(webm_io_available)" = "yes" ]; then 146 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8.webm" 147 vpxenc $(yuv_input_hantro_collage) \ 148 --codec=vp8 \ 149 --limit="${TEST_FRAMES}" \ 150 --output="${output}" 151 152 if [ ! -e "${output}" ]; then 153 elog "Output file does not exist." 154 return 1 155 fi 156 fi 157 } 158 159 vpxenc_vp8_webm_rt() { 160 if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \ 161 [ "$(webm_io_available)" = "yes" ]; then 162 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8_rt.webm" 163 vpxenc $(yuv_input_hantro_collage) \ 164 $(vpxenc_rt_params vp8) \ 165 --output="${output}" 166 if [ ! -e "${output}" ]; then 167 elog "Output file does not exist." 168 return 1 169 fi 170 fi 171 } 172 173 vpxenc_vp8_webm_2pass() { 174 if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \ 175 [ "$(webm_io_available)" = "yes" ]; then 176 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8.webm" 177 vpxenc $(yuv_input_hantro_collage) \ 178 --codec=vp8 \ 179 --limit="${TEST_FRAMES}" \ 180 --output="${output}" \ 181 --passes=2 182 183 if [ ! -e "${output}" ]; then 184 elog "Output file does not exist." 185 return 1 186 fi 187 fi 188 } 189 190 vpxenc_vp8_webm_lag10_frames20() { 191 if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \ 192 [ "$(webm_io_available)" = "yes" ]; then 193 local readonly lag_total_frames=20 194 local readonly lag_frames=10 195 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8_lag10_frames20.webm" 196 vpxenc $(yuv_input_hantro_collage) \ 197 --codec=vp8 \ 198 --limit="${lag_total_frames}" \ 199 --lag-in-frames="${lag_frames}" \ 200 --output="${output}" \ 201 --auto-alt-ref=1 \ 202 --passes=2 203 204 if [ ! -e "${output}" ]; then 205 elog "Output file does not exist." 206 return 1 207 fi 208 fi 209 } 210 211 vpxenc_vp8_ivf_piped_input() { 212 if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then 213 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp8_piped_input.ivf" 214 vpxenc_pipe $(yuv_input_hantro_collage) \ 215 --codec=vp8 \ 216 --limit="${TEST_FRAMES}" \ 217 --ivf \ 218 --output="${output}" 219 220 if [ ! -e "${output}" ]; then 221 elog "Output file does not exist." 222 return 1 223 fi 224 fi 225 } 226 227 vpxenc_vp9_ivf() { 228 if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then 229 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.ivf" 230 local readonly passes=$(vpxenc_passes_param) 231 vpxenc $(yuv_input_hantro_collage) \ 232 --codec=vp9 \ 233 --limit="${TEST_FRAMES}" \ 234 "${passes}" \ 235 --ivf \ 236 --output="${output}" 237 238 if [ ! -e "${output}" ]; then 239 elog "Output file does not exist." 240 return 1 241 fi 242 fi 243 } 244 245 vpxenc_vp9_webm() { 246 if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \ 247 [ "$(webm_io_available)" = "yes" ]; then 248 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.webm" 249 local readonly passes=$(vpxenc_passes_param) 250 vpxenc $(yuv_input_hantro_collage) \ 251 --codec=vp9 \ 252 --limit="${TEST_FRAMES}" \ 253 "${passes}" \ 254 --output="${output}" 255 256 if [ ! -e "${output}" ]; then 257 elog "Output file does not exist." 258 return 1 259 fi 260 fi 261 } 262 263 vpxenc_vp9_webm_rt() { 264 if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \ 265 [ "$(webm_io_available)" = "yes" ]; then 266 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_rt.webm" 267 vpxenc $(yuv_input_hantro_collage) \ 268 $(vpxenc_rt_params vp9) \ 269 --output="${output}" 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_webm_rt_multithread_tiled() { 279 if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \ 280 [ "$(webm_io_available)" = "yes" ]; then 281 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_rt_multithread_tiled.webm" 282 local readonly tilethread_min=2 283 local readonly tilethread_max=4 284 local readonly num_threads="$(seq ${tilethread_min} ${tilethread_max})" 285 local readonly num_tile_cols="$(seq ${tilethread_min} ${tilethread_max})" 286 287 for threads in ${num_threads}; do 288 for tile_cols in ${num_tile_cols}; do 289 vpxenc $(y4m_input_720p) \ 290 $(vpxenc_rt_params vp9) \ 291 --threads=${threads} \ 292 --tile-columns=${tile_cols} \ 293 --output="${output}" 294 done 295 done 296 297 if [ ! -e "${output}" ]; then 298 elog "Output file does not exist." 299 return 1 300 fi 301 302 rm "${output}" 303 fi 304 } 305 306 vpxenc_vp9_webm_rt_multithread_tiled_frameparallel() { 307 if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \ 308 [ "$(webm_io_available)" = "yes" ]; then 309 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_rt_mt_t_fp.webm" 310 local readonly tilethread_min=2 311 local readonly tilethread_max=4 312 local readonly num_threads="$(seq ${tilethread_min} ${tilethread_max})" 313 local readonly num_tile_cols="$(seq ${tilethread_min} ${tilethread_max})" 314 315 for threads in ${num_threads}; do 316 for tile_cols in ${num_tile_cols}; do 317 vpxenc $(y4m_input_720p) \ 318 $(vpxenc_rt_params vp9) \ 319 --threads=${threads} \ 320 --tile-columns=${tile_cols} \ 321 --frame-parallel=1 \ 322 --output="${output}" 323 done 324 done 325 326 if [ ! -e "${output}" ]; then 327 elog "Output file does not exist." 328 return 1 329 fi 330 331 rm "${output}" 332 fi 333 } 334 335 vpxenc_vp9_webm_2pass() { 336 if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \ 337 [ "$(webm_io_available)" = "yes" ]; then 338 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9.webm" 339 vpxenc $(yuv_input_hantro_collage) \ 340 --codec=vp9 \ 341 --limit="${TEST_FRAMES}" \ 342 --output="${output}" \ 343 --passes=2 344 345 if [ ! -e "${output}" ]; then 346 elog "Output file does not exist." 347 return 1 348 fi 349 fi 350 } 351 352 vpxenc_vp9_ivf_lossless() { 353 if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then 354 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless.ivf" 355 local readonly passes=$(vpxenc_passes_param) 356 vpxenc $(yuv_input_hantro_collage) \ 357 --codec=vp9 \ 358 --limit="${TEST_FRAMES}" \ 359 --ivf \ 360 --output="${output}" \ 361 "${passes}" \ 362 --lossless=1 363 364 if [ ! -e "${output}" ]; then 365 elog "Output file does not exist." 366 return 1 367 fi 368 fi 369 } 370 371 vpxenc_vp9_ivf_minq0_maxq0() { 372 if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then 373 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless_minq0_maxq0.ivf" 374 local readonly passes=$(vpxenc_passes_param) 375 vpxenc $(yuv_input_hantro_collage) \ 376 --codec=vp9 \ 377 --limit="${TEST_FRAMES}" \ 378 --ivf \ 379 --output="${output}" \ 380 "${passes}" \ 381 --min-q=0 \ 382 --max-q=0 383 384 if [ ! -e "${output}" ]; then 385 elog "Output file does not exist." 386 return 1 387 fi 388 fi 389 } 390 391 vpxenc_vp9_webm_lag10_frames20() { 392 if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \ 393 [ "$(webm_io_available)" = "yes" ]; then 394 local readonly lag_total_frames=20 395 local readonly lag_frames=10 396 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_lag10_frames20.webm" 397 local readonly passes=$(vpxenc_passes_param) 398 vpxenc $(yuv_input_hantro_collage) \ 399 --codec=vp9 \ 400 --limit="${lag_total_frames}" \ 401 --lag-in-frames="${lag_frames}" \ 402 --output="${output}" \ 403 "${passes}" \ 404 --auto-alt-ref=1 405 406 if [ ! -e "${output}" ]; then 407 elog "Output file does not exist." 408 return 1 409 fi 410 fi 411 } 412 413 # TODO(fgalligan): Test that DisplayWidth is different than video width. 414 vpxenc_vp9_webm_non_square_par() { 415 if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \ 416 [ "$(webm_io_available)" = "yes" ]; then 417 local readonly output="${VPX_TEST_OUTPUT_DIR}/vp9_non_square_par.webm" 418 local readonly passes=$(vpxenc_passes_param) 419 vpxenc $(y4m_input_non_square_par) \ 420 --codec=vp9 \ 421 --limit="${TEST_FRAMES}" \ 422 "${passes}" \ 423 --output="${output}" 424 425 if [ ! -e "${output}" ]; then 426 elog "Output file does not exist." 427 return 1 428 fi 429 fi 430 } 431 432 vpxenc_tests="vpxenc_vp8_ivf 433 vpxenc_vp8_webm 434 vpxenc_vp8_webm_rt 435 vpxenc_vp8_ivf_piped_input 436 vpxenc_vp9_ivf 437 vpxenc_vp9_webm 438 vpxenc_vp9_webm_rt 439 vpxenc_vp9_webm_rt_multithread_tiled 440 vpxenc_vp9_webm_rt_multithread_tiled_frameparallel 441 vpxenc_vp9_ivf_lossless 442 vpxenc_vp9_ivf_minq0_maxq0 443 vpxenc_vp9_webm_lag10_frames20 444 vpxenc_vp9_webm_non_square_par" 445 if [ "$(vpx_config_option_enabled CONFIG_REALTIME_ONLY)" != "yes" ]; then 446 vpxenc_tests="$vpxenc_tests 447 vpxenc_vp8_webm_2pass 448 vpxenc_vp8_webm_lag10_frames20 449 vpxenc_vp9_webm_2pass" 450 fi 451 452 run_tests vpxenc_verify_environment "${vpxenc_tests}" 453