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

Implemented Dockerisation + Direct Sqlite3 Extraction for ROS 2 Bag Folders #42

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
da1460a
:hammer: Replaced ros2bag2video.py with experimental method of extrac…
cardboardcode Oct 12, 2024
882a5f0
:hammer: Elaborated experimental ros2bag2video.py. Verified with hard…
cardboardcode Oct 12, 2024
01512f1
:heavy_plus_sign: Added Dockerfile.ros2 in root for dockerised option…
cardboardcode Oct 12, 2024
97d9a26
:hammer: Added license header in ros2bag2video.py
cardboardcode Oct 12, 2024
4540177
:hammer: Implemented argparse for configurable running for more user-…
cardboardcode Oct 12, 2024
96716ce
:hammer: Integrated configurable output file naming using ofile argum…
cardboardcode Oct 12, 2024
cbe1281
:hammer: Rectified dynamic output_video given by user.
cardboardcode Oct 12, 2024
e9fa938
:hammer: Implemented automatic removal of transient images.txt file g…
cardboardcode Oct 12, 2024
ee3951c
:hammer: Implemented safeguard for having valid rates given by user. …
cardboardcode Oct 12, 2024
064b873
:hammer: Optimized docker ros2 image in Dockerfile.ros2
cardboardcode Oct 12, 2024
71c2542
:heavy_plus_sign: Added Dockerfile.ros1 that allows rosbag2video.py t…
cardboardcode Oct 12, 2024
2cc7ef5
:hammer: Closes #22 by generating unique timestamped output file names.
cardboardcode Oct 12, 2024
be3dbf7
:hammer: Optimized Dockerfiles for ROS 1 and ROS 2.
cardboardcode Oct 12, 2024
8743316
:hammer: Ensured bridge variable is passed properly to save_image_fro…
cardboardcode Oct 12, 2024
b2999aa
:hammer: Rectified argument description for -ifile.
cardboardcode Oct 12, 2024
6d7fedf
:hammer: Implemented verbose mode for ros2bag2video.py
cardboardcode Oct 12, 2024
4d27e23
:hammer: Enabled user input for framerateinstead of hardcoded default…
cardboardcode Oct 12, 2024
63df19e
:hammer: Implemented dynamic setting for pix_fmt when running ffmpeg …
cardboardcode Oct 12, 2024
3053cea
:book: Elaborated root README.md to reflect the current implement for…
cardboardcode Oct 12, 2024
b890386
:hammer: Added TODO to implement a feature to determine whether bag f…
cardboardcode Oct 12, 2024
ec36a1a
:book: Added docker run commands under Run section in root README.md.
cardboardcode Oct 12, 2024
e66320d
:fire: Removed IS_VERBOSE mode TODO comment since verbose mode has be…
cardboardcode Oct 26, 2024
5dec4dc
:hammer: Implemented dynamic detection of message type using direct e…
cardboardcode Oct 26, 2024
90e7c2b
:hammer: Implemented dynamic processing of compressedimage referenced…
cardboardcode Oct 26, 2024
310239c
:fire: Removed TODO comment regarding processing CompressedImages.
cardboardcode Oct 26, 2024
4779303
:hammer: Adhered ros2bag2video.py to PEP08 standards with exceptions.
cardboardcode Oct 26, 2024
cc1b113
:hammer: Adhered to rosbag2video.py ROS 1 script to PEP08 standards w…
cardboardcode Oct 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Dockerfile.ros1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM ros:noetic-perception

