Rosanswers logo

Hi to all,

I have a *.bag file which contains different topics and I would like to extract only a specific topic and record it in a new bag file.

Is it possible?

I've read about a solution which enable users to extract a topic and save its content in a CSV file, but the problem is that I need to have another *.bag file and not CSV.

Is there any solution?

Thank you!!

Originally posted by Marcus Barnet on ROS Answers with karma: 287 on 2016-06-28

Post score: 2


1 Answer 1


Rosanswers logo

This is the first example listed for the rosbag filter command: http://wiki.ros.org/rosbag/Commandline#filter

rosbag filter my.bag only-tf.bag "topic == '/tf'"

If you want to extract a topic other than /tf, simply change that portion of the command.

Note that the expression topic == '/tf' is surrounded in double quotes so that it isn't interpreted by the shell, and /tf is further enclosed in single quotes because it is a python string literal.

Originally posted by ahendrix with karma: 47576 on 2016-06-28

This answer was ACCEPTED on the original site

Post score: 4

Original comments

Comment by Marcus Barnet on 2016-06-28:
Thank you!!!

Comment by petitchamp on 2019-02-04:
Is there any way to extract more than one topic from a bag file? something like "topic == '/tf1,/tf2'"?

Comment by ahendrix on 2019-02-04:
Yes; you can use any python expression as the filte, so you could do "topic in ['/topic1', '/topic2']" or even use python's string or regex matching!


Your Answer

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