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:

  • topic_set: Efficient data structure to hold a static set of topics with super-fast is-in-set queries.

  • tqdm_bag: Bag file reader that shows progressbars when loading index or reading messages.

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 form TOPIC:OUT_FORMAT:COMPRESSION:ENCODING:IN_FPS:OUT_FPS:PIX_FMT (only TOPIC is required)

    • OUT_FORMAT: Format of the exported images/video (e.g. jpg, mp4 etc.). Defaults to --out-format.

    • COMPRESSION: Compression level. The meaning depends on OUT_FORMAT. JPG has 0-100, PNG 0-9, MP4 0-51 (CRF).

    • ENCODING: Pixel format to convert the images to. E.g. bgr8 or mono8. passthrough means keeping the format. Empty string retains the format for raw images and converts compressed images to the recorded raw format in their .format field if it is available. Defaults to passthrough.

    • 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 to IN_FPS.

    • PIX_FMT: The -pix_fmt output option for ffmpeg, i.e. the pixel format of the video stream. Defaults to yuvj420p.

  • -h: Shows help.

  • --out-format: Default format for all topics (e.g. jpg, mp4 etc.). Defaults to jpg.

  • --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