# Install system packages
RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg \
ros-noetic-rosbag* \
python3-setuptools \
python3-pip && \
pip3 install rospkg pycryptodome && \
rm -rf /var/lib/apt/lists/*

# Setting up working directory
WORKDIR /rosbag2video_workspace

# Add user
RUN useradd -ms /bin/bash ubuntu
RUN echo 'ubuntu:asdf' | chpasswd
RUN adduser ubuntu sudo
RUN chown -R ubuntu /rosbag2video_workspace
USER ubuntu

ENTRYPOINT ["/ros_entrypoint.sh"]


15 changes: 15 additions & 0 deletions Dockerfile.ros2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM ros:humble-perception

RUN apt-get update && apt-get install -y --no-install-recommends \
ffmpeg && \
rm -rf /var/lib/apt/lists/*

# Setting up working directory
WORKDIR /ros2bag2video_workspace

# Add user
RUN adduser --quiet --disabled-password user
RUN chown -R user:user /ros2bag2video_workspace
USER user

ENTRYPOINT ["/ros_entrypoint.sh"]
128 changes: 100 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,72 +8,144 @@ [email protected]

with contributions from
Abel Gabor 2019,
Bey Hao Yun 2021
Bey Hao Yun 2024
[email protected],
[email protected]
[email protected]
```

## **Install**

**ffmpeg** is needed and can be installed on **Ubuntu** with:
Build docker images using the commands below:

1. Download `rosbag2video`:

```bash
cd $HOME
```

```bash
sudo apt install ffmpeg
git clone https://github.com/mlaiacker/rosbag2video --depth 1 --branch sqlite3_extraction_ros2 --single-branch && cd rosbag2video
```

**ROS2** and **other stuff**.
2. Build docker image for running ROS 1 `rosbag2video.py`:

```bash
sudo apt install python3-sensor-msgs python3-opencv ros-foxy-rosbag2-transport
docker build -f Dockerfile.ros1 -t ros2bagvideo:noetic .
```

3. Build docker image for running ROS 2 `ros2bag2video.py`:

```bash
docker build -f Dockerfile.ros2 -t ros2bagvideo:humble .
```

## **Usage**

For processing ROS 1 bag files, please use `rosbag2video.py`:

``` bash
ros2bag2video.py [--fps 25] [--rate 1.0] [-o outputfile] [-v] [-s] [-t topic] bagfile1
rosbag2video.py [--fps 25] [--rate 1] [-o outputfile] [-v] [-s] [-t topic] bagfile1 [bagfile2] ...

Converts image sequence(s) in ros bag file(s) to video file(s) with fixed frame rate using ffmpeg
ffmpeg needs to be installed!

--fps Sets FPS value that is passed to ffmpeg
Default is 25.
-h Displays this help.
--ofile (-o) sets output file name.
If no output file name (-o) is given the filename '<prefix><topic>.mp4' is used and default output codec is h264.
Multiple image topics are supported only when -o option is _not_ used.
ffmpeg will guess the format according to given extension.
Compressed and raw image messages are supported with mono8 and bgr8/rgb8/bggr8/rggb8 formats.
--rate (-r) You may slow down or speed up the video.
Default is 1.0, that keeps the original speed.
-s Shows each and every image extracted from the rosbag file (cv_bride is needed).
--topic (-t) Only the images from topic "topic" are used for the video output.
-v Verbose messages are displayed.
--prefix (-p) set a output file name prefix othervise 'bagfile1' is used (if -o is not set).
--start Optional start time in seconds.
--end Optional end time in seconds.
```

For processing ROS 2 bag folders, please use `ros2bag2video.py`:

``` bash
ros2bag2video.py [--rate 1.0] [-t topic] [-i bagfolder1] [-o outputfile] [-v] [-s]

Converts image sequence(s) in ros bag file(s) to video file(s) with fixed frame rate using ffmpeg
ffmpeg needs to be installed!

--rate (-r) Sets FPS value that is passed to ffmpeg
Default is 25.
-h Displays this help.
--ofile (-o) sets output file name.
If no output file name (-o) is given the filename 'output.mp4' is used.
--ifile (-i) sets input file name.
--rate (-r) You may slow down or speed up the video.
Default is 1.0, that keeps the original speed.
-s Shows each and every image extracted from the rosbag file.
--topic (-t) Only the images from topic "topic" are used for the video output.
-v Verbose messages are displayed.
```

## **Example Output**
## **Run**

For running ROS 1 `rosbag2video.py`:

```bash
docker run -it --rm \
--name rosbag2video_c \
-v ./:/rosbag2video_workspace \
ros2bagvideo:noetic bash
```

```bash
source /opt/ros/noetic/setup.bash
```

```bash
python3 rosbag2video.py -t <topic_name> -o <output_video_file_name> <bag_file_name>
# Eg. python3 rosbag2video.py -t /cam0/image_raw -o myvideo.mp4 ar_tracking_1.bag
```

For running ROS 2 `ros2bag2video.py`:

```bash
docker run -it --rm \
--name ros2bag2video_c \
-v ./:/ros2bag2video_workspace \
ros2bagvideo:humble bash
```

```bash
# Source ROS2 Humble
source /opt/ros/humble/setup.bash
```

```bash
python3 ros2bag2video.py -t <topic_name> -i <bag_folder_name> --save_images -o <output_video_file_name>
# Eg. python3 ros2bag2video.py -t /virtual_camera/image_raw -i rosbag2_2024_10_11-19_45_28 --save_images -o myvideo.mp4
```

## **Example Output**
If running `ros2bag2video.py` correctly, you should see something similar to what is shown below:

# Run the script. Rate greater than 5.0 leads to dropped frames on the test PC.
./ros2bag2video.py --fps=25 --rate=5.0 -t /camera_node/image_raw/compressed ~/Documents/rosbag2_2023_04_19-14_44_56


FPS (int) = 25
Rate (float) = 1.0
Topic (str) = /camera_node/image_raw/compressed
Output File (str) = output.mp4
Verbose (bool) = False
bag_file = rosbag2_2023_04_19-14_44_56/
[INFO] [1619616391.700087224] [rosbag2_storage]: Opened database './rosbag2_2023_04_19-14_44_56/rosbag2_2023_04_19-14_44_56.db3' for READ_ONLY.
[INFO] [1619616392.055535299] [ros2bag2videos]: Image Received [1/28]
[INFO] [1619616392.077294702] [ros2bag2videos]: Image Received [2/28]
[INFO] [1619616392.299152538] [ros2bag2videos]: Image Received [3/28]
[INFO] [1619616392.792717810] [ros2bag2videos]: Image Received [4/28]
[INFO] [1619616393.268813798] [ros2bag2videos]: Image Received [5/28]
[INFO] [1619616393.724949415] [ros2bag2videos]: Image Received [6/28]
[INFO] [1619616394.199588269] [ros2bag2videos]: Image Received [7/28]
[INFO] [1619616394.667638765] [ros2bag2videos]: Image Received [8/28]
```bash
[INFO] - Processing messages: [43/193]
...
Writing to output file, output.mp4
frame= 187 fps=6.3 q=29.0 size= 11264kB time=00:00:04.06 bitrate=22690.2kbits/s speed=0.187x
frame= 193 fps=5.7 q=-1.0 Lsize= 17157kB time=00:00:06.33 bitrate=22191.6kbits/s speed=0.187x
[INFO] - Writing video to: myvideo.mp4
```

If running `rosbag2video.py` correctly, you should see something similar to what is shown below:

```bash
############# UNCOMPRESSED IMAGE ######################
/cam0/image_raw with datatype: sensor_msgs/Image

frame= 178 fps=0.0 q=28.0 size= 256kB time=00:00:04.64 bitrate= 452.0kbits/s speed
frame= 340 fps=338 q=28.0 size= 768kB time=00:00:11.12 bitrate= 565.8kbits/s speed
frame= 513 fps=341 q=28.0 size= 1280kB time=00:00:18.04 bitrate= 581.3kbits/s speed
finished
```
Loading