jsk-ros-pkg / jsk_common

common programs for jsk-ros-pkg
42 stars 81 forks source link

Add jsk_rosbag_tools package #1738

Closed iory closed 2 years ago

iory commented 2 years ago

What is this?

Add jsk_rosbag_tools package which tools such as creating video from rosbag and compressing rosbag images.

bag_to_video.py

Create video from rosbag.

Usage

usage: bag_to_video.py [-h] [--out OUT] [--fps FPS] [--samplerate SAMPLERATE] [--channels CHANNELS] [--audio-topic AUDIO_TOPIC] [--image-topic IMAGE_TOPIC [IMAGE_TOPIC ...]] input_bagfile

rosbag to video

positional arguments:
  input_bagfile

optional arguments:
  -h, --help            show this help message and exit
  --out OUT, -o OUT     output directory path or filename.
                        If more than one --image-topic are specified,
                        this will be interpreted as a directory name.
                        Otherwise this is the file name.
  --fps FPS
  --samplerate SAMPLERATE, -r SAMPLERATE
                        sampling rate
  --channels CHANNELS   number of input channels
  --audio-topic AUDIO_TOPIC
  --image-topic IMAGE_TOPIC [IMAGE_TOPIC ...]
                        Topic name to extract.

Example

rosrun jsk_rosbag_tools bag_to_video.py $(rospack find jsk_rosbag_tools)/samples/data/20220530173950_go_to_kitchen_rosbag.bag \
  --samplerate 16000 --channels 1 --audio-topic /audio \
  --image-topic /head_camera/rgb/throttled/image_rect_color/compressed \
  -o /tmp/20220530173950_go_to_kitchen_rosbag.mp4

bag_to_audio.py

Create audio file from rosbag.

Usage

usage: bag_to_audio.py [-h] [--out OUT] [--samplerate SAMPLERATE] [--channels CHANNELS] [--audio-topic AUDIO_TOPIC] input_bagfile

rosbag to audio

positional arguments:
  input_bagfile

optional arguments:
  -h, --help            show this help message and exit
  --out OUT, -o OUT     output filename. If `--audio-topic`_info is exists, you don't have to specify samplerate and channels.
  --samplerate SAMPLERATE, -r SAMPLERATE
                        sampling rate
  --channels CHANNELS   number of input channels
  --audio-topic AUDIO_TOPIC

Example

rosrun jsk_rosbag_tools bag_to_audio.py $(rospack find jsk_rosbag_tools)/samples/data/20220530173950_go_to_kitchen_rosbag.bag \
  --samplerate 16000 --channels 1 --audio-topic /audio \
  -o /tmp/20220530173950_go_to_kitchen_rosbag.wav

video_to_bag.py

Convert video file to bagfile.

Usage

usage: video_to_bag.py [-h] [--out output_file] [--topic-name TOPIC_NAME] [--compress] [--no-progress-bar] inputvideo

Convert video to bag.

positional arguments:
  inputvideo

optional arguments:
  -h, --help            show this help message and exit
  --out output_file, -o output_file
                        name of the output bag file
  --topic-name TOPIC_NAME
                        Converted topic name.
  --compress            Compress Image flag.
  --no-progress-bar     Don't show progress bar.

Example

rosrun jsk_rosbag_tools video_to_bag.py /tmp/output_bag/head_camera--slash--rgb--slash--throttled--slash--image_rect_color--slash--compressed-with-audio.mp4 \
    -o /tmp/output_bag/video.bag --compress

compress_imgs.py

Convert Image messages to CompressedImage or CompressedDepthImage.

Usage

usage: compress_imgs.py [-h] [--out OUT] [--compressed-topics [COMPRESSED_TOPICS [COMPRESSED_TOPICS ...]]] [--replace] [--no-progress-bar] input_bagfile

Convert Image messages to CompressedImage or CompressedDepthImage

positional arguments:
  input_bagfile         input bagfile path

optional arguments:
  -h, --help            show this help message and exit
  --out OUT, -o OUT     output bagfile path
  --compressed-topics [COMPRESSED_TOPICS [COMPRESSED_TOPICS ...]]
                        this image topics are compressed
  --replace
  --no-progress-bar     Don't show progress bar.

Example

rosrun jsk_rosbag_tools compress_imgs.py $(rospack find jsk_rosbag_tools)/samples/data/20220530173950_go_to_kitchen_rosbag.bag \
  -o /tmp/20220530173950_go_to_kitchen_rosbag-compressed.bag

tf_static_to_tf.py

Convert tf_static to tf and save it as a rosbag.

usage: tf_static_to_tf.py [-h] [--out OUT] [--no-progress-bar] input_bagfile

Convert tf_static to tf and save it as a rosbag

positional arguments:
  input_bagfile      input bagfile path

optional arguments:
  -h, --help         show this help message and exit
  --out OUT, -o OUT  output bagfile path
  --no-progress-bar  Don't show progress bar.

Example

rosrun jsk_rosbag_tools tf_static_to_tf.py $(rospack find jsk_rosbag_tools)/samples/data/20220530173950_go_to_kitchen_rosbag.bag

merge.py

Merges two bagfiles.

Usage

usage: merge.py [-h] [--out output_file] [--topics TOPICS] [-i] main_bagfile bagfile

Merges two bagfiles.

positional arguments:
  main_bagfile          path to a bagfile, which will be the main bagfile
  bagfile               path to a bagfile which should be merged to the main bagfile

optional arguments:
  -h, --help            show this help message and exit
  --out output_file, -o output_file
                        name of the output file
  --topics TOPICS, -t TOPICS
                        topics which should be merged to the main bag
  -i                    reindex bagfile

Example

