NEWAI chat: ask your fleet anything, in plain language. Chat with your fleet Read more →

What is an MCAP file? How to open, read and convert it

What an MCAP file is, how ROS 2 records it, and how to inspect, read in Python, convert from .db3, compress and recover MCAP files on real robots.

Illustration for "What is an MCAP file?": a robot arm, a camera, a field rover, with the label ".db3 → .mcap · indexed, zstd"

Someone on the team sends you a file called rosbag2_0.mcap from a robot at a customer site. It's 1.8 GB. "The arm stopped around 14:20, can you look?" You double-click it and nothing on your laptop knows what to do with it.

Somewhere in that file are the 40 seconds before the arm stopped: the wrist camera, the joint states, the commands and the warnings, all on one clock. You just need to know how to get at them.

Robots running learned models are living minds. They decide many times a second, their models change every few weeks, and they work far from the people who trained them, so when one misbehaves you can't ask it why. The file is the closest thing you have to its memory of the moment, and most ROS 2 robots now write it as MCAP.

The short answer: An MCAP file is an open, indexed container for timestamped messages from many streams (camera images, ROS messages, logs, sensor data), with the schemas that describe those messages stored inside the file. Since ROS 2 Iron, ros2 bag record writes MCAP by default (on Humble, add -s mcap). You inspect it with the mcap CLI (mcap info file.mcap, no ROS needed), replay it with ros2 bag play, plot it in an open viewer such as PlotJuggler, read it in Python with the mcap and mcap-ros2-support packages, and convert old .db3 bags with mcap convert.

What is an MCAP file?

MCAP (pronounced "em-cap") is an open file format for pub/sub data. The MCAP specification describes it as a container for "timestamped pub/sub messages with arbitrary serialization formats". Each stream is a channel (usually a ROS topic) with a schema stored in the file, messages are grouped in chunks compressed with LZ4 or Zstandard, and an index at the end lets a reader jump to 14:20 or pull one topic without scanning 1.8 GB. The spec registry lists ROS 1, ROS 2 CDR, Protobuf, FlatBuffers, Cap'n Proto, CBOR, MessagePack and JSON encodings, and there are official libraries for C++, Python, Go, Rust, TypeScript and Swift. The MCAP glossary entry has the short definition; this post is the hands-on part.

What's inside, record by record

If you ever need to debug a broken file, it helps to know the layout. An MCAP file starts and ends with the same 8 magic bytes: 0x89 followed by MCAP0\r\n (the 0 is the major version). In between there are typed records:

| Record | What it holds | |---|---| | Header | Profile (e.g. ros2) and the library that wrote the file | | Footer | Where the summary section starts | | Schema | A message definition, e.g. std_msgs/msg/Float32 in ros2msg | | Channel | A topic name, its message encoding and its schema | | Message | One timestamped message on one channel | | Chunk | A batch of schemas, channels and messages, optionally compressed | | Message Index / Chunk Index | Where each channel's messages sit, and each chunk's time range | | Attachment / Metadata | Arbitrary files (a URDF, a calibration) and key-value pairs | | Statistics / Summary Offset / Data End | Counts and time range, plus fast access to the summary |

You can check the first one yourself: head -c 8 file.mcap | xxd should show 894d 4341 5030 0d0a. If it doesn't, the file isn't MCAP, whatever its extension says.

MCAP and ROS 2: how it gets recorded

Since ROS 2 Iron, rosbag2 writes MCAP by default. The Iron release notes give the reason: the old SQLite3 storage "was not performant enough and lacked certain features desirable for offline processing". SQLite3 is still available as a plugin, so you'll still meet .db3 files from older robots and from Humble, where SQLite3 is still the default.

Of the distros supported as of November 2026, Jazzy, Kilted and Lyrical Luth record MCAP without any flag:

ros2 bag record -o pick_test /joint_states /wrist_cam/image_raw/compressed /rosout

ros2 bag info pick_test

ros2 bag play pick_test

On Humble, add -s mcap (short for --storage mcap) and install the rosbag2_storage_mcap package. The output is a folder with a metadata.yaml and one or more .mcap files. ros2 bag play and ros2 bag info accept the folder or a single .mcap file.

The writer options that matter on a robot

The MCAP storage plugin has preset profiles you pick with --storage-preset-profile:

  • `fastwrite`: no chunking, no CRCs, no message index. The lowest CPU cost, meant for resource-constrained robots. The catch: without a message index, reading a subset of topics or seeking doesn't work, so post-process these files (for example with mcap compress) before long-term storage.
  • `zstd_fast`: Zstandard chunk compression at the fastest level, no CRCs. A good default on a robot with a spare core and a small disk.
  • `zstd_small`: 4 MB chunks, Zstandard at its highest ratio, chunk CRCs on. Small files, heavy to write. The rosbag2 docs suggest it as a post-processing step with ros2 bag convert, not on the robot while it works.

