Skip to content

Commit 7b2b33e

Browse files
authored
feat: online configure (#13)
1 parent 731194b commit 7b2b33e

23 files changed

+27205
-1052
lines changed

CMakeLists.txt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pkg_check_modules(AVUTIL REQUIRED libavutil)
1313
pkg_check_modules(SWSCALE REQUIRED libswscale)
1414

1515
find_package(OpenCV REQUIRED)
16+
find_package(CURL REQUIRED)
1617

1718
message(STATUS "ROS_VERSION: " $ENV{ROS_VERSION})
1819
message(STATUS "ROS_DISTRO: " $ENV{ROS_DISTRO})
@@ -28,11 +29,12 @@ if("$ENV{ROS_VERSION}" STREQUAL "1")
2829
roscpp
2930
std_srvs
3031
sensor_msgs
32+
# coscene_msgs
3133
foxglove_msgs
3234
)
3335

3436
catkin_package(
35-
CATKIN_DEPENDS roscpp std_srvs sensor_msgs foxglove_msgs
37+
CATKIN_DEPENDS roscpp std_srvs sensor_msgs foxglove_msgs # coscene_msgs
3638
)
3739

3840
include_directories(
@@ -41,11 +43,12 @@ if("$ENV{ROS_VERSION}" STREQUAL "1")
4143
)
4244

4345
# Add the executable
44-
add_executable(coencoder src/ros1/coencoder.cpp)
46+
add_executable(coencoder src/ros1/main.cpp)
4547

4648
target_include_directories(coencoder
4749
SYSTEM PRIVATE
4850
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
51+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/vendor>
4952
$<INSTALL_INTERFACE:include>
5053
${catkin_INCLUDE_DIRS}
5154
)
@@ -58,6 +61,7 @@ if("$ENV{ROS_VERSION}" STREQUAL "1")
5861
${AVFORMAT_LIBRARIES}
5962
${AVUTIL_LIBRARIES}
6063
${SWSCALE_LIBRARIES}
64+
${CURL_LIBRARIES}
6165
)
6266
elseif("$ENV{ROS_VERSION}" STREQUAL "2")
6367
message(STATUS "Building with ament_cmake")
@@ -70,15 +74,23 @@ elseif("$ENV{ROS_VERSION}" STREQUAL "2")
7074
find_package(rclcpp REQUIRED)
7175
find_package(std_srvs REQUIRED)
7276
find_package(sensor_msgs REQUIRED)
77+
# find_package(coscene_msgs REQUIRED)
7378
find_package(foxglove_msgs REQUIRED)
7479

75-
add_executable(coencoder src/ros2/coencoder.cpp)
80+
add_executable(coencoder src/ros2/main.cpp)
7681

77-
ament_target_dependencies(coencoder rclcpp std_srvs sensor_msgs foxglove_msgs)
82+
ament_target_dependencies(coencoder
83+
rclcpp
84+
std_srvs
85+
sensor_msgs
86+
# coscene_msgs
87+
foxglove_msgs
88+
)
7889

7990

8091
target_include_directories(coencoder PRIVATE
8192
${PROJECT_SOURCE_DIR}/include
93+
${PROJECT_SOURCE_DIR}/vendor
8294
${OpenCV_INCLUDE_DIRS}
8395
)
8496

@@ -88,6 +100,7 @@ elseif("$ENV{ROS_VERSION}" STREQUAL "2")
88100
${AVCODEC_LIBRARIES}
89101
${AVUTIL_LIBRARIES}
90102
${SWSCALE_LIBRARIES}
103+
${CURL_LIBRARIES}
91104
)
92105

93106
else()

README.md

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,65 @@
55
- Have ROS on your system
66

77
- Install dependencies
8-
```bash
9-
sudo apt install libavformat-dev libswscale-dev libopencv-dev ros-{ros_distro}-foxglove-msgs -y
10-
```
8+
```bash
9+
sudo apt install libavcodec-dev libavutil-dev libopencv-dev libcurl4 ros-{ros_distro}-foxglove-msgs -y
10+
```
11+
## GPU Supported
12+
coencoder currently supports encoding using GPUs, currently supports the following encoders:
13+
```C++
14+
"h264_nvenc", // NVIDIA NVENC
15+
"h264_qsv", // Intel Quick Sync
16+
"h264_amf", // AMD VCE
17+
"h264_vaapi", // VAAPI (Linux hardware acceleration)
18+
```
1119

1220
## Configuration
1321

14-
Edit the configuration parameters in the launch file (`coencoder/launch/coencoder.launch`):
22+
If the system environment variable contains `HOME`, the config file is located at `$HOME/.config/coencoder/config.json`, otherwise, the config file is located at `/tmp/coencoder/config/config.json`. If you start coEncoder using `rosrun` (or `ros2 run`), you can use --config-file to specify the config file path.
1523

