forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

hevc10-roundtrip.sh69 lines, 3.1 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# hevc10-roundtrip.sh: Main 10 round trip of ec-h265. Encodes testsrc2 clips as 10-bit
3# 4:2:0 (yuv420p10le), decodes the stream with ec-h265 and with ffmpeg, and compares
4# each against the encoder's reconstruction byte for byte. Also reports the size, the
5# 10-bit PSNR of the reconstruction against the source, and for bitrate mode the rate
6# achieved against the target.
7#
8# Usage: scripts/hevc10-roundtrip.sh (run it where the cargo build happens:
9# scripts/remote-run.sh h265m10enc -- scripts/hevc10-roundtrip.sh)
10#
11# Environment: DATA (default $HOME/.cache/hevc10-data), GOP (keyframe interval for the
12# GOP rows, default 8), QP (constant QP, default 30), RC (bitrate mode as kbps@fps, e.g.
13# 2500@30; when set, the constant-QP rows are skipped), FRAMES (default 64), CLIPS
14# (default "416x240 1280x720"), EXTRA (encoder flags, e.g. "sh").
15set -euo pipefail
16
17here=$(cd "$(dirname "$0")/.." && pwd)
18data=${DATA:-$HOME/.cache/hevc10-data}
19gop=${GOP:-8}
20qp=${QP:-30}
21rc=${RC:-}
22frames=${FRAMES:-64}
23clips=${CLIPS:-"416x240 1280x720"}
24mkdir -p "$data"
25
26cargo build --release -q -p ec-h265 --example hevc_gop --manifest-path "$here/Cargo.toml"
27target=$(cargo metadata --format-version 1 --no-deps --manifest-path "$here/Cargo.toml" \
28 | python3 -I -c 'import json,sys; print(json.load(sys.stdin)["target_directory"])')
29gopbin="$target/release/examples/hevc_gop"
30
31status=0
32export EC_H265_BITDEPTH=10
33if [ -n "$rc" ]; then modes="rc"; else modes="qp"; fi
34printf '%-10s %-6s %-6s %-8s %-9s %-10s %-10s %-10s %-10s\n' clip gop mode bytes kbps psnr_y psnr_yuv ec_decode ffmpeg_decode
35for size in $clips; do
36 w=${size%x*}
37 h=${size#*x}
38 src="$data/src10-$size.yuv"
39 if [ ! -s "$src" ]; then
40 ffmpeg -v error -y -f lavfi -i "testsrc2=size=${size}:rate=30" \
41 -vf "scroll=v=0.02,format=yuv420p10le" -frames:v "$frames" -f rawvideo "$src"
42 fi
43 for keyint in 1 "$gop"; do
44 for mode in $modes; do
45 tag="$size-k$keyint-$mode"
46 stream="$data/$tag.hevc"
47 recon="$data/$tag.recon.yuv"
48 dec="$data/$tag.ec.yuv"
49 ff="$data/$tag.ff.yuv"
50 if [ "$mode" = rc ]; then
51 EC_H265_RC=$rc "$gopbin" encode "$src" "$w" "$h" "$keyint" "$qp" "$stream" "$recon" ${EXTRA:-} >/dev/null
52 else
53 "$gopbin" encode "$src" "$w" "$h" "$keyint" "$qp" "$stream" "$recon" ${EXTRA:-} >/dev/null
54 fi
55 "$gopbin" decode "$stream" "$dec" >/dev/null
56 ffmpeg -v error -y -i "$stream" -f rawvideo -pix_fmt yuv420p10le "$ff"
57 if cmp -s "$dec" "$recon"; then ec=exact; else ec=MISMATCH; status=1; fi
58 if cmp -s "$ff" "$recon"; then fv=exact; else fv=MISMATCH; status=1; fi
59 bytes=$(stat -c %s "$stream")
60 kbps=$(awk -v b="$bytes" -v f="$frames" 'BEGIN{printf "%.1f", b*8*30/f/1000}')
61 metrics=$(python3 -I "$here/scripts/yuv_psnr.py" "$w" "$h" "$src" "$recon" 10)
62 py=$(sed -n 's/.*psnr_y=\([^ ]*\).*/\1/p' <<<"$metrics")
63 pyuv=$(sed -n 's/.*psnr_yuv=\([^ ]*\).*/\1/p' <<<"$metrics")
64 printf '%-10s %-6s %-6s %-8s %-9s %-10s %-10s %-10s %-10s\n' \
65 "$size" "$keyint" "$mode" "$bytes" "$kbps" "$py" "$pyuv" "$ec" "$fv"
66 done
67 done
68done
69exit $status