For finer control, pass --storage-config-file with writer options such as chunkSize, compression (None, Lz4, Zstd) and compressionLevel.

My rule on robots: record with zstd_fast if the CPU allows, fastwrite if it doesn't, and never use rosbag2's file-level compression on MCAP. The rosbag2 README explains why: file compression produces a file that can't be indexed, while MCAP's own chunk compression keeps the index, so tools can still seek.

Two more recorder flags worth knowing: -b / --max-bag-size (bytes) and -d / --max-bag-duration (seconds) split the recording into several files, so a power cut damages one short file, not the whole session. And --snapshot-mode with --max-cache-size or --max-cache-duration keeps a rolling buffer in memory and writes it only when you call the recorder's snapshot service. That is the "save the last N seconds when something goes wrong" pattern, built into rosbag2.

How to open an MCAP file

1. Inspect it with the mcap CLI

The `mcap` CLI is a single binary. Install it with brew install mcap or download a release binary. As of November 2026 the latest release is v0.4.0. The CLI was rewritten in Rust and its version numbers restarted at 0.1.0, so don't be surprised if an old install reports 0.0.5x.

mcap info recording.mcap

mcap list channels recording.mcap

mcap cat recording.mcap --topics /rosout --format=ndjson | head

mcap info is the first thing I run on any file someone sends me. It shows the time range, the message count per channel, the compression and the chunk sizes. Three things to look for:

  • A channel with far fewer messages than its rate implies. A camera that should have 9,000 frames in five minutes at 30 Hz and has 3,300 was running at 11 Hz.
  • A channel that ends early. If /wrist_cam/image_raw stops 40 seconds before the end of the file, that's where to start.
  • No summary, or a missing index. That means the recording didn't finish cleanly, or it was written with fastwrite. See the recovery section below.

Other subcommands worth knowing: filter (copy part of a file, such as a few topics, into a new one), merge, compress / decompress, sort, du (which channel takes the space), and get / add for attachments and metadata.

2. Replay it into ROS

If you have ROS 2 installed, ros2 bag play recording.mcap publishes every topic again, so RViz, your own nodes or ros2 topic echo see it as if it were live. Add --topics to replay only some of them, and --rate 0.5 to slow it down. This is the most useful way to reproduce a bug in a node: feed it the exact inputs it saw on the robot.

3. Look at it in a viewer

Several open tools read MCAP directly. PlotJuggler (open source) lists MCAP as a supported file format and is good for plotting joint states, rates and anything numeric against time. For camera frames and 3D data, replaying into RViz works everywhere. And because the format is open and documented, it's reasonable to write your own small viewer for your team's data.

How to read an MCAP file in Python

You don't need ROS installed to read ROS 2 messages from an MCAP file. The definitions are in the file, and the `mcap-ros2-support` package decodes CDR on its own. I ran both examples below with mcap 1.6.0 and mcap-ros2-support 0.6.0, the current PyPI releases as of November 2026.

pip install mcap mcap-ros2-support

The short version, from the package docs:

from mcap_ros2.reader import read_ros2_messages

for msg in read_ros2_messages("recording.mcap"):

print(f"{msg.channel.topic}: {msg.ros_msg}")

When you want to filter by topic and keep access to timestamps and schemas:

from mcap.reader import make_reader

from mcap_ros2.decoder import DecoderFactory

with open("recording.mcap", "rb") as f:

reader = make_reader(f, decoder_factories=[DecoderFactory()])

for schema, channel, message, ros_msg in reader.iter_decoded_messages(topics=["/battery_voltage"]):

print(message.log_time, ros_msg.data)

message.log_time is in nanoseconds (since the Unix epoch for rosbag2 recordings). reader.get_summary() gives you the channels and statistics without reading every message; it returns None when the file has no summary, which is your hint that the recording didn't finish cleanly. Inside a ROS 2 environment rosbag2_py.SequentialReader works too, but the mcap packages run anywhere, including a CI job with no ROS at all.

The same library writes MCAP too (mcap.writer.Writer for any encoding, mcap_ros2.writer.Writer for ROS 2 messages). That's handy for non-ROS processes on the robot: a Python inference service can write its own MCAP with JSON or Protobuf messages, and it lines up with the ROS recording by timestamp.

How to convert a .db3 bag to MCAP

