Merge pull request #2 from maladzenkau/development
Adding the camera from the dev
This commit is contained in:
commit
12f70a1b72
|
|
@ -77,4 +77,4 @@ ros2 launch image2rtsp rtsp.launch.py
|
||||||
## To Do
|
## To Do
|
||||||
- Add the camera directly as a source
|
- Add the camera directly as a source
|
||||||
- Add web camera ros2 topic formats
|
- Add web camera ros2 topic formats
|
||||||
- Add compressed images formats (jpeg, png)
|
- Add compressed images formats (jpeg, png)
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
/image2rtsp:
|
/image2rtsp:
|
||||||
ros__parameters:
|
ros__parameters:
|
||||||
|
|
||||||
|
# If camera serves as a source
|
||||||
|
camera: True
|
||||||
|
source: "v4l2src device=/dev/video0"
|
||||||
|
|
||||||
|
# If the source is a ros2 topic
|
||||||
topic: "/color/image_raw"
|
topic: "/color/image_raw"
|
||||||
|
|
||||||
|
# General setup
|
||||||
mountpoint: "/back"
|
mountpoint: "/back"
|
||||||
bitrate: "500"
|
bitrate: "500"
|
||||||
framerate: "30"
|
framerate: "30"
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ public:
|
||||||
GstRTSPServer *rtsp_server;
|
GstRTSPServer *rtsp_server;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
string source;
|
||||||
string topic;
|
string topic;
|
||||||
string mountpoint;
|
string mountpoint;
|
||||||
string bitrate;
|
string bitrate;
|
||||||
|
|
@ -26,6 +27,7 @@ private:
|
||||||
string pipeline_head;
|
string pipeline_head;
|
||||||
string pipeline_tail;
|
string pipeline_tail;
|
||||||
bool local_only;
|
bool local_only;
|
||||||
|
bool camera;
|
||||||
GstAppSrc *appsrc;
|
GstAppSrc *appsrc;
|
||||||
|
|
||||||
void video_mainloop_start();
|
void video_mainloop_start();
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ using std::placeholders::_1;
|
||||||
|
|
||||||
Image2rtsp::Image2rtsp() : Node("image2rtsp"){
|
Image2rtsp::Image2rtsp() : Node("image2rtsp"){
|
||||||
// Declare and get the parameters
|
// Declare and get the parameters
|
||||||
|
this->declare_parameter("source", "v4l2src device=/dev/video0");
|
||||||
this->declare_parameter("topic", "/color/image_raw");
|
this->declare_parameter("topic", "/color/image_raw");
|
||||||
this->declare_parameter("mountpoint", "/back");
|
this->declare_parameter("mountpoint", "/back");
|
||||||
this->declare_parameter("bitrate", "500");
|
this->declare_parameter("bitrate", "500");
|
||||||
|
|
@ -17,7 +18,9 @@ Image2rtsp::Image2rtsp() : Node("image2rtsp"){
|
||||||
this->declare_parameter("caps_2", "/1,width=640,height=480");
|
this->declare_parameter("caps_2", "/1,width=640,height=480");
|
||||||
this->declare_parameter("port", "8554");
|
this->declare_parameter("port", "8554");
|
||||||
this->declare_parameter("local_only", true);
|
this->declare_parameter("local_only", true);
|
||||||
|
this->declare_parameter("camera", false);
|
||||||
|
|
||||||
|
source = this->get_parameter("source").as_string();
|
||||||
topic = this->get_parameter("topic").as_string();
|
topic = this->get_parameter("topic").as_string();
|
||||||
mountpoint = this->get_parameter("mountpoint").as_string();
|
mountpoint = this->get_parameter("mountpoint").as_string();
|
||||||
bitrate = this->get_parameter("bitrate").as_string();
|
bitrate = this->get_parameter("bitrate").as_string();
|
||||||
|
|
@ -26,6 +29,7 @@ Image2rtsp::Image2rtsp() : Node("image2rtsp"){
|
||||||
caps_2 = this->get_parameter("caps_2").as_string();
|
caps_2 = this->get_parameter("caps_2").as_string();
|
||||||
port = this->get_parameter("port").as_string();
|
port = this->get_parameter("port").as_string();
|
||||||
local_only = this->get_parameter("local_only").as_bool();
|
local_only = this->get_parameter("local_only").as_bool();
|
||||||
|
camera = this->get_parameter("camera").as_bool();
|
||||||
|
|
||||||
// Start the subscription
|
// Start the subscription
|
||||||
subscription_ = this->create_subscription<sensor_msgs::msg::Image>(topic, 10, std::bind(&Image2rtsp::topic_callback, this, _1));
|
subscription_ = this->create_subscription<sensor_msgs::msg::Image>(topic, 10, std::bind(&Image2rtsp::topic_callback, this, _1));
|
||||||
|
|
@ -35,10 +39,16 @@ Image2rtsp::Image2rtsp() : Node("image2rtsp"){
|
||||||
rtsp_server = rtsp_server_create(port, local_only);
|
rtsp_server = rtsp_server_create(port, local_only);
|
||||||
appsrc = NULL;
|
appsrc = NULL;
|
||||||
// Setup the pipeline
|
// Setup the pipeline
|
||||||
pipeline_head = "( appsrc name=imagesrc do-timestamp=true min-latency=0 max-latency=0 max-bytes=1000 is-live=true ! videoconvert ! videoscale ! ";
|
|
||||||
pipeline_tail = "key-int-max=30 ! video/x-h264, profile=baseline ! rtph264pay name=pay0 pt=96 )";
|
pipeline_tail = "key-int-max=30 ! video/x-h264, profile=baseline ! rtph264pay name=pay0 pt=96 )";
|
||||||
pipeline = pipeline_head + caps_1 + framerate + caps_2 + " ! x264enc tune=zerolatency bitrate=" + bitrate + pipeline_tail;
|
if (camera == false){
|
||||||
rtsp_server_add_url(mountpoint.c_str(), pipeline.c_str(), (GstElement **)&(appsrc));
|
pipeline_head = "( appsrc name=imagesrc do-timestamp=true min-latency=0 max-latency=0 max-bytes=1000 is-live=true ! videoconvert ! videoscale ! ";
|
||||||
|
pipeline = pipeline_head + caps_1 + framerate + caps_2 + " ! x264enc tune=zerolatency bitrate=" + bitrate + pipeline_tail;
|
||||||
|
rtsp_server_add_url(mountpoint.c_str(), pipeline.c_str(), (GstElement **)&(appsrc));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pipeline = "( " + source + " ! videoconvert ! videoscale ! " + caps_1 + framerate + caps_2 + " ! x264enc tune=zerolatency bitrate=" + bitrate + pipeline_tail;
|
||||||
|
rtsp_server_add_url(mountpoint.c_str(), pipeline.c_str(), NULL);
|
||||||
|
}
|
||||||
RCLCPP_INFO(this->get_logger(), "Stream available at rtsp://%s:%s%s", gst_rtsp_server_get_address(rtsp_server), port.c_str(), mountpoint.c_str());
|
RCLCPP_INFO(this->get_logger(), "Stream available at rtsp://%s:%s%s", gst_rtsp_server_get_address(rtsp_server), port.c_str(), mountpoint.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue