Skip to content

Instantly share code, notes, and snippets.

@wkalt
Created November 4, 2021 22:34
Show Gist options
  • Save wkalt/19247722f966d36987fc91f01eff7574 to your computer and use it in GitHub Desktop.
Save wkalt/19247722f966d36987fc91f01eff7574 to your computer and use it in GitHub Desktop.
#!/bin/env python3
import rosbag
import sys
_, inputfile, outputfile = sys.argv
bag = rosbag.Bag(inputfile)
message_count = bag.get_message_count()
c = 0
with rosbag.Bag(outputfile, "w") as output:
for topic, msg, t in bag.read_messages():
if c < message_count - 1:
output.write(topic, msg, msg.header.stamp if msg._has_header else t)
c += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment