0
$\begingroup$

Rosanswers logo

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.


Originally posted by cmansley on ROS Answers with karma: 198 on 2011-07-21

Post score: 9


Original comments

Comment by lucasw on 2022-06-24:
https://www.clearpathrobotics.com/assets/downloads/support/merge_bag.py doesn't do the time offsetting but does merge two or more bag files

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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


Originally posted by tfoote with karma: 58457 on 2011-07-21

This answer was ACCEPTED on the original site

Post score: 6


Original comments

Comment by cmansley on 2011-07-21:
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

$\endgroup$
0
$\begingroup$

Rosanswers logo

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

Originally posted by bchr with karma: 596 on 2016-02-10

This answer was NOT ACCEPTED on the original site

Post score: 9


Original comments

Comment by moooeeeep on 2019-09-16:
The link seems to be broken. A copy of this script seems to be here: https://github.com/udacity/self-driving-car/blob/master/image-localization/community-code/roboauto/scripts/bagmerge.py

Comment by troy on 2019-10-23:
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/21fec0c748227eec89338054e6dd1833

Comment by vschmidt on 2021-09-30:
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.