Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(capbench): reject exports with the wrong frame count or size
Marcos Daniel Rivera Gonzalez4bcad5662894
diff --git a/scripts/capbench.py b/scripts/capbench.pyindex c9103ca36..55fd98085 100644--- a/scripts/capbench.py+++ b/scripts/capbench.py@@ -264,6 +264,18 @@ def parse_export(lines):return metrics+def export_problem(probe, expected_frames, resolution):+ if not probe.get("out_frames"):+ return "export has no readable video frames"+ if expected_frames and probe["out_frames"] != expected_frames:+ return f"export has {probe['out_frames']:.0f} frames, expected {expected_frames:.0f}"+ max_width, max_height = (float(side) for side in resolution.split("x"))+ width, height = probe.get("out_width", 0), probe.get("out_height", 0)+ if not (0 < width <= max_width and 0 < height <= max_height):+ return f"export is {width:.0f}x{height:.0f}, outside {resolution}"+ return None++def export_bench(fps, resolution, quality, extra=()):def argv(ctx, out_dir):return [@@ -273,6 +285,9 @@ def export_bench(fps, resolution, quality, extra=()):def post(ctx, out_dir, metrics):probe = ffprobe_video(out_dir / "export.mp4")+ problem = export_problem(probe, metrics.get("frames"), resolution)+ if problem:+ raise InvalidRun(problem)metrics.update(probe)if metrics.get("frames") and metrics.get("wall_s"):metrics["export_fps"] = metrics["frames"] / metrics["wall_s"]diff --git a/scripts/test-capbench.py b/scripts/test-capbench.pyindex 2c97965c9..0eedaabf9 100644--- a/scripts/test-capbench.py+++ b/scripts/test-capbench.py@@ -166,6 +166,15 @@ class CapbenchTests(unittest.TestCase):self.assertEqual(metrics["frames"], 100.0)self.assertAlmostEqual(metrics["steady_fps"], 50.0)+ def test_export_problem_rejects_broken_exports(self):+ good = {"out_frames": 1850.0, "out_width": 1664.0, "out_height": 1080.0}+ self.assertIsNone(capbench.export_problem(good, 1850.0, "1920x1080"))+ self.assertIsNotNone(capbench.export_problem({}, 1850.0, "1920x1080"))+ self.assertIsNotNone(capbench.export_problem({**good, "out_frames": 0.0}, None, "1920x1080"))+ self.assertIsNotNone(capbench.export_problem({**good, "out_frames": 1849.0}, 1850.0, "1920x1080"))+ self.assertIsNotNone(capbench.export_problem({**good, "out_width": 0.0}, 1850.0, "1920x1080"))+ self.assertIsNotNone(capbench.export_problem({**good, "out_height": 2160.0}, 1850.0, "1920x1080"))+def test_exports_ffprobe_cannot_read_are_invalid(self):if not capbench.shutil.which("ffprobe"):self.skipTest("ffprobe is not on PATH")