| 1 | import subprocess, sys, time, os |
| 2 | from PIL import Image |
| 3 | state = os.environ.get("HARNESS_STATE", "/tmp/claude-1000/yumush-harness") |
| 4 | env = dict(os.environ) |
| 5 | for line in open(f"{state}/env"): |
| 6 | k, v = line.split()[1].split("=", 1) |
| 7 | env[k] = v |
| 8 | x0, y0, x1, y1, src_w = [int(a) for a in sys.argv[1:6]] |
| 9 | seconds = float(sys.argv[6]) if len(sys.argv) > 6 else 3 |
| 10 | def find_video(im): |
| 11 | for y in range(y0, y1): |
| 12 | if im.getpixel((x0 + (x1 - x0) // 2, y))[0] > 20: |
| 13 | return y |
| 14 | def 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 |
| 24 | samples = [] |
| 25 | end = time.time() + seconds |
| 26 | while 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] |
| 35 | print(f"frames {n0}->{n1} in {t1-t0:.2f}s = {(n1-n0)/(t1-t0):.1f} fps, {len(samples)} shots") |