# Storage Configuration for Mcap with rosbag2 API

**URL:** <https://discourse.openrobotics.org/t/storage-configuration-for-mcap-with-rosbag2-api/35083>\
**Category:** ROS General\
**Tags:** ros2\
**Created:** [December 14, 2023, 9:31am UTC](https://discourse.openrobotics.org/t/storage-configuration-for-mcap-with-rosbag2-api/35083 "2023-12-14T09:31:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lars](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/lars/32/8658_2.png) [@lars](https://discourse.openrobotics.org/u/lars)\
**Post date:** [December 14, 2023, 9:31am UTC](https://discourse.openrobotics.org/t/storage-configuration-for-mcap-with-rosbag2-api/35083/1 "2023-12-14T09:31:38Z")

</div>

With using the cli, you can use a config file to configure mcap.

> ros2 bag record -s mcap --storage-config-file …

I want to change the MCAP storage options like compression, chunksize and so on with the rosbag2 API either python or c++  
How can I do this with the API if I want to write to a bag from my node directly? Are there any good tutorials similar to this? [Recording a bag from a node (Python) — ROS 2 Documentation: Humble documentation](https://docs.ros.org/en/humble/Tutorials/Advanced/Recording-A-Bag-From-Your-Own-Node-Py.html)

---

<div class="post-metadata">

**Author:** ![marko](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@marko](https://discourse.openrobotics.org/u/marko)\
**Post date:** [December 14, 2023, 11:35am UTC](https://discourse.openrobotics.org/t/storage-configuration-for-mcap-with-rosbag2-api/35083/2 "2023-12-14T11:35:30Z")

</div>

You can use mcap and compression like this in cpp:

```cpp
    rosbag2_storage::StorageOptions storage_options;
    storage_options.storage_id = "mcap";
    storage_options.storage_preset_profile = "zstd_fast";

```

Should work the same for python

The presets are documented [here](https://github.com/ros2/rosbag2/blob/0fcc839d4363855fe4a5c8693b5e16dfd64b9b34/rosbag2_storage_mcap/README.md#storage-preset-profiles)

---

<div class="post-metadata">

**Author:** ![lars](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.openrobotics.org/lars/32/8658_2.png) [@lars](https://discourse.openrobotics.org/u/lars)\
**Post date:** [December 15, 2023, 10:50am UTC](https://discourse.openrobotics.org/t/storage-configuration-for-mcap-with-rosbag2-api/35083/3 "2023-12-15T10:50:42Z")

</div>

Apparently there is also the option: storage\_options.storage\_config\_uri

€: For Python it is available since Humble, I guess for cpp in earlier versions.

---

<div class="post-metadata">

**Author:** ![jacoby](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@jacoby](https://discourse.openrobotics.org/u/jacoby)\
**Post date:** [December 15, 2023, 6:12pm UTC](https://discourse.openrobotics.org/t/storage-configuration-for-mcap-with-rosbag2-api/35083/4 "2023-12-15T18:12:46Z")

</div>

Not sure if this is helpful, but the [`nml_bag`](https://github.com/ricmua/nml_bag) package has an [example](https://github.com/ricmua/nml_bag/blob/main/doc/markdown/example.md) (also as [.py](https://github.com/ricmua/nml_bag/blob/main/nml_bag/example.py)) that sets storage options and writes a bag programmatically in Python.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/ros/original/3X/b/6/b607ee3cc8e908b1b613bd74a683d749fea635a1.svg) [@system](https://discourse.openrobotics.org/u/system)\
**Post date:** [January 14, 2024, 6:13pm UTC](https://discourse.openrobotics.org/t/storage-configuration-for-mcap-with-rosbag2-api/35083/5 "2024-01-14T18:13:45Z")

</div>

Closed on January 14, 2024, 6:13pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
