Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(capbench): treat exports ffprobe cannot read as invalid runs

Marcos Daniel Rivera Gonzalez8ce135ec573a
diff --git a/scripts/capbench.py b/scripts/capbench.py
index f270e14b6..c9103ca36 100644
--- a/scripts/capbench.py
+++ b/scripts/capbench.py
@@ -227,10 +227,12 @@ def ffprobe_video(path):
text=True,
)
if result.returncode != 0:
- return {}
+ raise InvalidRun(f"ffprobe could not read {path.name}: {result.stderr.strip()[:200]}")
data = json.loads(result.stdout)
stream = (data.get("streams") or [{}])[0]
fmt = data.get("format", {})
+ if not int(stream.get("nb_read_packets", 0)):
+ raise InvalidRun(f"ffprobe found no video frames in {path.name}")
return {
"out_frames": float(stream.get("nb_read_packets", 0)),
"out_duration_s": float(fmt.get("duration", 0)),
diff --git a/scripts/test-capbench.py b/scripts/test-capbench.py
index ce83fa8ad..2c97965c9 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_exports_ffprobe_cannot_read_are_invalid(self):
+ if not capbench.shutil.which("ffprobe"):
+ self.skipTest("ffprobe is not on PATH")
+ post = capbench.BENCHES["export-1080p60"]["post"]
+ with tempfile.TemporaryDirectory() as tmp:
+ (Path(tmp) / "export.mp4").write_bytes(b"not an mp4")
+ with self.assertRaisesRegex(capbench.InvalidRun, "ffprobe"):
+ post(None, Path(tmp), {"frames": 100.0, "wall_s": 2.0})
+
def test_compare_flags_only_separated_changes(self):
def results(values):
return {"benches": {"b": {"runs": [{"wall_s": v} for v in values], "better": {"wall_s": "lower"}}}}