diff options
Diffstat (limited to 'media/libjxl/src/tools/benchmark/hm')
-rw-r--r-- | media/libjxl/src/tools/benchmark/hm/README.md | 12 | ||||
-rwxr-xr-x | media/libjxl/src/tools/benchmark/hm/decode.sh | 98 | ||||
-rwxr-xr-x | media/libjxl/src/tools/benchmark/hm/encode.sh | 97 |
3 files changed, 207 insertions, 0 deletions
diff --git a/media/libjxl/src/tools/benchmark/hm/README.md b/media/libjxl/src/tools/benchmark/hm/README.md new file mode 100644 index 0000000000..e54904eff9 --- /dev/null +++ b/media/libjxl/src/tools/benchmark/hm/README.md @@ -0,0 +1,12 @@ +This directory contains encoding and decoding scripts for HEVC, for use with +the benchmark custom codec. They use the HEVC reference encoder at https://hevc.hhi.fraunhofer.de/svn/svn_HEVCSoftware/ +and require the `TAppEncoderHighBitDepthStatic` and +`TAppDecoderHighBitDepthStatic` binaries to be placed in this directory. + +Example usage, for encoding at QP = 30: + +``` +tools/benchmark_xl --input=image.png --codec='custom:bin:.../tools/benchmark/hm/encode.sh:.../tools/benchmark/hm/decode.sh:-q:30' +``` + +The paths to the encode and decode scripts should be adjusted as necessary. diff --git a/media/libjxl/src/tools/benchmark/hm/decode.sh b/media/libjxl/src/tools/benchmark/hm/decode.sh new file mode 100755 index 0000000000..624c8ba729 --- /dev/null +++ b/media/libjxl/src/tools/benchmark/hm/decode.sh @@ -0,0 +1,98 @@ +#!/usr/bin/env bash + +# Copyright (c) the JPEG XL Project Authors. All rights reserved. +# +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +set -euo pipefail + +decoder="$(dirname "$0")"/TAppDecoderHighBitDepthStatic + +usage() { + echo "$0 [-v] <input.bin> <output.png>" >&2 + exit 1 +} + +verbose=0 + +while getopts ':hv' arg; do + case "$arg" in + h) + usage + ;; + + v) + verbose=1 + ;; + + \?) + echo "Unrecognized option -$OPTARG" >&2 + exit 1 + ;; + esac +done +shift $((OPTIND-1)) + +if [ $# -lt 2 ]; then + usage +fi + +run() { + if [ "$verbose" -eq 1 ]; then + "$@" + else + "$@" > /dev/null 2>&1 + fi +} + +input="$1" +output="$2" + +bin="$(mktemp)" +yuv="$(mktemp)" +width_file="$(mktemp)" +height_file="$(mktemp)" +icc_file="$(mktemp --suffix=.icc)" + +cleanup() { + rm -- "$bin" "$yuv" "$width_file" "$height_file" "$icc_file" +} +trap cleanup EXIT + +unpack_program="$(cat <<'END' + use File::Copy; + my ($input, $bin, $width_file, $height_file, $icc_file) = @ARGV; + open my $input_fh, '<:raw', $input; + sysread($input_fh, my $size, 8) == 8 or die; + my ($width, $height) = unpack 'NN', $size; + open my $width_fh, '>', $width_file; + print {$width_fh} "$width\n"; + open my $height_fh, '>', $height_file; + print {$height_fh} "$height\n"; + sysread($input_fh, my $icc_size, 4) == 4 or die; + $icc_size = unpack 'N', $icc_size; + sysread($input_fh, my $icc_data, $icc_size) == $icc_size or die; + open my $icc_fh, '>', $icc_file; + print {$icc_fh} $icc_data; + copy $input_fh, $bin; +END +)" +run perl -Mstrict -Mwarnings -Mautodie -e "$unpack_program" -- "$input" "$bin" "$width_file" "$height_file" "$icc_file" + +width="$(cat "$width_file")" +height="$(cat "$height_file")" + +start="$EPOCHREALTIME" +run "$decoder" --OutputBitDepth=10 -b "$bin" -o "$yuv" +end="$EPOCHREALTIME" + +elapsed="$(echo "$end - $start" | bc)" +run echo "Completed in $elapsed seconds" + +echo "$elapsed" > "${output%.png}".time + +run ffmpeg -hide_banner -f rawvideo -vcodec rawvideo -s "${width}x$height" -r 25 -pix_fmt yuv444p10le -i "$yuv" -pix_fmt rgb24 -vf scale=in_color_matrix=bt709 -y "$output" +if [ -s "$icc_file" ]; then + mogrify -profile "$icc_file" "$output" +fi diff --git a/media/libjxl/src/tools/benchmark/hm/encode.sh b/media/libjxl/src/tools/benchmark/hm/encode.sh new file mode 100755 index 0000000000..319ba6953c --- /dev/null +++ b/media/libjxl/src/tools/benchmark/hm/encode.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash + +# Copyright (c) the JPEG XL Project Authors. All rights reserved. +# +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file. + +set -euo pipefail + +encoder="$(dirname "$0")"/TAppEncoderHighBitDepthStatic +cfg_dir="$(dirname "$0")"/../../../third_party/HEVCSoftware/cfg + +usage() { + echo "$0 [-v] [-q <N>] <input.png> <output.bin>" >&2 + exit 1 +} + +q=27 +verbose=0 + +while getopts ':hq:v' arg; do + case "$arg" in + h) + usage + ;; + + q) + q="$OPTARG" + ;; + + v) + verbose=1 + ;; + + \?) + echo "Unrecognized option -$OPTARG" >&2 + exit 1 + ;; + esac +done +shift $((OPTIND-1)) + +if [ $# -lt 2 ]; then + usage +fi + +run() { + if [ "$verbose" -eq 1 ]; then + "$@" + else + "$@" > /dev/null 2>&1 + fi +} + +input="$1" +output="$2" + +yuv="$(mktemp)" +bin="$(mktemp)" + +to_clean=("$yuv" "$bin") +cleanup() { + rm -- "${to_clean[@]}" +} +trap cleanup EXIT + +run ffmpeg -hide_banner -i "$input" -pix_fmt yuv444p10le -vf scale=out_color_matrix=bt709 -color_primaries bt709 -color_trc bt709 -colorspace bt709 -f rawvideo -y "$yuv" + +width="$(identify -format '%w' "$input")" +height="$(identify -format '%h' "$input")" + +start="$EPOCHREALTIME" +run "$encoder" -c "$cfg_dir"/encoder_intra_main_scc_10.cfg -f 1 -fr 1 -wdt "$width" -hgt "$height" --InputChromaFormat=444 --InputBitDepth=10 --ConformanceWindowMode=1 -i "$yuv" -b "$bin" -q "$q" +end="$EPOCHREALTIME" + +elapsed="$(echo "$end - $start" | bc)" +run echo "Completed in $elapsed seconds" + +echo "$elapsed" > "${output%.bin}".time + +icc="${output%.*}.icc" +if run convert "$input" "$icc"; then + to_clean+=("$icc") +fi + +pack_program="$(cat <<'END' + use File::Copy; + use IO::Handle; + my ($width, $height, $bin, $icc, $output) = @ARGV; + open my $output_fh, '>:raw', $output; + syswrite $output_fh, pack 'NN', $width, $height; + syswrite $output_fh, pack 'N', -s $icc; + copy $icc, $output_fh; + copy $bin, $output_fh; +END +)" +run perl -Mstrict -Mwarnings -Mautodie -e "$pack_program" -- "$width" "$height" "$bin" "$icc" "$output" |