How to export image and video data from a bag file
Description: This tutorial explains how to export image messages from a bag file into a series of jpeg images and then goes on to show how to encode them into an OGG Theora video.Keywords: data, rosbag, record, play, info, bag, export, video
Tutorial Level: BEGINNER
Next Tutorial: Producing filtered bag files
Tutorial setup
This tutorial requires that you have previously recorded a bag file which contains image data you would like to export as jpeg images or video. Additionally, this tutorial requires that the image_view package has been built and a few video utilities are installed:
This will install the necessary tools to complete the tutorial. The rest of this tutorial will assume that you have a .bag file previously created that is named test.bag and that this bag file is stored in the image_view package directory.
Exporting jpegs from bag file
To export jpeg images from a bag file first you will need to create a launch file which will dump the data. This example uses /camera/image_raw as the topic for the desired image data. This can be replaced as needed.
1 <launch>
2 <node pkg="rosbag" type="rosbag" name="rosbag" args="play -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>
The launch file can be started by running
1 roslaunch export.launch
This will dump the images name frame%04d.jpg into the folder ".ros" in your home directory. When the process has completed it will display a message similar to process has finished cleanly. at which point you should enter ctrl-C to end the launched program.
The images files can be easily to moved to where ever is convenient.
Converting jpegs into an OGG Theora Video
These instructions are based on the information found here, and have been tested and shown to work.
If your camera was running at 15 frames per second then you would execute the following in a shell for reasonable results.
1 cd ~/test
2 jpeg2yuv -I p -f 15 -j frame%04d.jpg -b 1 > tmp.yuv
3 ffmpeg2theora --optimize --videoquality 10 --videobitrate 16778 -o output.ogv tmp.yuv
or generate MPEG video directly from jpegs.






