Get informations about a mcap
import sys
from mcap.reader import make_reader
filename = None
mcapfile = filename or sys.argv[1]
with open(filename, "rb") as f:
reader = make_reader(f)
header = reader.get_header()
msg_profile = header.profile
mcap_version = header.library
summary = reader.get_summary()
statistics = summary.statistics
schemas = summary.schemas
channels = summary.channels
start = statistics.message_start_time
end = statistics.message_end_time
# schemas : {id: Schema(id=id,data=msg_definition, encoding='ros1msg'/'ros2msg', name='sensor_msgs/msg/Imu')}
# channels : {id: Channel(id=id,topic='/topic', message_encoding='cdr', metadata={'offered_qos_profiles': '{}'}, schema_id=schema_id)}
for schema, channel, message in reader.iter_messages(topics=["/velocity"]):
topic = channel.topic
message_type = schema.name
message_data = message.data
ROS1 messages from mcap
import sys
from mcap_ros1.reader import read_ros1_messages
for msg in read_ros1_messages(sys.argv[1]):
topic = msg.topic
if topic == "/topic":
msg_object = msg.ros_msg
field = msg_object.field_name
import sys
from mcap_ros2.reader import read_ros2_messages
for msg in read_ros2_messages(sys.argv[1]):
topic = msg.topic
if topic == "/topic":
msg_object = msg.ros_msg
field = msg_object.field_name