16-
- ROS1
17-
```xml
18-
<launch>
19-
<!-- Specify topics requiring H264 encoding -->
20-
<rosparam param="/coencoder/subscribe_topics">['/camera_1', '/camera_2', '/camera_3']</rosparam>
21-
<rosparam param="/coencoder/video_resolutions">['1600x900','640x480','1280x720']</rosparam>
22-
23-
<node name="coencoder" pkg="coencoder" type="coencoder" output="screen">
24-
<param name="output_fps" value="20"/>
25-
<param name="bitrate" value="400000"/>
26-
<param name="depth_image_max_value" value="10000"/>
27-
</node>
28-
</launch>
29-
```
30-
- ROS2
31-
```xml
32-
<launch>
33-
<node pkg="coencoder" exec="coencoder" name="coencoder" output="screen">
34-
<param name="output_fps" value="20"/>
35-
<param name="bitrate" value="400000"/>
36-
<param name="depth_image_max_value" value="10000"/>
37-
<param name="subscribe_topics" value="['/Node_1_image', '/Node_2_image']"/>
38-
<param name="video_resolutions" value="['1920*1080', '1920*1080']"/>
39-
</node>
40-
</launch>
41-
```
24+
```Json
25+
{
26+
"enable_by_default": true,
27+
"log_directory": "/home/cos/logs",
28+
"log_level": "Debug",
29+
"topics_param": [
30+
{
31+
"bitrate": 1600000,
32+
"encoder_name": "h264_nvenc",
33+
"input": "/camera_0/raw_image",
34+
"output": "/camera_0/raw_image/h264"
35+
},
36+
{
37+
"bitrate": 1600000,
38+
"encoder_name": "libx264",
39+
"input": "/camera_1/raw_image",
40+
"output": "/camera_1/raw_image/h264"
41+
}
42+
]
43+
}
44+
```
45+
* **enable_by_default**: Whether to enable encoding by default
46+
* **log_directory**: Log file path
47+
* **log_level**: Log level, possible values: Debug / Info / Warn / Error
48+
* **topics_param**: Array type, contains 3 fields
49+
* **bitrate**: Output bitrate
50+
* **encoder_name**: Encoder name, supports `h264_nvenc`, `h264_qsv`, `h264_amf`, `h264_vaapi`, and you can also use `libx264` to encode frames by CPU. If this field is missing in the configuration, `libx264` will be used for encoding
51+
* **input**: Input topic name
52+
* **output**: Output topic name
4253

43-
- `subscribe_topics`: Specify one or more topics for H264 encoding. The topic's message types must be `sensor_msgs/CompressedImage` or `sensor_msgs/Image`.
44-
- `video_resolutions`: Specify the resolution for each topic. Ensure a one-to-one correspondence with `subscribe_topics`.
54+
## Online Configuration Modification
55+
**Online configuration modification requires coScout v1.1.8 or later**
56+
* Online configuration editing
57+
* Organization Settings -> Devices -> Device Configuration
58+
59+
![img_0](./img/device-config.png)
60+
* Edit fields
61+
62+
![img_1](./img/config-setting.png)
63+
In device configuration, add the `coEncoder` field as shown in the image above. Note that `coEncoder` is a sub-field of `plugin_config`.
64+
* Configuration validity
65+
* The configuration MUST contain the `topics_param` field, and this field must be of array type.
66+
* Elements in `topics_param` MUST have three fields: `input`, `output`, `bitrate`. `input` and `output` are strings, `bitrate` is an integer.
4567

4668
## Compile OR deb install
4769

