ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
9

Is there a way to merge bag files?

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

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

Comments

1

https://www.clearpathrobotics.com/ass... doesn't do the time offsetting but does merge two or more bag files

lucasw gravatar image lucasw  ( 2022-06-24 10:33:32 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
6

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

tfoote gravatar image

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

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

Comments

4
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 -0600 )edit
9

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

bchr gravatar image

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

bagedit provides a script that does just that: bagmerge.py

$ bag_merge.py --help
usage: bagmerge.py [-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

Comments

3

The link seems to be broken. A copy of this script seems to be here: https://github.com/udacity/self-drivi...

moooeeeep gravatar image moooeeeep  ( 2019-09-16 05:33:40 -0600 )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: https://gist.github.com/troygibb/21fe...

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

There's an interesting side effect of this script. The resulting merged bag is much larger than the sum of the two original bags. Maybe originally compressed messages are getting uncompressed implicitly and don't get re-compressed? I'm not sure.

vschmidt gravatar image vschmidt  ( 2021-09-30 19:03:35 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2011-07-21 05:55:19 -0600

Seen: 26,564 times

Last updated: Feb 10 '16