rosrun jsk_rosbag_tools merge.py \
    $(rospack find jsk_rosbag_tools)/samples/data/20220530173950_go_to_kitchen_rosbag.bag \
    $(rospack find jsk_rosbag_tools)/samples/data/2022-05-07-hello-test.bag
k-okada commented 2 years ago

BTW, what happens if we merge https://github.com/jsk-ros-pkg/jsk_common/pull/1704 ?? @sktometometo @iory

708yamaguchi commented 2 years ago

Thank you for this convenient features.

I want to use bag_to_video feature at the end of daily go-to-kitchen demo.

Generating video after the demo with bag_to_video, instead of during the demo with audio_video_recorder, reduces fetch's CPU usage during the demo.

In this case, I thought it would be useful to import bag_to_video as a python package. How about achieving this feature by not using catkin_virtualenv?

708yamaguchi commented 2 years ago

Thank you for your update.

I found the following errors when executing bag_to_video.py with python 2.7.17

iory commented 2 years ago

Once we merge this package, we should update information at

I would like to add this change to the documentation for many users.

Affonso-Gui commented 2 years ago

Nice! I have tested the bag_to_video.py node a bit and it worked great, with a few caveats (https://github.com/iory/jsk_common/pull/2)

Some thoughts:

708yamaguchi commented 2 years ago

Today's fetch go-to-kitchen demo, fetch cannot create good video from /rviz/image/compressed.. Fetch kitchen patrol demo: 2022/06/04 (09:55:10) robag_compressed

I reproduce this problem on my laptop, too. This is the link to the rosbag file. (I manually extracted /rviz/image/compressed, so this rosbag file has only one topic). https://drive.google.com/file/d/1x2bnU8S_XWoeuMNJGbJHBPTD3STE1DAt/view?usp=sharing

iory commented 2 years ago

Thank you for your feedback.

video_to_bag.py seems to have overlap with this node http://wiki.ros.org/movie_publisher#movie_to_bag

I see. I think there are differences between video_to_bag.py and movie_to_bag

Having video_to_bag.py in jsk_rosbag_tools has the advantage of being at least easier for jsk users to recognize and maintain it.

We have some raise Exception with no arguments, which can lead to very hard-to-read bugs. Maybe consider adding an error message to them?

Thanks! I added a messages on raise.

Why --slash-- instead of normal underscores in https://github.com/iory/jsk_common/blob/rosbag-tools/jsk_rosbag_tools/python/jsk_rosbag_tools/topic_name_utils.py#L6 ???

The topic name may contain an underscore, so I'm doing this to restore the original topic name correctly.

iory commented 2 years ago

@708yamaguchi Thanks for your feedback! This problem occurs when the image size changes. I fixed it with this commit. https://github.com/jsk-ros-pkg/jsk_common/pull/1738/commits/ce184eef89c496af876dddfc8b34b36bb858117e

https://user-images.githubusercontent.com/4690682/172870185-7554f4cf-de02-43c6-97dd-9fd5236719fd.mp4

iory commented 2 years ago

Test passed. Could someone review this PR?

Some people use this node in their projects. https://github.com/jsk-ros-pkg/jsk_recognition/pull/2703 @nakane11 https://github.com/knorth55/jsk_common/pull/11 @708yamaguchi @tkmtnt7000

k-okada commented 2 years ago

I am afraid this package installs a lot of pip dependences , so I prefer to use catkin_virtualenv, please re-consider using that . If so, I am happy with merging this PR https://github.com/Zulko/moviepy/blob/18e9f57d1abbae8051b9aef75de3f19b4d1f0630/setup.py#L74-L92

Just for note; The packages is valid only when you show some results which is not achieved without the proposed feature. I am looking for RSJ papers that uses audio-visual information.

Naoki-Hiraoka commented 2 years ago

tf_static_to_tf.py とhttps://github.com/jsk-ros-pkg/jsk_common/blob/master/jsk_topic_tools/scripts/static_tf_republisher.py は一長一短があるので適切な使い分けが必要ですが、別の場所に置いてあるので片方を見つけられなそうです。2つを同じ場所に置くか、類似のソフトウェアがあることをドキュメントに書いておくことはできますでしょうか。

iory commented 2 years ago

I am afraid this package installs a lot of pip dependences , so I prefer to use catkin_virtualenv, please re-consider using that . If so, I am happy with merging this PR

I re-enabled catkin-virtualenv. https://github.com/jsk-ros-pkg/jsk_common/pull/1738/commits/fb24554d4519b3d090a5bdfefbbbf0db41c5822c

Just for note; The packages is valid only when you show some results which is not achieved without the proposed feature. I am looking for RSJ papers that uses audio-visual information.

I'll keep in mind.

iory commented 2 years ago

@Naoki-Hiraoka

tf_static_to_tf.py とhttps://github.com/jsk-ros-pkg/jsk_common/blob/master/jsk_topic_tools/scripts/static_tf_republisher.py は一長一短があるので適切な使い分けが必要ですが、別の場所に置いてあるので片方を見つけられなそうです。2つを同じ場所に置くか、類似のソフトウェアがあることをドキュメントに書いておくことはできますでしょうか。

こちらのREADMEの方に書きました。 https://github.com/jsk-ros-pkg/jsk_common/pull/1738/commits/007febbbb94b5167322c1321408e6be7c62555bd 確認よろしくお願いします。

Naoki-Hiraoka commented 2 years ago

@iory ご対応くださりありがとうございます。READMEに十分な記述が加わったことを確認しました。

iory commented 2 years ago

Thanks for merging. I updated the documents in ROS community. https://answers.ros.org/question/44777/how-to-extract-video-from-bag-file/?answer=403176#post-id-403176 http://wiki.ros.org/rosbag/Tutorials/Exporting%20image%20and%20video%20data#Converting_images_in_rosbag_into_an_Video_using_jsk_rosbag_tools