|Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.|
How to export image and video data from a bag fileDescription: 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
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:
For newer versions :
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="play" name="rosbag" required="true" args="$(find image_view)/test.bag"/> 3 <node name="extract" pkg="image_view" type="extract_images" respawn="false" required="true" 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.
The images files can be easily to moved to where ever is convenient.
If your bag file contains compressed images for example on /camera/image_raw/compressed it will be necessary for you to decompress the images before exporting.
1 rosrun image_transport republish compressed in:=camera/image_raw raw out:=camera_out/image
Now your decompressed images will be the topic /camera_out/image, so you should change line 4 in the launch file to:
1 <remap from="image" to="/camera_out/image"/>
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.
or generate MPEG video directly from jpegs.
Also, to generate an mp4 video directly from jpg on the command line, you can use -