I haven't tested it myself, but there's a chance you could use ternaris/rosbags for this.
Announcement on ROS Discourse: Rosbags - the pure python library for everything rosbag.
There doesn't appear to be any implementation for ROS2->ROS1, but ROS1->ROS2 is there, and the library itself is capable of reading/writing both ROS1 and ROS2 bags.
Originally posted by gvdhoorn with karma: 86574 on 2021-10-12
This answer was ACCEPTED on the original site
Post score: 3
Original comments
Comment by dvy on 2022-06-30:
@gvdhoorn: Thanks! I was able to convert a ros2 bag file to ros1 bag file using ternaris/rosbags and was able to play it in ROS1 as well.
Comment by draj on 2022-11-07:
@mandymandy: Can you please tell me how did you do it? Because by following the ternaris/rosbags instructions. I am unable to run it. Also I am very new to ROS .
I also want to do the same i.e. convert ROS2 bag(.db3 bag files) to ROS1(.bag files)
Comment by dvy on 2022-11-07:
pip install rosbags
Convert "bar", result will be "bar.bag"
rosbags-convert bar
Comment by draj on 2022-11-07:
@dvy Thank you very much, it worked. The bag files are converted but there is one more problem, I can see that bag file is reading but I cannot visualize anything on Rviz.
Comment by dvy on 2022-11-07:
@draj: No problem. For this, you need to check if your bag file has the required messages using rosbag info bagfile.bag
, then try to play it and echo the topic. If you get the data on terminal, it should be some minor setting issue on rviz. All the best!
Comment by draj on 2022-11-07:
@dvy Thank you once again. I already did that, as mentioned above I can see the topics and also getting the data on the terminal but rviz is not having the same frame id. I am trying to work on it.
I hope I solve the error. Is it fine if I question again, if it doesn't work?
Comment by dvy on 2022-11-07:
@draj: Its completely fine to ask questions but I would suggest you to raise another question for that in order to avoid mixing up responses here.
Comment by Gutha Bharadwaj on 2023-05-18:
I get an error while following the above commands
Could not read meta data tho i have my yaml file in the same directory
Comment by gts_63 on 2023-07-03:
Hello, I was looking at how to convert ROS2 bag files to ROS1 bag files and found in this thread from @dvy and @draj that it's working but I couldn't get it to work for me.
For a ROS1 bag file, I used the command:
rosbags-convert bagfile.bag --dst new_folder/
It worked and converted to the .bag file to a .db3 file with its metadata.yaml counterpart.
If I try the same command on a .db3 file, it gives an error: "Source and destination rosbag versions must differ." Does this not work on ROS2 to ROS1 conversions? I was thinking of making a new post to get a faster response. I'm on foxy for ROS2 and noetic for ROS1. I source only one distro(and any related workspace) at a time, and tried running the command on both distros but it gives the same results.
EDIT: I got it to work, it seems you have to be at the same directory level as the folder containing the .db3 folder and it has to be the same name of it. Then specify the folder to convert: rosbags-convert db3_file/