cras_bag_tools
Various utilities to work with bag files
README
cras_bag_tools
Czech-army knife for working with ROS BAG files.
Python Modules
Several useful functions are exported as Python submodules as module cras_bag_tools:
Scripts
extract_images
Extract image topics from bag file to image or video files.
Usage
ros2 run cras_bag_tools extract_images [-h] [--out-format OUT_FORMAT] [--verbose] bag_file output_dir [image_topics [image_topics ...]]
bag_file: The bag to read.output_dir: Directory where all generated files should be stored.image_topics: Zero or more topics to convert. If zero, all image topics are converted. Each image topic can be followed by additional configuration in the formTOPIC:OUT_FORMAT:COMPRESSION:ENCODING:IN_FPS:OUT_FPS:PIX_FMT(onlyTOPICis required)OUT_FORMAT: Format of the exported images/video (e.g.jpg,mp4etc.). Defaults to--out-format.COMPRESSION: Compression level. The meaning depends onOUT_FORMAT. JPG has 0-100, PNG 0-9, MP4 0-51 (CRF).ENCODING: Pixel format to convert the images to. E.g.bgr8ormono8.passthroughmeans keeping the format. Empty string retains the format for raw images and converts compressed images to the recorded raw format in their.formatfield if it is available. Defaults topassthrough.Following options are for video formats only.
IN_FPS: Framerate of the topic images. If not set, it is estimated from the frequency of the messages in the bag. You can set the FPS higher than the original, effectively speeding up the video.OUT_FPS: Output framerate. Defaults toIN_FPS.PIX_FMT: The-pix_fmtoutput option for ffmpeg, i.e. the pixel format of the video stream. Defaults toyuvj420p.
-h: Shows help.--out-format: Default format for all topics (e.g.jpg,mp4etc.). Defaults tojpg.--verbose: Print various details during execution.
Example command
# Convert all image topics in the bag to a series of JPEG images in folder imgs/
ros2 run cras_bag_tools extract_images spot_2022-10-27-10-35-46 imgs
# Convert topic /rviz/fixed_image/compressed to an MP4 video
ros2 run cras_bag_tools extract_images spot_2022-10-27-10-35-46 . /rviz/fixed_image/compressed:mp4:23:passthrough:25