event-triggered MCAP clips from a continuous ROS 2 recording (preroll included)

Sharing a tool we just open-sourced, in case it’s useful to anyone else thinking about the same approach.

The problem: on a robot, the data worth keeping is sparse — a few seconds around a disengagement, a near-miss, a moment perception got it wrong. But you can’t know an event mattered until after it’s already started, and a useful clip needs the lead-up, not just the aftermath. That preroll only exists if the data was already on disk when the event fired.

momentedge-clipper runs alongside an ordinary ros2 bag record, tails the growing MCAP file, and on each trigger cuts a standalone MCAP clip covering [trigger_time − preroll, trigger_time + postroll]. Recording stays rosbag2’s job; the clipper only extracts windows. The two communicate through the file on disk, nothing else.

A few design choices that might be relevant:

  • It tails an already-on-disk recording, rather than buffering in RAM. This is the main difference from rosbag2’s snapshot mode: snapshot holds messages in a memory buffer and writes on trigger, so preroll is bounded by RAM and you only get what was buffered at trigger time. The clipper reads from the continuous on-disk recording, so preroll is bounded by disk, and a trigger can reach back into data that was written well before it fired.
  • Decode-free. It copies MCAP message bytes straight through — channels and schemas carry over, message bodies are never deserialized. It’s agnostic to your message types.
  • MCAP in, MCAP out. Clips are standard, complete MCAP files — they open in Foxglove, the mcap CLI, and ros2 bag replay. No custom format on either side.
  • A trigger is just a topic. Anything that publishes momentedge_msgs/Trigger — a fault detector, a watchdog, an operator button, your perception stack — can drive it. The clipper has no opinion about when something matters; it just captures the window you ask for.

It’s written in Rust (built on r2r), passes its e2e suite on Humble and Jazzy, and ships as Debian packages per distro. There’s a synthetic camera in-repo so you can exercise the whole thing without hardware.

It’s early and Apache-2.0. I’d genuinely like to know where it breaks against real recordings and real trigger sources — bug reports, design objections, and “why not just do X” questions all welcome.

Repo: GitHub - Momentedge/momentedge-clipper: Event-triggered MCAP clips from a continuous ROS 2 recording — including the seconds before the event. · GitHub

1 Like

Curious about one layer. You say decode-free, message bytes copied straight through, but MCAP chunks batch messages compressed, so decode-free isn’t automatically decompress-free. Unless the trigger window lands exactly on a chunk boundary, a true byte-copy either has to decompress and recompress the boundary chunks, or grab a bit more than the window you asked for. Which way did you go, or is it chunk aligned for now?

Also wondering if two clips cut from the same recording keep message order for interleaved topics. I build replay tooling off recordings, so clip determinism is the part I care about.