Module my_ros_utils.bag_conversion
Functions
def bag2audio(bag_file, audio_topic, audio_info_topic=None, output_dir=None)-
Reads a ROS1 bag file and extracts the audio from a given audio topic.
Args
bag_file:str- Path to the bag file.
audio_topic:str- Name of the audio topic to extract from the bag. The messages published on this topic must be of type
audio_common_msgs/AudioDataoraudio_common_msgs/AudioDataStamped. audio_info_topic:str, optional- Name of the topic to extract info on audio stream. The messages published on this topic must be of type
audio_common_msgs/AudioInfo. If not specified, default values inaudio_common/audio_capture/launch/capture_wave.launchare used. Defaults to None. output_dir:str, optional- Destination directory for output files. If set to
None, the output file will be saved in the same directory of the input bag. Defaults toNone.
def bag2video(bag_file, image_topic, output_dir=None)-
Reads a ROS1 bag file and extracts the images from a given image topic. Adapted from munzz11 on GitHub Gist.
Args
bag_file:str- Path to the bag file.
image_topic:str- Name of the image topic to extract from the bag. The messages published on this topic must be of type
sensor_msgs/Imageorsensor_msgs/CompressedImage. output_dir:str, optional- Destination directory for output files. If set to
None, the output file will be saved in the same directory of the input bag. Defaults toNone.
def combine_video_audio(video_file, audio_file, output_file=None)-
Combine video and audio files into a single MP4 file.
Args
video_file:str- Path to the video file.
audio_file:str- Path to the audio file.
output_file:str, optional- Output video file. If set to
None, the output file will be saved in the same directory of the input video file. Defaults to None.
def parse_audio_format(format_str)-
Parse an audio format string (e.g., S16LE) and return: - sample width (in bytes) - byteorder ('little' or 'big') - range of values (min, max)
Args
format_str:str- Audio format string. Must start with 'S' or 'U' to indicate signed or unsigned format, respectively. The format string should also include the sample width in bits (e.g., 'S16LE' for signed 16-bit little-endian).
Return
dict: A dictionary containing the sample width, byteorder, and range of values (min, max).