Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add jsk_rosbag_tools package #1738

Merged
merged 45 commits into from Jul 3, 2022
Merged

Add jsk_rosbag_tools package #1738

merged 45 commits into from Jul 3, 2022

Conversation

iory
Copy link
Member

@iory iory commented May 31, 2022

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

Copy link
Member

@k-okada k-okada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<?xml version="1.0"?>
<package format="3">
<name>jsk_rosbag_tools</name>
<version>0.0.1</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please set version to 2.2.1, all packages in a repository must have same version number

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed. Thank you.



# cv_bridge_python3 import
if os.environ['ROS_PYTHON_VERSION'] == '3':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why

import sys, os; sys.path.insert(0,'/opt/ros/' +  os.environ['ROS_DISTRO'] + '/lib/python3/dist-packages/')
import cv_bridge
from cv_bridge.boost.cv_bridge_boost import getCvType

did not work?
c.f. ros/rosdistro#32505 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I no longer need this import because I no longer use catkin virtualenv.

@@ -0,0 +1,4 @@
moviepy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could specify version? to prevent install latest version which is not compatible with this source tree.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<launch>

<test test-name="test_bag_to_video" pkg="jsk_rosbag_tools" type="test_jsk_rosbag_tools.py"
time-limit="3600.0" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am afraid this test takes too long time, increasing the total test time of jsk_common, could you consider shoulder version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified rosbag file to reduce test time.
Therefore, I changed the time-limit to 360.0.


if (${catkin_virtualenv_VERSION} VERSION_LESS "0.6.1")
message(WARNING "Please install catkin_virtualenv>=0.6.1.")
message(WARNING "Current catkin_virtualen version is ${catkin_virtualenv_VERSION}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add return() here??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I no longer use catkin virtualenv.

INPUT_REQUIREMENTS requirements.in
PYTHON_INTERPRETER python3
USE_SYSTEM_PACKAGES TRUE
ISOLATE_REQUIREMENTS FALSE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just out of curiosity, why we set FALSE?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I no longer use catkin virtualenv.



if(CATKIN_ENABLE_TESTING)
find_package(catkin REQUIRED COMPONENTS catkin_virtualenv roslint rostest)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need to set find catkin_virtualenv and catkin_generate_vertualenv, which is already set Line .19

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I no longer use catkin virtualenv.

@k-okada
Copy link
Member

k-okada commented Jun 1, 2022

BTW, what happens if we merge #1704 ?? @sktometometo @iory

@708yamaguchi
Copy link
Member

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?

replaced_topic_name = topic_name
replaced_topic_name = replaced_topic_name.replace('/', '--slash--')
output_videopath = os.path.join(
out, "{}.mp4".format(replaced_topic_name))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding an argument that specifies the name of the output file? (Same for other programs)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Modified

@708yamaguchi
Copy link
Member

708yamaguchi commented Jun 1, 2022

Thank you for your update.

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

  • execution permission to each script (e.g. bag_to_video.py)
  • unknown argument exist_ok=True
  • version error when pip install -r requirements.txt
    • ERROR: Could not find a version that satisfies the requirement certifi==2022.5.18.1
    • ERROR: Could not find a version that satisfies the requirement charset-normalizer==2.0.12
    • ERROR: Could not find a version that satisfies the requirement idna==3.3
    • ERROR: Could not find a version that satisfies the requirement imageio-ffmpeg==0.4.7
    • ...

@iory
Copy link
Member Author

iory commented Jun 1, 2022

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
Copy link
Member

Nice! I have tested the bag_to_video.py node a bit and it worked great, with a few caveats (iory#2)

Some thoughts:

Traceback (most recent call last):
  File "/home/affonso/jsk_common_ws/src/jsk_common/jsk_rosbag_tools/scripts/bag_to_video.py", line 57, in <module>
    main()
  File "/home/affonso/jsk_common_ws/src/jsk_common/jsk_rosbag_tools/scripts/bag_to_video.py", line 53, in main
    audio_topic=args.audio_topic)
  File "/home/affonso/jsk_common_ws/src/jsk_common/jsk_rosbag_tools/python/jsk_rosbag_tools/bag_to_video.py", line 84, in bag_to_video
    makedirs(osp.dirname(output_filepath))
  File "/home/affonso/jsk_common_ws/src/jsk_common/jsk_rosbag_tools/python/jsk_rosbag_tools/makedirs.py", line 30, in makedirs
    raise OSError
OSError

as opposed to the more informative OSError: [Errno 2] No such file or directory: ''

@708yamaguchi
Copy link
Member

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
Copy link
Member Author

iory commented Jun 4, 2022

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 iory closed this Jun 4, 2022
@iory iory reopened this Jun 4, 2022
@iory
Copy link
Member Author

iory commented Jun 9, 2022

@708yamaguchi
Thanks for your feedback!
This problem occurs when the image size changes. I fixed it with this commit.
ce184ee

rviz--slash--image--slash--compressed.mp4

@iory
Copy link
Member Author

iory commented Jun 30, 2022

Test passed.
Could someone review this PR?

Some people use this node in their projects.
jsk-ros-pkg/jsk_recognition#2703 @nakane11
knorth55#11 @708yamaguchi @tkmtnt7000

@k-okada
Copy link
Member

k-okada commented Jun 30, 2022

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
Copy link
Contributor

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
Copy link
Member Author

iory commented Jul 1, 2022

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. fb24554

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
Copy link
Member Author

iory commented Jul 1, 2022

@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の方に書きました。
007febb
確認よろしくお願いします。

@Naoki-Hiraoka
Copy link
Contributor

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

@k-okada k-okada merged commit 7147133 into jsk-ros-pkg:master Jul 3, 2022
@iory iory deleted the rosbag-tools branch July 3, 2022 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants