First Steps with rosbag

ROS (Robot Operating System) provides a set of libraries and tools to help software developers create robotic applications. It offers hardware abstraction, device drivers, libraries, visualization tools, message passing, and package management among other features.

rosbag is used for recording depth camera data. The rosbag package provides a command-line tool along with C++ classes and Python APIs. With the command line, rosbag can record, replay messages from bags, rterieve summary information, check message types, filter informatoin using Python expressions, compress and decompress bags, and reindex them.

List of supported commands by rosbag:

  1. View information contained in a .bag file: rosbag info

  2. Replay information contained in a .bag file: rosbag play 2.1 Publish messages at a specific frequency: rosbag play -r 2 2.2 Start publishing messages from a specific time: rosbag play -s 2

  3. Record all topic information: rosbag record -a 3.1 Record partial information: rosbag record -o subset /turtle1/cmd_vel /turtle1/pose which creates a file named subset.bag.

  4. Other commands: 4.1 Check: Determine if a .bag can be played on the current system or if it can be migrated. rosbag check 4.2 Fix: Repair messages in a .bag file so it can be played on the current system. rosbag fix 4.3 Filter: Convert a .bag file using a Python expression. rosbag filter 4.4 Compress: Compress one or more .bag files. rosbag compress 4.5 Decompress: Decompress one or more .bag files. rosbag decompress 4.6 Reindex: Rebuild one or more corrupted .bag files. rosbag reindex

  5. Export image data recorded in a .bag file as images or video. a. Create a file named export.launch and write the following content:

1 <launch>
2   <node pkg="rosbag" type="play" name="rosbag" args="-d 2 $(find image_view)/test.bag"/>
3   <node name="extract" pkg="image_view" type="extract_images" respawn="false" output="screen" cwd="ROS_HOME">
4     <remap from="image" to="/camera/image_raw"/>
5   </node>
6 </launch>

b. Run the launch file:

1 roslaunch export.launch

At this point, the data will be separated into a set of images stored in the ".ros" folder.

c. Create a folder /source Move the images from "/.ros" to /source:

1 mv ~/.ros/frame*.jpg source/

d. Convert to video:

1 cd ~/source
2 jpeg2yuv -I p -f 15 -j frame%04d.jpg -b 1 > tmp.yuv

Where -f 15 represents the frame rate, and -b 1 indictaes the starting image number.

To generate an .ogv file:

1 ffmpeg2theora --optimize --videoquality 10 --videobitrate 16778 -o output.ogv tmp.yuv

To generate an mpg file:

1 mencoder "mf://*.jpg" -mf type=jpg:fps=15 -o output.mpg -speed 1 -ofps 30 -ovc lavc -lavcopts vcodec=mpeg2video:vbitrate=2500 -oac copy -of mpeg

In this step, you may need to install some packages. Install them as prompted:

sudo apt-get install package-name

Tags: rosbag ROS data recording Image Processing video conversion

Posted on Thu, 14 May 2026 03:38:20 +0000 by cbassett03