Ask Your Question
10

How to split a recorded rosbag file ?

asked 2013-11-10 21:36:33 -0500

sai gravatar image

updated 2013-11-18 19:12:07 -0500

tfoote gravatar image

Ubuntu 12.04 and fuerte

I have a bag file of 400 seconds length.

I would like to split it into two bag files of 150 seconds and 250 seconds.

There is an option to split bag files while recording using option --split, but now I already have a recorder one.

What can be done?

Thanks

edit retag flag offensive close merge delete

Comments

1

Is it not possible to just play back the bag and rerecord the topics using the --split option?

jdlangs gravatar imagejdlangs ( 2013-11-11 06:46:14 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
22

answered 2016-05-09 22:57:34 -0500

M@t gravatar image

updated 2016-05-09 23:27:04 -0500

My answer is pretty redundant coming three years late, but for anyone else who asks this another option is to use the rosbag filter command, e.g.

rosbag filter input.bag output.bag "t.secs <= 1284703931.86"

You can use the standard greater-than-or-equal-to (>=) and less-than-or-qual-to (<=) operators to keep all data before or after your cutoff point. Keep in mind that ROS time-stamps each message with Unix time, rather than the time of the message relative to the start of the record. So you'll need to find the start and end times of your record and do a bit of basic math to find the 150 sec point.

For other filter commands, take a look at rosbag/Commandline

edit flag offensive delete link more

Comments

I think the misleading part could be the use of seconds in this case because I believe the time-stamp is given in the computer's epoch time.

ubuntuslave gravatar imageubuntuslave ( 2018-02-20 10:40:53 -0500 )edit

Is Unix time and a computer's epoch time not one and the same?

M@t gravatar imageM@t ( 2018-02-22 14:42:49 -0500 )edit
2

for bounding with a startpoint and an endpoint, the expression looks like this:

rosbag filter input.bag output.bag "t.secs >= 1531425960 and t.secs <= 1531426140"
KH - 219Design.com gravatar imageKH - 219Design.com ( 2018-07-13 13:13:39 -0500 )edit
1

answered 2013-11-11 06:46:48 -0500

lindzey gravatar image

I don't know if there's an existing utility for doing this, but it would be pretty simple to do using rosbag's python API. Check out the examples in the cookbook.

You could also try replaying it, and recording all messages with rosbag record -a --split --duration=250.

edit flag offensive delete link more
0

answered 2018-05-01 17:09:55 -0500

lucasw gravatar image

Here is a bash script to split a bag into two using a parameter from 0.0 to 1.0- 0.5 would produce two half length bags:

#!/bin/bash
# provide input bag, output bags prefix, and time fraction
echo $1, $2, $3
t0=`rosbag info -y -k start $1`
t1=`rosbag info -y -k end $1`
tfr=`echo "$t0 + ($t1 - $t0) * $3" | bc -l`
echo $t0, $t1, $tfr
rosbag filter $1 $2_a.bag "t.secs <= $tfr"
rosbag filter $1 $2_b.bag "t.secs > $tfr"
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-11-10 21:36:33 -0500

Seen: 16,800 times

Last updated: May 01 '18