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

Revision history [back]

rosbag::Bag input("input.bag");
rosbag::Bag output("output.bag", rosbag::bagmode::Write);
rosbag::View topic_view(input, rosbag::TopicQuery("topic_to_reqrite"));

BOOST_FOREACH(rosbag::MessageInstance const message, topic_view) {
  output.write(message.getTopic(), message.getTime(), message, message.getConnectionHeader()); 
}

For more information on the API functions, have a look at the API docs.

This code should work:

rosbag::Bag input("input.bag");
rosbag::Bag output("output.bag", rosbag::bagmode::Write);
rosbag::View topic_view(input, rosbag::TopicQuery("topic_to_reqrite"));

BOOST_FOREACH(rosbag::MessageInstance const message, topic_view) {
  output.write(message.getTopic(), message.getTime(), message, message.getConnectionHeader()); 
}

For more information on the API functions, have a look at the API docs.