Skip to main content

MCAP Data Loader

PyPI Python License

A Python library for loading and processing MCAP data files in a way that is more suitable for machine learning and robotics training pipelines.

English | 简体中文

Features

  • Dataset-style APIs for iterating MCAP data as episodes/samples
  • Built-in statistics utilities (dataset-level and episode-level)
  • Convenient access to topics and attachments
  • Integration CLI for training with LeRobot using MCAP as the dataset backend

Installation

Install from PyPI:

pip install mcap-data-loader

Or install from source:

git clone https://github.com/OpenGHz/MCAP-DataLoader.git --depth 1
cd MCAP-DataLoader
pip install -e .

Quickstart (basic usage)

A basic example showing how to load MCAP files from a directory, inspect statistics, and iterate through episodes/samples:

from mcap_data_loader.datasets.mcap_dataset import (
    McapFlatBuffersEpisodeDataset,
    McapFlatBuffersEpisodeDatasetConfig,
)
from pprint import pprint

dataset = McapFlatBuffersEpisodeDataset(
    McapFlatBuffersEpisodeDatasetConfig(
        data_root="data/example",
        # keys typically include topic names and optional special fields (e.g. "log_stamps")
        keys=["/follow/arm/joint_state/position", "log_stamps"],
    )
)

print(f"All files: {dataset.all_files}")
print(f"Dataset length: {len(dataset)}")

print("Dataset statistics:")
pprint(dataset.statistics())

for episode in dataset:
    print(f"Current file: {episode.config.data_root}")

    for sample in episode:
        print(f"Sample keys: {sample.keys()}")
        break

    print(f"Episode length: {len(episode)}")
    print(f"All topics: {episode.reader.all_topic_names()}")
    print(f"All attachments: {episode.reader.all_attachment_names()}")

    print("Episode statistics:")
    pprint(episode.statistics())
    print("----" * 10)

More examples and detailed usage can be found in the examples directory.

Integration with LeRobot training

MCAP Data Loader provides a CLI to train LeRobot models using MCAP data files. This allows you to use MCAP datasets directly as the training data source for LeRobot, without needing to convert them into a different format.

You should have LeRobot installed in your environment to use this feature. You can install it from PyPI (0.4.3 is tested):

pip install lerobot

Train with an MCAP dataset

Run:

mcap-lerobot-train -c configs/config.yaml

Recommended: place your config file under a configs/ directory in your current working directory.

Configuration reference

The top level is the standard LeRobot configuration, with an additional mcap section for MCAP dataset loading settings:

batch_size: 2
num_workers: 1
policy:
  type: act
  push_to_hub: false
  chunk_size: 2
  n_action_steps: 2

dataset:
  root: data
  repo_id: example
  streaming: true

mcap:
  states:
    - /follow/arm/joint_state/position
    - /follow/eef/joint_state/position
  actions:
    - /lead/arm/pose/position
    - /lead/arm/pose/orientation
  images:
    - /env_camera/color/image_raw

The lists of topics specified by states and actions will be loaded and concatenated to form the observation.state and action required by lerobot, serving as low-dimensional state and action inputs in the training data. Meanwhile, images will be appended to the observation.images field, using the first part of the name (e.g., env_camera in the example above) as a suffix for image input, such as observation.images.env_camera, for use during training.

Vision-language-action policies (pi0.5)

Vision-language-action policies such as pi0.5 need two things beyond ACT, both handled by the mcap section:

  • Language task. Each sample must carry a language instruction. It is extracted per-episode from an MCAP metadata record (by default task_info.task_description). Set task_source to metadata (default), config (use the static task string), or none (disable, e.g. for ACT).
  • Quantile statistics. pi0.5 normalizes state/action with quantiles, so q01/q99 stats are required. Set compute_quantiles: true to compute them with one extra pass over the dataset. This is auto-enabled when the policy uses quantile normalization.

pi0.5 also requires a non-empty states. A minimal example (see configs/pi05.yaml):

policy:
  type: pi05
  chunk_size: 50
  n_action_steps: 50

mcap:
  states:
    - /follow/arm/pose/position
    - /follow/arm/pose/orientation
  actions:
    - /lead/arm/pose/position
    - /lead/arm/pose/orientation
  images:
    - /env_camera/color/image_raw
  task_source: metadata          # metadata | config | none
  task_metadata_name: task_info
  task_field: task_description    # or task_description_zh
  task: "do the task"            # fallback when metadata is missing
  compute_quantiles: true

The action chunk length, image resize to 224, and state/action padding are handled inside the pi0.5 model, so no data-side change is needed for those. The first run downloads the PaliGemma tokenizer/weights from the Hugging Face hub.

Organizing processed data

For processed data, MCAP is better suited to creating a new file that contains only the processed topics, rather than appending processed data back into the original file. For an example of generating processed topics, see the airdc process_poses script.

During training, you can specify both the original dataset directory and the processed dataset directory at the same time. MCAP Data Loader will merge them automatically at runtime, so they can be consumed as if they were read from a single dataset.

A typical configuration looks like this:

dataset:
  root: data
  repo_id:
    - mujoco
    - mujoco_processed
  streaming: true

Notes:

  • dataset.root and dataset.repo_id are reused to specify the MCAP dataset root directory and dataset name.
  • Command-line overrides compatible with LeRobot are supported and take the highest priority (they override values in the config file). For example:
    mcap-lerobot-train -c configs/config.yaml --dataset.repo_id=example_task
    

Train with LeRobot’s original dataset format

If you want to use LeRobot’s original data format (while still using this CLI), add --ori:

mcap-lerobot-train -c configs/ori.yaml --ori

Make sure the dataset path in your config points to the actual LeRobot dataset location.

Help / supported CLI args

Show supported parameters:

mcap-lerobot-train -h

If the output is long, redirect to a file:

mcap-lerobot-train -h > lerobot_help.txt

Data Processing

For pose-topic post-processing (generating relative-pose and rotation_6d topics), see the airdc.scripts.process_poses script in the airdc project.

The script can generate:

  • relative pose topics with _rela suffix
  • rotation_6d topics converted from quaternion pose topics

Example:

python3 -m airdc.scripts.process_poses \
  data/example \
  --keys /follow/arm/pose/position /follow/arm/pose/orientation \
  --targets rela rotation_6d

Documentation

More runnable examples live in the examples directory.

Project structure

mcap_data_loader/
├── basis/          # Config-able base classes (datasets, loaders, data types)
├── callers/        # Composable transforms (map, normalize, stack, policy, ...)
├── configurers/    # Hydra / config wiring
├── data_types/     # Shared data-type definitions
├── datasets/       # MCAP dataset APIs + LeRobot training integration
├── pipelines/      # Data pipeline stages (horizon, flatten, merge, slice, ...)
├── schemas/        # FlatBuffers schemas (.fbs / .bfbs)
├── scripts/        # Data-processing / helper scripts
├── serialization/  # MCAP / ROS / FlatBuffers / video (de)serialization
└── utils/          # Shared utilities

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for the development setup, coding style, and pull-request process, and note our Code of Conduct.

Getting help

License

This project is licensed under the terms of the MIT License.

Metadata

Release files for mcap-data-loader 0.3.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcap-data-loader 0.3.5
File Size Uploaded Provenance
mcap_data_loader-0.3.5.tar.gz 165.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mcap-data-loader 0.3.5
File Interpreter ABI Platform
mcap_data_loader-0.3.5-py3-none-any.whl Python 3 none any Details

Total release size: 357.4 kB

Release files / mcap_data_loader-0.3.5.tar.gz

Download URL mcap_data_loader-0.3.5.tar.gz
Size 165.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8388003cc328d9fa9d7d229450b0963850a8050eaf687ca653a80dc21d057921
BLAKE2b-256 checksum
How to use checksums
e61946ee1e004b8af970fe6eed895cb2a5a70b2199f83a4c89ea1bb772d33441
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.18

Release files / mcap_data_loader-0.3.5-py3-none-any.whl

Download URL mcap_data_loader-0.3.5-py3-none-any.whl
Size 191.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f141a110be8fc2d75cd321706372759a10688d6bfb741c60ef71071738a3240b
BLAKE2b-256 checksum
How to use checksums
51969ff92b26b31e073e483822547de58ef248865f472d78d5718bccf1241665
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.18

Security for mcap-data-loader 0.3.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.5 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page