You'll meet .db3 files from Humble robots and older recordings. Two ways to convert them.

With the mcap CLI, no ROS needed:

mcap convert old_run.db3 old_run.mcap

mcap convert old_run.bag old_run.mcap # ROS 1 bags too

Since the Rust rewrite, the CLI reads the message definitions stored inside ROS 2 bags from Iron onwards, so you don't need a sourced workspace. Bags recorded before Iron don't carry their definitions. For those, use ros2 bag convert on a machine with the original message packages sourced.

With ros2 bag convert, using an output YAML. This is adapted from the rosbag2_storage_mcap README, and it also compresses the result:

# convert.yaml

output_bags:

- uri: old_run_mcap

storage_id: mcap

storage_preset_profile: zstd_small

ros2 bag convert -i old_run -o convert.yaml

The same command turns a fastwrite recording into a small, indexed file before you upload it. Record fast on the robot, compress later where CPU is cheap.

Then check the result: mcap info should show the same message count per channel as the source (ros2 bag info on the original), and the same start and end times. If the counts differ, look for topics whose type couldn't be resolved.

When an MCAP file is broken

Robots lose power. A recording that was being written when the battery died has no footer and no summary. It's not lost.

  • mcap recover damaged.mcap -o recovered.mcap rebuilds the chunk indexes and the summary. Its exit code tells you how it went: 0 means everything was recovered, 3 means some data was lost, 1 means nothing could be recovered. Use that in scripts.
  • mcap doctor checks a file's structure, which is a quick way to confirm what kind of damage you're dealing with.

Two habits prevent most of this. Split recordings with --max-bag-duration, so a crash damages one short file. And copy only closed files off the robot: a file that's still being written will look broken to whoever opens it.

What I'd put in place

A short checklist for teams that record robot data in production:

  1. Record MCAP everywhere, including Humble (-s mcap). One format across the fleet means one set of tools.
  2. Use zstd_fast on the robot, or fastwrite if CPU is tight, and post-process to zstd_small before long-term storage.
  3. Split by duration, and set a disk budget so recordings never fill the disk the robot needs to run.
  4. Record a compressed camera topic instead of raw images when you can. Raw 1080p RGB frames at 30 Hz are close to 190 MB every second.
  5. Store the release version, model checkpoint, robot ID and URDF inside the file as metadata and attachments, so the file explains itself.

What to record and when to trigger it is the subject of our flight recorder post.

How we do it at PhysicalFleet

When something goes wrong on a robot, the PhysicalFleet agent saves the last five minutes of metrics, logs, events, ROS logs and camera thumbnails as a standard MCAP file. You replay it in the dashboard with everything on one timeline, and because it's plain MCAP, you can also open it in other tools that read the format. More on our Debug page.

If you've got an MCAP trick we missed, or a file that defeated every tool you tried, tell us. We'd like to hear it.

Common questions

How do I open an MCAP file?

No ROS needed: install the mcap CLI (brew install mcap or a release binary) and run mcap info file.mcap to see its topics, message counts and time range. For plots, open it in a desktop viewer such as PlotJuggler. With ROS 2 installed, ros2 bag play file.mcap replays it into RViz and your own nodes, and in Python the mcap package iterates over the messages.

How do I record an MCAP file in ROS 2?

Run ros2 bag record -o my_run /topic1 /topic2, or -a for all topics. On Iron and newer that writes MCAP by default; on Humble, install rosbag2_storage_mcap and add -s mcap. Add --storage-preset-profile zstd_fast for compressed, still indexed files.

Can I read an MCAP file without ROS installed?

Yes. MCAP files store the message definitions inside the file, and the mcap-ros2-support Python package decodes ROS 2 messages without any ROS installation. The mcap CLI also reads and converts files on any machine.

How do I make MCAP files smaller?

Use chunk compression: record with --storage-preset-profile zstd_fast, or compress afterwards with mcap compress or ros2 bag convert and the zstd_small preset. Record compressed image topics instead of raw ones, and keep only the topics you need with mcap filter. Avoid rosbag2's file-level compression on MCAP, since it makes the file unindexable.

What does "mcap recover" do?

It reads a damaged or truncated MCAP file, for example one that was being written when a robot lost power, and writes a new file with rebuilt chunk indexes and a summary section. An exit code of 0 means full recovery and 3 means some data was lost.

#MCAP#ROS 2#rosbag2#mcap CLI#robot data#Python
Eitan ChudnovskyCo-founder, PhysicalFleet

From the lab bench. To the entire fleet.

Connect your first machine in minutes, develop it in the lab and run your whole fleet in production from one place.

Free for up to 3 machines · Then pay as you go