0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

rosbag(mcap)に記録された各トピックサイズを求める

Posted at

コード

from mcap.reader import make_reader
from mcap_ros2.decoder import DecoderFactory
from tqdm import tqdm


mcap_file = "hoge.mcap"

topic_sizes = {}

with open(mcap_file, "rb") as f:
    reader = make_reader(f, decoder_factories=[DecoderFactory()])
    for schema, channel, message, ros_msg in tqdm(reader.iter_decoded_messages(), dynamic_ncols=True):
        topic = channel.topic
        msg_size = len(message.data)

        if topic not in topic_sizes:
            topic_sizes[topic] = 0
        topic_sizes[topic] += msg_size

for topic, size in topic_sizes.items():
    # バイトからMBに変換
    size_mb = size / (1024 * 1024)
    print(f"Topic: {topic}, Size: {size_mb:.2f} MB")

print(f"Total size: {sum(topic_sizes.values()) / (1024 * 1024):.2f} MB")

実行結果

383109it [01:09, 5543.74it/s]
Topic: /topic1, Size: 3.01 MB
Topic: /topic2, Size: 4.02 MB
Total size: 7.03 MB
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?