The problem you’re encountering is because
rosbag play plays back messages in the order they were recorded in the bag file, but that is not necessarily the same as the chronological order of their timestamps nor the order they were broadcast in. Due to that, some messages can get replayed out of order compared to TFs that they relied upon.
I don’t think it’d be useful to make
rosbag play change the header/stamp of messages; messages will still get played back in the wrong order, and you will be guaranteed to get different behavior from your system than was originally observed. Playing back bag files based on the order of message timestamps would be more useful, but also fairly difficult to do correctly due to how rosbags are structured.
The commonly accepted solution is to simply do a bit of post-processing on recorded bag files and reorder them so that messages are ordered based on their timestamps. There is an example snippet of Python code in the rosbag Cookbook that shows how to do that.
Edit: Oops, the example I was thinking of involves rewriting header timestamps, not reordering messages. I’ll see if I can find the code for that…
Edit 2: I added the script we use for reordering bag files to the cookbook page, since it’s fairly small and will hopefully be useful for other people.