Ask Your Question

Why doesn't the rosbag api support splitted bags files?

asked 2015-02-13 05:14:25 -0500

anonymous user



I am writing a piece of code which uses the rosbag python API to parse a bag file. It crawls a directory and processes all found bags (searches for *.bag). Basically it looks like this

for filename in *.bag
    bag  = rosbag.Bag(filename)
    for topic, msg, ts in bag.read_messages(...):
        # do something
    # output something

I am having the problem that I encounter splitted bag files.


As the crawling is done automatically (e.g. every night), I do not have the possibility to manually tell the system which bags belong together. I don't like the idea to add this data manually by e.g. adding another description file.

Skipping the once which end with a number different from 0 is easy. But identifying the next part is hard. With rosbag play the user defines all parts to join. A manual solution giving each sequence a different prefix is not suitable as I am working on existing files. Currently I am having a heuristic which looks like this:

1) split the filename into: prefix_dateAndTime_counter.bag
2) get the timestamp of the last message in the current bag
3) check if files exist with name
    3.1) prefix_dateAndTime(last timestamp)_(counter+1).bag
    3.2) add 1 second to "last timestamp" and retry 3.1
4) if 3.1or 3.2 succeed continue with this file otherwise stop parsing

Question 1: Has there been a reason to not include meta information about splitted bags into the bagfile? Some meta data telling e.g. the name of the next bagfile.

For the future I would love to have something like:

  • an entry at the end of a bag "this bag continues in xyz.bag"
  • or an option to tell rosbag record keep the timestamp of the first bag fixed and just change the counter, resulting in something like "date_1.bag date_2.bag ..."

Question 2: Anything planned like that for the future?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-02-13 13:19:51 -0500

tfoote gravatar image

There's not really a place in the bag files for adding arbitrary metadata like you want. And I don't think that it is worth extending the bag format that way.

As a simple work around I suggest that you use directories to group bag files. That should take care of your issue correlating bags from a single recording. The other suggestion is to use a slightly more dynamic prefix which encodes your run number or some other element which you can correlate between the bags.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-02-13 05:14:25 -0500

Seen: 616 times

Last updated: Feb 13 '15