• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
18readonly TEST_FRAMES=10
19
20# Environment check: Make sure input is available.
21vpxenc_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
39vpxenc_can_encode_vp8() {
40  if [ "$(vp8_encode_available)" = "yes" ]; then
41    echo yes
42  fi
43}
44
45vpxenc_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.
53yuv_input_hantro_collage() {
54  echo ""${YUV_RAW_INPUT}"
55       --width="${YUV_RAW_INPUT_WIDTH}"
56       --height="${YUV_RAW_INPUT_HEIGHT}""
57}
58
59y4m_input_non_square_par() {
60  echo ""${Y4M_NOSQ_PAR_INPUT}""
61}
62
63y4m_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.
69vpxenc_rt_params() {
70  local 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.
94vpxenc_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.
106vpxenc_pipe() {
107  local encoder="$(vpx_tool_path vpxenc)"
108  local 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.
118vpxenc() {
119  local encoder="$(vpx_tool_path vpxenc)"
120  local input="$1"
121  shift
122  eval "${VPX_TEST_PREFIX}" "${encoder}" "${input}" \
123    --test-decode=fatal \
124    "$@" ${devnull}
125}
126
127vpxenc_vp8_ivf() {
128  if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then
129    local 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
143vpxenc_vp8_webm() {
144  if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
145     [ "$(webm_io_available)" = "yes" ]; then
146    local 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
159vpxenc_vp8_webm_rt() {
160  if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
161     [ "$(webm_io_available)" = "yes" ]; then
162    local 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
173vpxenc_vp8_webm_2pass() {
174  if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
175     [ "$(webm_io_available)" = "yes" ]; then
176    local 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
190vpxenc_vp8_webm_lag10_frames20() {
191  if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && \
192     [ "$(webm_io_available)" = "yes" ]; then
193    local lag_total_frames=20
194    local lag_frames=10
195    local 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
211vpxenc_vp8_ivf_piped_input() {
212  if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then
213    local 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
227vpxenc_vp9_ivf() {
228  if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
229    local output="${VPX_TEST_OUTPUT_DIR}/vp9.ivf"
230    local 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
245vpxenc_vp9_webm() {
246  if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
247     [ "$(webm_io_available)" = "yes" ]; then
248    local output="${VPX_TEST_OUTPUT_DIR}/vp9.webm"
249    local 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
263vpxenc_vp9_webm_rt() {
264  if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
265     [ "$(webm_io_available)" = "yes" ]; then
266    local 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
278vpxenc_vp9_webm_rt_multithread_tiled() {
279  if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
280     [ "$(webm_io_available)" = "yes" ]; then
281    local output="${VPX_TEST_OUTPUT_DIR}/vp9_rt_multithread_tiled.webm"
282    local tilethread_min=2
283    local tilethread_max=4
284    local num_threads="$(seq ${tilethread_min} ${tilethread_max})"
285    local 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
295        if [ ! -e "${output}" ]; then
296          elog "Output file does not exist."
297          return 1
298        fi
299        rm "${output}"
300      done
301    done
302  fi
303}
304
305vpxenc_vp9_webm_rt_multithread_tiled_frameparallel() {
306  if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
307     [ "$(webm_io_available)" = "yes" ]; then
308    local output="${VPX_TEST_OUTPUT_DIR}/vp9_rt_mt_t_fp.webm"
309    local tilethread_min=2
310    local tilethread_max=4
311    local num_threads="$(seq ${tilethread_min} ${tilethread_max})"
312    local num_tile_cols="$(seq ${tilethread_min} ${tilethread_max})"
313
314    for threads in ${num_threads}; do
315      for tile_cols in ${num_tile_cols}; do
316        vpxenc $(y4m_input_720p) \
317          $(vpxenc_rt_params vp9) \
318          --threads=${threads} \
319          --tile-columns=${tile_cols} \
320          --frame-parallel=1 \
321          --output="${output}"
322        if [ ! -e "${output}" ]; then
323          elog "Output file does not exist."
324          return 1
325        fi
326        rm "${output}"
327      done
328    done
329  fi
330}
331
332vpxenc_vp9_webm_2pass() {
333  if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
334     [ "$(webm_io_available)" = "yes" ]; then
335    local output="${VPX_TEST_OUTPUT_DIR}/vp9.webm"
336    vpxenc $(yuv_input_hantro_collage) \
337      --codec=vp9 \
338      --limit="${TEST_FRAMES}" \
339      --output="${output}" \
340      --passes=2
341
342    if [ ! -e "${output}" ]; then
343      elog "Output file does not exist."
344      return 1
345    fi
346  fi
347}
348
349vpxenc_vp9_ivf_lossless() {
350  if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
351    local output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless.ivf"
352    local passes=$(vpxenc_passes_param)
353    vpxenc $(yuv_input_hantro_collage) \
354      --codec=vp9 \
355      --limit="${TEST_FRAMES}" \
356      --ivf \
357      --output="${output}" \
358      "${passes}" \
359      --lossless=1
360
361    if [ ! -e "${output}" ]; then
362      elog "Output file does not exist."
363      return 1
364    fi
365  fi
366}
367
368vpxenc_vp9_ivf_minq0_maxq0() {
369  if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
370    local output="${VPX_TEST_OUTPUT_DIR}/vp9_lossless_minq0_maxq0.ivf"
371    local passes=$(vpxenc_passes_param)
372    vpxenc $(yuv_input_hantro_collage) \
373      --codec=vp9 \
374      --limit="${TEST_FRAMES}" \
375      --ivf \
376      --output="${output}" \
377      "${passes}" \
378      --min-q=0 \
379      --max-q=0
380
381    if [ ! -e "${output}" ]; then
382      elog "Output file does not exist."
383      return 1
384    fi
385  fi
386}
387
388vpxenc_vp9_webm_lag10_frames20() {
389  if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
390     [ "$(webm_io_available)" = "yes" ]; then
391    local lag_total_frames=20
392    local lag_frames=10
393    local output="${VPX_TEST_OUTPUT_DIR}/vp9_lag10_frames20.webm"
394    local passes=$(vpxenc_passes_param)
395    vpxenc $(yuv_input_hantro_collage) \
396      --codec=vp9 \
397      --limit="${lag_total_frames}" \
398      --lag-in-frames="${lag_frames}" \
399      --output="${output}" \
400      "${passes}" \
401      --auto-alt-ref=1
402
403    if [ ! -e "${output}" ]; then
404      elog "Output file does not exist."
405      return 1
406    fi
407  fi
408}
409
410# TODO(fgalligan): Test that DisplayWidth is different than video width.
411vpxenc_vp9_webm_non_square_par() {
412  if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && \
413     [ "$(webm_io_available)" = "yes" ]; then
414    local output="${VPX_TEST_OUTPUT_DIR}/vp9_non_square_par.webm"
415    local passes=$(vpxenc_passes_param)
416    vpxenc $(y4m_input_non_square_par) \
417      --codec=vp9 \
418      --limit="${TEST_FRAMES}" \
419      "${passes}" \
420      --output="${output}"
421
422    if [ ! -e "${output}" ]; then
423      elog "Output file does not exist."
424      return 1
425    fi
426  fi
427}
428
429vpxenc_vp9_webm_sharpness() {
430  if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then
431    local sharpnesses="0 1 2 3 4 5 6 7"
432    local output="${VPX_TEST_OUTPUT_DIR}/vpxenc_vp9_webm_sharpness.ivf"
433    local last_size=0
434    local this_size=0
435
436    for sharpness in ${sharpnesses}; do
437
438      vpxenc $(yuv_input_hantro_collage) \
439        --sharpness="${sharpness}" \
440        --codec=vp9 \
441        --limit=1 \
442        --cpu-used=2 \
443        --end-usage=q \
444        --cq-level=40 \
445        --output="${output}" \
446        "${passes}"
447
448      if [ ! -e "${output}" ]; then
449        elog "Output file does not exist."
450        return 1
451      fi
452
453      this_size=$(stat -c '%s' "${output}")
454      if [ "${this_size}" -lt "${last_size}" ]; then
455        elog "Higher sharpness value yielded lower file size."
456        echo "${this_size}" " < " "${last_size}"
457        return 1
458      fi
459      last_size="${this_size}"
460
461    done
462  fi
463}
464
465vpxenc_tests="vpxenc_vp8_ivf
466              vpxenc_vp8_webm
467              vpxenc_vp8_webm_rt
468              vpxenc_vp8_ivf_piped_input
469              vpxenc_vp9_ivf
470              vpxenc_vp9_webm
471              vpxenc_vp9_webm_rt
472              vpxenc_vp9_webm_rt_multithread_tiled
473              vpxenc_vp9_webm_rt_multithread_tiled_frameparallel
474              vpxenc_vp9_ivf_lossless
475              vpxenc_vp9_ivf_minq0_maxq0
476              vpxenc_vp9_webm_lag10_frames20
477              vpxenc_vp9_webm_non_square_par
478              vpxenc_vp9_webm_sharpness"
479
480if [ "$(vpx_config_option_enabled CONFIG_REALTIME_ONLY)" != "yes" ]; then
481  vpxenc_tests="$vpxenc_tests
482                vpxenc_vp8_webm_2pass
483                vpxenc_vp8_webm_lag10_frames20
484                vpxenc_vp9_webm_2pass"
485fi
486
487run_tests vpxenc_verify_environment "${vpxenc_tests}"
488