rosbag2_to_video.api module

exception rosbag2_to_video.api.CommandInputError(msg: str)

Bases: ValueError

Error raised when provided command line arguments are not valid.

class rosbag2_to_video.api.SequentialImageBagReader(bag_reader: rosbag2_py.SequentialReader, topic_name: str)

Bases: object

Reader of images from a bagfile source sequentially.

get_next() Tuple[np.ndarray, float]

Return next image and its timestamp.

has_next()

Return true if there is at least one more message to read.

class rosbag2_to_video.api.SequentialVideoWriter(cv_video_writer: cv2.VideoWriter, first_cv_image: np.ndarray, start_stamp: float, fps: float)

Bases: object

Create videos from images provided sequentially.

add_frame(cv_image: np.ndarray, stamp: float)

Add a frame to the video, given an image and its timestamp.

close()

Close the video writer.

property frames_written: int

Get the number of frames that were written to the video.

property images_processed: int

Get the number of images that were provided.

Images that were skipped and not written are also counted.

property images_skipped: int

Get the number of images that were skipped and not written to the video.

rosbag2_to_video.api.add_arguments_to_parser(argparser: ArgumentParser)

Define command line arguments for the bag to video tool.

rosbag2_to_video.api.convert_bag_to_video(bag_path: str, storage_id: str, topic_name: str, output_path: str, codec: int, fps: float)

Create a bagfile from a video.

rosbag2_to_video.api.create_sequential_image_bag_reader(bag_path: str, storage_id: str, topic_name: str) SequentialImageBagReader

Create a SequentialImageBagReader instance.

Parameters:
  • bag_path – Path to the bagfile (folder with metadata or file).

  • storage_id – Storage id of the bagfile.

  • topic_name – Name of the image topic.

rosbag2_to_video.api.create_sequential_video_writer(output_path: str, codec: int, fps: float, first_cv_image: np.ndarray, start_stamp: float)

Create a SequentialVideoWriter instance.

Parameters:
  • output_path – Path of the video to be created.

  • codec – fourcc of the codec to be used.

  • fps – Video frame per second to be used.

  • first_cv_image – First image to write to the video. Video width and height are got from here.

  • start_stamp – Timestamp of the first image.

rosbag2_to_video.api.cv2_video_writer_fourcc(codec_str: str) int

Validate the user provided video codec string and return it as fourcc.

rosbag2_to_video.api.get_stamp_from_image_msg(image_msg) float

Convert timestamp in msg from nanoseconds to seconds.

rosbag2_to_video.api.get_topic_type(topic_name: str, topics_and_types) str

Get the topic type from the topic name and the topic information in the bag.

rosbag2_to_video.api.main(args)

Create a bagfile from a video.

Wrapper of convert_bag_to_video(), that handles exceptions and prints errors instead.