libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

vmaf.sh (1597B)


      1 #!/usr/bin/env bash
      2 # Copyright (c) the JPEG XL Project Authors. All rights reserved.
      3 #
      4 # Use of this source code is governed by a BSD-style
      5 # license that can be found in the LICENSE file.
      6 
      7 set -euo pipefail
      8 
      9 original="$1"
     10 decoded="$2"
     11 output="$3"
     12 
     13 tmpdir="$(mktemp --directory)"
     14 
     15 exr_original="$(mktemp --tmpdir="$tmpdir" --suffix='.exr')"
     16 exr_decoded="$(mktemp --tmpdir="$tmpdir" --suffix='.exr')"
     17 
     18 yuv_original="$(mktemp --tmpdir="$tmpdir" --suffix='.yuv')"
     19 yuv_decoded="$(mktemp --tmpdir="$tmpdir" --suffix='.yuv')"
     20 
     21 vmaf_csv="$(mktemp --tmpdir="$tmpdir" --suffix='.csv')"
     22 
     23 cleanup() {
     24   rm -- "$exr_original" "$exr_decoded" "$yuv_original" "$yuv_decoded" "$vmaf_csv"
     25   rmdir --ignore-fail-on-non-empty -- "$tmpdir"
     26 }
     27 trap cleanup EXIT
     28 
     29 convert "$original" "$exr_original"
     30 convert "$decoded" "$exr_decoded"
     31 
     32 srgb=(-colorspace bt709 -color_primaries bt709 -color_trc iec61966-2-1)
     33 ffmpeg "${srgb[@]}" -i "$exr_original" -pix_fmt yuv444p10le "${srgb[@]}" -y "$yuv_original" &>/dev/null
     34 ffmpeg "${srgb[@]}" -i "$exr_decoded" -pix_fmt yuv444p10le "${srgb[@]}" -y "$yuv_decoded" &>/dev/null
     35 
     36 "$(dirname "$0")"/../../../third_party/vmaf/libvmaf/build/tools/vmafossexec \
     37   yuv444p10le \
     38   "$(identify -format '%w' "$original")" "$(identify -format '%h' "$original")" \
     39   "$yuv_original" "$yuv_decoded" \
     40   "$(dirname "$0")/../../../third_party/vmaf/model/vmaf_v0.6.1.pkl" \
     41   --log-fmt csv --log "$vmaf_csv" &>/dev/null
     42 
     43 read_csv="$(cat <<'END'
     44 import csv
     45 import sys
     46 reader = csv.DictReader(sys.stdin)
     47 for row in reader:
     48   print(row['vmaf'])
     49 END
     50 )"
     51 
     52 python -c "$read_csv" < "$vmaf_csv" > "$output"