@@ -85,6 +107,8 @@ Edit the configuration parameters in the launch file (`coencoder/launch/coencode
85107
source /opt/ros/{ros destro}/setup.bash
86108
87109
roslaunch coencoder coencoder.launch
110+
# You can also use `rosrun` to start the node
111+
rosrun coencoder coencoder --config-file {your_config_file_path}
88112
```
89113

90114
- ROS2
@@ -95,4 +119,6 @@ Edit the configuration parameters in the launch file (`coencoder/launch/coencode
95119
source /opt/ros/{ros destro}/setup.bash
96120
97121
ros2 launch coencoder coencoder_launch.xml
122+
# You can also use `ros2 run` to start the node
123+
ros2 run coencoder coencoder -- --config-file {your_config_file_path}
98124
```

README_cn.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# coEncoder
2+
3+
## 前置条件
4+
5+
- 系统上需要安装ROS
6+
7+
- 安装依赖
8+
```bash
9+
sudo apt install libavcodec-dev libavutil-dev libopencv-dev libcurl4 ros-{ros_distro}-foxglove-msgs -y
10+
```
11+
## GPU支持
12+
coencoder目前支持使用GPU进行编码,目前支持以下编码器:
13+
```C++
14+
"h264_nvenc", // NVIDIA NVENC
15+
"h264_qsv", // Intel Quick Sync
16+
"h264_amf", // AMD VCE
17+
"h264_vaapi", // VAAPI (Linux hardware acceleration)
18+
```
19+
20+
## 配置
21+
22+
如果系统环境变量包含`HOME`,配置文件位于`$HOME/.config/coencoder/config.json`,否则配置文件位于`/tmp/coencoder/config/config.json`. 如果使用 `rosrun` (or `ros2 run`) 启动coEncoder, 可使用 --config-file 指定配置文件路径
23+
24+
```Json
25+
{
26+
"enable_by_default": true,
27+
"log_directory": "/home/cos/logs",
28+
"log_level": "Debug",
29+
"topics_param": [
30+
{
31+
"bitrate": 1600000,
32+
"encoder_name": "h264_nvenc",
33+
"input": "/camera_0/raw_image",
34+
"output": "/camera_0/raw_image/h264"
35+
},
36+
{
37+
"bitrate": 1600000,
38+
"encoder_name": "libx264",
39+
"input": "/camera_1/raw_image",
40+
"output": "/camera_1/raw_image/h264"
41+
}
42+
]
43+
}
44+
```
45+
* **enable_by_default:** 是否默认启用编码
46+
* **log_directory:** 日志文件路径
47+
* **log_level:** 日志级别,可选值:Debug / Info / Warn / Error
48+
* **topics_param:** 数组类型,包含3个字段
49+
* **bitrate:** 输出码率
50+
* **encoder_name:** 编码器名称,支持`h264_nvenc``h264_qsv``h264_amf``h264_vaapi`,同时也可以使用`libx264`通过CPU编码帧. 如果配置中缺失该字段,则使用 `libx264` 进行编码
51+
* **input:** 输入topic名称
52+
* **output:** 输出topic名称
53+
54+
## 在线配置修改
55+
**在线配置修改需要 coScout v1.1.8 或更高版本**
56+
* 在线配置编辑
57+
* 组织设置 -> 设备 -> 设备配置
58+
59+
![img_0](./img/device-config.png)
60+
* 编辑字段
61+
62+
![img_1](./img/config-setting.png)
63+
在设备配置中,如上图所示添加`coEncoder`字段。注意`coEncoder``plugin_config`的子字段。
64+
* 配置有效性
65+
* 配置必须包含`topics_param`字段,且该字段必须为数组类型。
66+
* `topics_param`中的元素必须包含三个字段:`input``output``bitrate``input``output`为字符串,`bitrate`为整数。
67+
68+
## 编译或deb安装
69+
70+
*** 您可以通过自行编译来安装CoEncoder。或者,我们也会提供.deb包进行安装。 ***
71+
- 编译
72+
- ROS1
73+
```bash
74+
# 将项目复制到您的ROS工作空间
75+
cp -r {this_repo} {your_ros_ws}/src/
76+
77+
# Source ROS设置并构建
78+
source /opt/ros/{ros_distro}/setup.bash
79+
80+
cd {your_ros_ws}
81+
82+
catkin_make --pkg coencoder install
83+
```
84+
- ROS2
85+
```bash
86+
# 将项目复制到您的ROS工作空间
87+
cp -r {this_repo} {your_ros_ws}/src/
88+
# Source ROS设置并构建
89+
source /opt/ros/{ros_distro}/setup.bash
90+
91+
cd {your_ros_ws}
92+
colcon build --packages-select coencoder
93+
```
94+
95+
- deb安装
96+
```bash
97+
dpkg -i ros-{ros distro}-coencoder_latest_{system arch}.deb
98+
```
99+
100+
## 运行
101+
102+
- ROS1
103+
```bash
104+
# 如果通过编译安装coencoder,source您的工作空间
105+
source {your_ros_ws}/install/setup.bash
106+
# 如果通过deb安装coencoder,source ros
107+
source /opt/ros/{ros destro}/setup.bash
108+
109+
roslaunch coencoder coencoder.launch
110+
# 也可使用 `rosrun` 启动节点
111+
rosrun coencoder coencoder --config-file {your_config_file_path}
112+
```
113+
114+
- ROS2
115+
```bash
116+
# 如果通过编译安装coencoder,source您的工作空间
117+
source {your_ros_ws}/install/setup.bash
118+
# 如果通过deb安装coencoder,source ros
119+
source /opt/ros/{ros destro}/setup.bash
120+
121+
ros2 launch coencoder coencoder_launch.xml
122+
# 也可使用 `rosrun` 启动节点
123+
ros2 run coencoder coencoder -- --config-file {your_config_file_path}
124+
```

config/config.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"enable_by_default": true,
3+
"log_directory": "/home/cos/logs",
4+
"log_level": "Debug",
5+
"topics_param": [
6+
{
7+
"encoder_name": "h264_nvenc",
8+
"bitrate": 1600000,
9+
"input": "/camera_0/raw_image",
10+
"output": "/camera_0/raw_image/h264"
11+
},
12+
{
13+
"encoder_name": "h264_nvenc",
14+
"bitrate": 1600000,
15+
"input": "/camera_1/raw_image",
16+
"output": "/camera_1/raw_image/h264"
17+
}
18+
]
19+
}

img/config-setting.png

101 KB
Loading

img/device-config.png

33.6 KB
Loading

0 commit comments

Comments
 (0)