Ask Your Question

Is there a way to merge bag files?

asked 2011-07-21 05:55:19 -0500

I have data across multiple bag files, but I don't care about absolute timestamps, just relative time. I would like to merge the separate bag files into one bag file. For example, if I was recording images to a bag file, then later recorded more images to a different bag file, I would like to combine these bag files into a single one. Right now, I am playing them back and recording them into another bag file, but this seems clunky.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2011-07-21 07:13:31 -0500

tfoote gravatar image

updated 2011-07-21 07:13:53 -0500

You can checkout the rosbag Code API and associated cookbook you should be able to do exactly what you want pretty quickly.

edit flag offensive delete link more


Thanks! I ended up doing just that. I just felt like there should be a nice way to merge two bag files with the same topics. I can see this being helpful for many different types of data. Something like rosbag merge *.bag /topic
cmansley gravatar image cmansley  ( 2011-07-21 08:59:13 -0500 )edit

answered 2016-02-10 03:43:20 -0500

bchr gravatar image

updated 2016-02-10 03:43:39 -0500

bagedit provides a script that does just that:

$ --help
usage: [-h] [-o output_file] [-t topics] [-i] main_bagfile bagfile

Merges two bagfiles.

positional arguments:
  main_bagfile    path to a bagfile, which will be the main bagfile
  bagfile         path to a bagfile which should be merged to the main bagfile

optional arguments:
  -h, --help      show this help message and exit
  -o output_file  name of the output file
  -t topics       topics which should be merged to the main bag
  -i              reindex bagfile
edit flag offensive delete link more



The link seems to be broken. A copy of this script seems to be here:

moooeeeep gravatar image moooeeeep  ( 2019-09-16 05:33:40 -0500 )edit

In case you want to also add a prefix to the second bag, I've modified the above script slightly to take an optional -p[prefix] argument:

troy gravatar image troy  ( 2019-10-23 11:55:35 -0500 )edit

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: 2011-07-21 05:55:19 -0500

Seen: 14,941 times

Last updated: Feb 10 '16