forge
Explore
Log in

Don't you dare go Hollow

yumush

Clone
★ 0

0 watching0 forksRustAGPL-3.06.8 MiB27ceb05Tahinli7 hours ago399 commits

fps.py35 lines, 1.2 KiBHistoryRawDownload
1import subprocess, sys, time, os
2from PIL import Image
3state = os.environ.get("HARNESS_STATE", "/tmp/claude-1000/yumush-harness")
4env = dict(os.environ)
5for line in open(f"{state}/env"):
6 k, v = line.split()[1].split("=", 1)
7 env[k] = v
8x0, y0, x1, y1, src_w = [int(a) for a in sys.argv[1:6]]
9seconds = float(sys.argv[6]) if len(sys.argv) > 6 else 3
10def find_video(im):
11 for y in range(y0, y1):
12 if im.getpixel((x0 + (x1 - x0) // 2, y))[0] > 20:
13 return y
14def read(path):
15 im = Image.open(path).convert("RGB")
16 top = find_video(im)
17 s = (x1 - x0) / src_w
18 n = 0
19 for i in range(32):
20 px = im.getpixel((int(x0 + (i * 16 + 8) * s), int(top + 4 * s)))
21 if px[0] > 128:
22 n |= 1 << i
23 return n
24samples = []
25end = time.time() + seconds
26while time.time() < end:
27 p = f"{state}/shots/fps.png"
28 t = time.time()
29 if os.environ.get("WIN"):
30 subprocess.run(["./win.sh", "shot", "fps"], check=True, stdout=subprocess.DEVNULL)
31 else:
32 subprocess.run(["grim", p], env=env, check=True)
33 samples.append((t, read(p)))
34(t0, n0), (t1, n1) = samples[0], samples[-1]
35print(f"frames {n0}->{n1} in {t1-t0:.2f}s = {(n1-n0)/(t1-t0):.1f} fps, {len(samples)} shots")