forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiBe12d32fTahinli6 days ago3982 commits

hevc-thread-bench.sh72 lines, 2.9 KiBHistoryRawDownload
1#!/usr/bin/env bash
2# hevc-thread-bench.sh: encode lavfi clips with ec-h265 at 1, 2, 4 and 6 worker threads,
3# report fps per thread count, and check that every thread count writes the same bytes.
4#
5# Usage: scripts/remote-run.sh hevcencthreads --host b -- scripts/hevc-thread-bench.sh
6#
7# Environment: DATA (default $HOME/.cache/hevcencthreads-data), GOP (keyframe interval,
8# default 8), QP (default 30), FRAMES (default 12), CLIPS (default "1280x720 1920x1080"),
9# THREADS (default "1 2 4 6"), RUNS (timed runs per point, default 1, best time kept).
10# RC_KBPS: when set (e.g. 4000), encode with bitrate control at that rate and FPS (default 30)
11# through the hevc_rc example instead of constant QP through hevc_gop.
12set -euo pipefail
13
14here=$(cd "$(dirname "$0")/.." && pwd)
15data=${DATA:-$HOME/.cache/hevcencthreads-data}
16gop=${GOP:-8}
17qp=${QP:-30}
18frames=${FRAMES:-12}
19clips=${CLIPS:-"1280x720 1920x1080"}
20threads_list=${THREADS:-"1 2 4 6"}
21runs=${RUNS:-1}
22mkdir -p "$data"
23
24rc_kbps=${RC_KBPS:-}
25rc_fps=${FPS:-30}
26if [ -n "$rc_kbps" ]; then
27 cargo build --release -q -p ec-h265 --example hevc_rc --manifest-path "$here/Cargo.toml"
28else
29 cargo build --release -q -p ec-h265 --example hevc_gop --manifest-path "$here/Cargo.toml"
30fi
31target=$(cargo metadata --format-version 1 --no-deps --manifest-path "$here/Cargo.toml" \
32 | python3 -I -c 'import json,sys; print(json.load(sys.stdin)["target_directory"])')
33gopbin="$target/release/examples/hevc_gop"
34[ -n "$rc_kbps" ] && gopbin="$target/release/examples/hevc_rc"
35
36printf '%-10s %-8s %-10s %-10s %-10s %-s\n' clip threads secs fps bytes identical
37for size in $clips; do
38 w=${size%x*}
39 h=${size#*x}
40 src="$data/src-$size-$frames.yuv"
41 if [ ! -s "$src" ]; then
42 ffmpeg -v error -y -f lavfi -i "testsrc2=size=${size}:rate=30" \
43 -vf "scroll=v=0.02,format=yuv420p" -frames:v "$frames" -f rawvideo "$src"
44 fi
45 ref_md5=""
46 for t in $threads_list; do
47 out="$data/out-$size-t$t.hevc"
48 recon="$data/recon-$size-t$t.yuv"
49 best=""
50 for _ in $(seq "$runs"); do
51 start=$(date +%s.%N)
52 if [ -n "$rc_kbps" ]; then
53 EC_H265_THREADS="$t" "$gopbin" encode "$src" "$w" "$h" "$gop" "$rc_kbps" "$rc_fps" "$out" "$recon" >/dev/null
54 else
55 EC_H265_THREADS="$t" "$gopbin" encode "$src" "$w" "$h" "$gop" "$qp" "$out" "$recon" >/dev/null
56 fi
57 end=$(date +%s.%N)
58 secs=$(python3 -I -c "print(f'{$end - $start:.3f}')")
59 if [ -z "$best" ] || python3 -I -c "import sys; sys.exit(0 if $secs < $best else 1)"; then
60 best=$secs
61 fi
62 done
63 bytes=$(stat -c %s "$out")
64 md5=$(md5sum "$out" | cut -d' ' -f1)
65 if [ -z "$ref_md5" ]; then ref_md5=$md5; fi
66 same=yes
67 [ "$md5" = "$ref_md5" ] || same=NO
68 [ "$same" = yes ] || { echo "FAIL: $size threads $t bytes differ from the first thread count" >&2; exit 1; }
69 fps=$(python3 -I -c "print(f'{$frames / $best:.2f}')")
70 printf '%-10s %-8s %-10s %-10s %-10s %-s\n' "$size" "$t" "$best" "$fps" "$bytes" "$same"
71 done
72done